~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_iocache.cc

  • Committer: Brian Aker
  • Date: 2009-10-12 06:15:02 UTC
  • mfrom: (1165.1.178 static-functions)
  • Revision ID: brian@gaz-20091012061502-cds4m0cya7ow8sj7
Merge Stewart

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
 
63
63
using namespace std;
64
64
 
 
65
extern "C" {
 
66
static int _my_b_read(register IO_CACHE *info, unsigned char *Buffer, size_t Count);
 
67
static int _my_b_read_r(register IO_CACHE *cache, unsigned char *Buffer, size_t Count);
 
68
static int _my_b_seq_read(register IO_CACHE *info, unsigned char *Buffer, size_t Count);
 
69
static int _my_b_write(register IO_CACHE *info, const unsigned char *Buffer, size_t Count);
 
70
}
 
71
 
65
72
#define lock_append_buffer(info) \
66
73
 pthread_mutex_lock(&(info)->append_buffer_lock)
67
74
#define unlock_append_buffer(info) \
427
434
    1      Error: can't read requested characters
428
435
*/
429
436
 
430
 
int _my_b_read(register IO_CACHE *info, unsigned char *Buffer, size_t Count)
 
437
static int _my_b_read(register IO_CACHE *info, unsigned char *Buffer, size_t Count)
431
438
{
432
439
  size_t length,diff_length,left_length, max_length;
433
440
  my_off_t pos_in_file;
887
894
    1      Error: can't read requested characters
888
895
*/
889
896
 
890
 
int _my_b_read_r(register IO_CACHE *cache, unsigned char *Buffer, size_t Count)
 
897
extern "C" int _my_b_read_r(register IO_CACHE *cache, unsigned char *Buffer, size_t Count)
891
898
{
892
899
  my_off_t pos_in_file;
893
900
  size_t length, diff_length, left_length;
1055
1062
    1  Failed to read
1056
1063
*/
1057
1064
 
1058
 
int _my_b_seq_read(register IO_CACHE *info, unsigned char *Buffer, size_t Count)
 
1065
extern "C" int _my_b_seq_read(register IO_CACHE *info, unsigned char *Buffer, size_t Count)
1059
1066
{
1060
1067
  size_t length, diff_length, left_length, save_count, max_length;
1061
1068
  my_off_t pos_in_file;
1405
1412
   -1 On error; my_errno contains error code.
1406
1413
*/
1407
1414
 
1408
 
int _my_b_write(register IO_CACHE *info, const unsigned char *Buffer, size_t Count)
 
1415
extern "C" int _my_b_write(register IO_CACHE *info, const unsigned char *Buffer, size_t Count)
1409
1416
{
1410
1417
  size_t rest_length,length;
1411
1418
 
1467
1474
  return 0;
1468
1475
}
1469
1476
 
1470
 
 
1471
 
/*
1472
 
  Append a block to the write buffer.
1473
 
  This is done with the buffer locked to ensure that we don't read from
1474
 
  the write buffer before we are ready with it.
1475
 
*/
1476
 
 
1477
 
int my_b_append(register IO_CACHE *info, const unsigned char *Buffer, size_t Count)
1478
 
{
1479
 
  size_t rest_length,length;
1480
 
 
1481
 
  /*
1482
 
    Assert that we cannot come here with a shared cache. If we do one
1483
 
    day, we might need to add a call to copy_to_read_buffer().
1484
 
  */
1485
 
  assert(!info->share);
1486
 
 
1487
 
  lock_append_buffer(info);
1488
 
  rest_length= (size_t) (info->write_end - info->write_pos);
1489
 
  if (Count <= rest_length)
1490
 
    goto end;
1491
 
  memcpy(info->write_pos, Buffer, rest_length);
1492
 
  Buffer+=rest_length;
1493
 
  Count-=rest_length;
1494
 
  info->write_pos+=rest_length;
1495
 
  if (my_b_flush_io_cache(info,0))
1496
 
  {
1497
 
    unlock_append_buffer(info);
1498
 
    return 1;
1499
 
  }
1500
 
  if (Count >= IO_SIZE)
1501
 
  {                                     /* Fill first intern buffer */
1502
 
    length=Count & (size_t) ~(IO_SIZE-1);
1503
 
    if (my_write(info->file,Buffer, length, info->myflags | MY_NABP))
1504
 
    {
1505
 
      unlock_append_buffer(info);
1506
 
      return info->error= -1;
1507
 
    }
1508
 
    Count-=length;
1509
 
    Buffer+=length;
1510
 
    info->end_of_file+=length;
1511
 
  }
1512
 
 
1513
 
end:
1514
 
  memcpy(info->write_pos,Buffer,(size_t) Count);
1515
 
  info->write_pos+=Count;
1516
 
  unlock_append_buffer(info);
1517
 
  return 0;
1518
 
}
1519
 
 
1520
 
 
1521
 
int my_b_safe_write(IO_CACHE *info, const unsigned char *Buffer, size_t Count)
1522
 
{
1523
 
  /*
1524
 
    Sasha: We are not writing this with the ? operator to avoid hitting
1525
 
    a possible compiler bug. At least gcc 2.95 cannot deal with
1526
 
    several layers of ternary operators that evaluated comma(,) operator
1527
 
    expressions inside - I do have a test case if somebody wants it
1528
 
  */
1529
 
  if (info->type == SEQ_READ_APPEND)
1530
 
    return my_b_append(info, Buffer, Count);
1531
 
  return my_b_write(info, Buffer, Count);
1532
 
}
1533
 
 
1534
 
 
1535
1477
/*
1536
1478
  Write a block to disk where part of the data may be inside the record
1537
1479
  buffer.  As all write calls to the data goes through the cache,