~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/mf_iocache.c

Merged in changes from Andrey.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
#include <mystrings/m_string.h>
53
53
#ifdef HAVE_AIOWAIT
54
54
#include "mysys_err.h"
 
55
#include <mysys/aio_result.h>
55
56
static void my_aiowait(my_aio_result *result);
56
57
#endif
 
58
#include <mysys/iocache.h>
57
59
#include <errno.h>
58
60
 
59
61
#define lock_append_buffer(info) \
221
223
      if (type == SEQ_READ_APPEND)
222
224
        buffer_block *= 2;
223
225
      if ((info->buffer=
224
 
           (uchar*) my_malloc(buffer_block,
 
226
           (unsigned char*) my_malloc(buffer_block,
225
227
                             MYF((cache_myflags & ~ MY_WME) |
226
228
                                 (cachesize == min_cache ? MY_WME : 0)))) != 0)
227
229
      {
327
329
      seek_offset <= my_b_tell(info))
328
330
  {
329
331
    /* Reuse current buffer without flushing it to disk */
330
 
    uchar *pos;
 
332
    unsigned char *pos;
331
333
    if (info->type == WRITE_CACHE && type == READ_CACHE)
332
334
    {
333
335
      info->read_end=info->write_pos;
429
431
    1      Error: can't read requested characters
430
432
*/
431
433
 
432
 
int _my_b_read(register IO_CACHE *info, uchar *Buffer, size_t Count)
 
434
int _my_b_read(register IO_CACHE *info, unsigned char *Buffer, size_t Count)
433
435
{
434
436
  size_t length,diff_length,left_length, max_length;
435
437
  my_off_t pos_in_file;
597
599
*/
598
600
 
599
601
void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
600
 
                         IO_CACHE *write_cache, uint num_threads)
 
602
                         IO_CACHE *write_cache, uint32_t num_threads)
601
603
{
602
604
  assert(num_threads > 1);
603
605
  assert(read_cache->type == READ_CACHE);
649
651
void remove_io_thread(IO_CACHE *cache)
650
652
{
651
653
  IO_CACHE_SHARE *cshare= cache->share;
652
 
  uint total;
 
654
  uint32_t total;
653
655
 
654
656
  /* If the writer goes, it needs to flush the write cache. */
655
657
  if (cache == cshare->source_cache)
890
892
    1      Error: can't read requested characters
891
893
*/
892
894
 
893
 
int _my_b_read_r(register IO_CACHE *cache, uchar *Buffer, size_t Count)
 
895
int _my_b_read_r(register IO_CACHE *cache, unsigned char *Buffer, size_t Count)
894
896
{
895
897
  my_off_t pos_in_file;
896
898
  size_t length, diff_length, left_length;
1013
1015
*/
1014
1016
 
1015
1017
static void copy_to_read_buffer(IO_CACHE *write_cache,
1016
 
                                const uchar *write_buffer, size_t write_length)
 
1018
                                const unsigned char *write_buffer, size_t write_length)
1017
1019
{
1018
1020
  IO_CACHE_SHARE *cshare= write_cache->share;
1019
1021
 
1024
1026
  */
1025
1027
  while (write_length)
1026
1028
  {
1027
 
    size_t copy_length= min(write_length, write_cache->buffer_length);
 
1029
    size_t copy_length= cmin(write_length, write_cache->buffer_length);
1028
1030
    int  __attribute__((unused)) rc;
1029
1031
 
1030
1032
    rc= lock_io_cache(write_cache, write_cache->pos_in_file);
1059
1061
    1  Failed to read
1060
1062
*/
1061
1063
 
1062
 
int _my_b_seq_read(register IO_CACHE *info, uchar *Buffer, size_t Count)
 
1064
int _my_b_seq_read(register IO_CACHE *info, unsigned char *Buffer, size_t Count)
1063
1065
{
1064
1066
  size_t length, diff_length, left_length, save_count, max_length;
1065
1067
  my_off_t pos_in_file;
1182
1184
      TODO: figure out if the assert below is needed or correct.
1183
1185
    */
1184
1186
    assert(pos_in_file == info->end_of_file);
1185
 
    copy_len=min(Count, len_in_buff);
 
1187
    copy_len=cmin(Count, len_in_buff);
1186
1188
    memcpy(Buffer, info->append_read_pos, copy_len);
1187
1189
    info->append_read_pos += copy_len;
1188
1190
    Count -= copy_len;
1221
1223
     1          An error has occurred; IO_CACHE to error state.
1222
1224
*/
1223
1225
 
1224
 
int _my_b_async_read(register IO_CACHE *info, uchar *Buffer, size_t Count)
 
1226
int _my_b_async_read(register IO_CACHE *info, unsigned char *Buffer, size_t Count)
1225
1227
{
1226
1228
  size_t length,read_length,diff_length,left_length,use_length,org_Count;
1227
1229
  size_t max_length;
1228
1230
  my_off_t next_pos_in_file;
1229
 
  uchar *read_buffer;
 
1231
  unsigned char *read_buffer;
1230
1232
 
1231
1233
  memcpy(Buffer,info->read_pos,
1232
1234
         (left_length= (size_t) (info->read_end-info->read_pos)));
1284
1286
      }
1285
1287
    }
1286
1288
        /* Copy found bytes to buffer */
1287
 
    length=min(Count,read_length);
 
1289
    length=cmin(Count,read_length);
1288
1290
    memcpy(Buffer,info->read_pos,(size_t) length);
1289
1291
    Buffer+=length;
1290
1292
    Count-=length;
1318
1320
      if ((read_length=my_read(info->file,info->request_pos,
1319
1321
                               read_length, info->myflags)) == (size_t) -1)
1320
1322
        return info->error= -1;
1321
 
      use_length=min(Count,read_length);
 
1323
      use_length=cmin(Count,read_length);
1322
1324
      memcpy(Buffer,info->request_pos,(size_t) use_length);
1323
1325
      info->read_pos=info->request_pos+Count;
1324
1326
      info->read_end=info->request_pos+read_length;
1389
1391
 
1390
1392
int _my_b_get(IO_CACHE *info)
1391
1393
{
1392
 
  uchar buff;
 
1394
  unsigned char buff;
1393
1395
  IO_CACHE_CALLBACK pre_read,post_read;
1394
1396
  if ((pre_read = info->pre_read))
1395
1397
    (*pre_read)(info);
1397
1399
    return my_b_EOF;
1398
1400
  if ((post_read = info->post_read))
1399
1401
    (*post_read)(info);
1400
 
  return (int) (uchar) buff;
 
1402
  return (int) (unsigned char) buff;
1401
1403
}
1402
1404
 
1403
1405
/* 
1410
1412
   -1 On error; my_errno contains error code.
1411
1413
*/
1412
1414
 
1413
 
int _my_b_write(register IO_CACHE *info, const uchar *Buffer, size_t Count)
 
1415
int _my_b_write(register IO_CACHE *info, const unsigned char *Buffer, size_t Count)
1414
1416
{
1415
1417
  size_t rest_length,length;
1416
1418
 
1479
1481
  the write buffer before we are ready with it.
1480
1482
*/
1481
1483
 
1482
 
int my_b_append(register IO_CACHE *info, const uchar *Buffer, size_t Count)
 
1484
int my_b_append(register IO_CACHE *info, const unsigned char *Buffer, size_t Count)
1483
1485
{
1484
1486
  size_t rest_length,length;
1485
1487
 
1523
1525
}
1524
1526
 
1525
1527
 
1526
 
int my_b_safe_write(IO_CACHE *info, const uchar *Buffer, size_t Count)
 
1528
int my_b_safe_write(IO_CACHE *info, const unsigned char *Buffer, size_t Count)
1527
1529
{
1528
1530
  /*
1529
1531
    Sasha: We are not writing this with the ? operator to avoid hitting
1543
1545
  we will never get a seek over the end of the buffer
1544
1546
*/
1545
1547
 
1546
 
int my_block_write(register IO_CACHE *info, const uchar *Buffer, size_t Count,
 
1548
int my_block_write(register IO_CACHE *info, const unsigned char *Buffer, size_t Count,
1547
1549
                   my_off_t pos)
1548
1550
{
1549
1551
  size_t length;
1723
1725
    info->alloced_buffer=0;
1724
1726
    if (info->file != -1)                       /* File doesn't exist */
1725
1727
      error= my_b_flush_io_cache(info,1);
1726
 
    my_free((uchar*) info->buffer,MYF(MY_WME));
1727
 
    info->buffer=info->read_pos=(uchar*) 0;
 
1728
    free((unsigned char*) info->buffer);
 
1729
    info->buffer=info->read_pos=(unsigned char*) 0;
1728
1730
  }
1729
1731
  if (info->type == SEQ_READ_APPEND)
1730
1732
  {
1807
1809
    total_bytes += 4+block_size;
1808
1810
  }
1809
1811
  close_file(&sra_cache);
1810
 
  my_free(block,MYF(MY_WME));
 
1812
  free(block);
1811
1813
  if (!my_stat(fname,&status,MYF(MY_WME)))
1812
1814
    die("%s failed to stat, but I had just closed it,\
1813
1815
 wonder how that happened");