~vjsamuel/drizzle/fix-bug-850898

« back to all changes in this revision

Viewing changes to drizzled/internal/iocache.h

  • Committer: Mark Atwood
  • Date: 2011-08-17 19:14:47 UTC
  • mfrom: (2385.3.17 rf)
  • Revision ID: me@mark.atwood.name-20110817191447-h86yzddvycd0xmof
mergeĀ lp:~olafvdspek/drizzle/refactor6

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include <drizzled/internal/my_sys.h>
24
24
 
25
 
namespace drizzled
26
 
{
27
 
namespace internal
28
 
{
29
 
 
30
 
struct io_cache_st;
31
 
typedef int (*IO_CACHE_CALLBACK)(struct io_cache_st*);
32
 
 
33
 
struct io_cache_st    /* Used when cacheing files */
34
 
{
 
25
namespace drizzled {
 
26
namespace internal {
 
27
 
 
28
#define my_b_EOF INT_MIN
 
29
 
 
30
class io_cache_st    /* Used when cacheing files */
 
31
{
 
32
public:
 
33
  typedef int (*IO_CACHE_CALLBACK)(io_cache_st*);
 
34
 
35
35
  /* Offset in file corresponding to the first byte of unsigned char* buffer. */
36
36
  my_off_t pos_in_file;
37
37
  /*
77
77
    my_b_read() will call read_function to fetch the data. read_function
78
78
    must never be invoked directly.
79
79
  */
80
 
  int (*read_function)(struct io_cache_st *,unsigned char *,size_t);
 
80
  int (*read_function)(io_cache_st* ,unsigned char *,size_t);
81
81
  /*
82
82
    Same idea as in the case of read_function, except my_b_write() needs to
83
83
    be replaced with my_b_append() for a SEQ_READ_APPEND cache
84
84
  */
85
 
  int (*write_function)(struct io_cache_st *,const unsigned char *,size_t);
 
85
  int (*write_function)(io_cache_st* ,const unsigned char *,size_t);
86
86
  /*
87
87
    Specifies the type of the cache. Depending on the type of the cache
88
88
    certain operations might not be available and yield unpredicatable
89
89
    results. Details to be documented later
90
90
  */
91
 
  enum cache_type type;
 
91
  cache_type type;
92
92
  int error;
93
93
  /*
94
94
    Callbacks when the actual read I/O happens. These were added and
157
157
    alloced_buffer(0)
158
158
  { }
159
159
 
160
 
  ~io_cache_st()
161
 
  { }
162
 
 
 
160
  int get();
 
161
  int block_write(const void*, size_t, my_off_t);
163
162
  void close_cached_file();
164
163
  bool real_open_cached_file();
165
164
  int end_io_cache();
166
 
  int init_io_cache(int file, size_t cachesize,
167
 
                    enum cache_type type, my_off_t seek_offset,
168
 
                    bool use_async_io, myf cache_myflags);
 
165
  int init_io_cache(int file, size_t cachesize, cache_type type, my_off_t seek_offset, bool use_async_io, myf cache_myflags);
169
166
  void init_functions();
170
167
 
171
 
  bool reinit_io_cache(enum cache_type type_arg,
172
 
                       my_off_t seek_offset,
173
 
                       bool use_async_io,
174
 
                       bool clear_cache);
 
168
  bool reinit_io_cache(cache_type type_arg, my_off_t seek_offset, bool use_async_io, bool clear_cache);
175
169
  void setup_io_cache();
176
 
  bool open_cached_file(const char *dir,
177
 
                        const char *prefix, size_t cache_size,
178
 
                        myf cache_myflags);
179
 
 
 
170
  bool open_cached_file(const char *dir, const char *prefix, size_t cache_size, myf cache_myflags);
 
171
  int flush(int need_append_buffer_lock= 1);
 
172
 
 
173
  void clear()
 
174
  {
 
175
    buffer= NULL;
 
176
  }
 
177
 
 
178
  bool inited() const
 
179
  {
 
180
    return buffer;
 
181
  }
 
182
 
 
183
  my_off_t tell() const
 
184
  {
 
185
    return pos_in_file + *current_pos - request_pos;
 
186
  }
 
187
 
 
188
  int read(void* Buffer0, size_t Count)
 
189
  {
 
190
    unsigned char* Buffer= reinterpret_cast<unsigned char*>(Buffer0);
 
191
    if (read_pos + Count > read_end)
 
192
      return read_function(this, Buffer, Count);
 
193
    memcpy(Buffer, read_pos, Count);
 
194
    read_pos += Count;
 
195
    return 0;
 
196
  }
 
197
 
 
198
  int write(const void* Buffer0, size_t Count)
 
199
  {
 
200
    const unsigned char* Buffer= reinterpret_cast<const unsigned char*>(Buffer0);
 
201
    if (write_pos + Count > write_end)
 
202
      return write_function(this, Buffer, Count);
 
203
    memcpy(write_pos, Buffer, Count);
 
204
    write_pos += Count;
 
205
    return 0;
 
206
  }
180
207
};
181
208
 
182
 
typedef struct io_cache_st IO_CACHE;    /* Used when cacheing files */
183
 
 
184
 
extern int _my_b_get(io_cache_st *info);
185
 
extern int _my_b_async_read(io_cache_st *info,unsigned char *Buffer,size_t Count);
186
 
 
187
 
extern int my_block_write(io_cache_st *info, const unsigned char *Buffer,
188
 
                          size_t Count, my_off_t pos);
189
 
extern int my_b_flush_io_cache(io_cache_st *info, int need_append_buffer_lock);
190
 
 
191
 
#define flush_io_cache(info) my_b_flush_io_cache((info),1)
192
 
 
193
209
} /* namespace internal */
194
210
} /* namespace drizzled */
195