~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/internal/iocache.h

Merge Monty - Updates to pandora-build to support features of gcc 4.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#pragma once
22
 
 
23
 
#include <drizzled/internal/my_sys.h>
24
 
 
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
 
 
 
21
#ifndef DRIZZLED_INTERNAL_IOCACHE_H
 
22
#define DRIZZLED_INTERNAL_IOCACHE_H
 
23
 
 
24
#include "drizzled/internal/my_sys.h"
 
25
 
 
26
namespace drizzled
 
27
{
 
28
namespace internal
 
29
{
 
30
 
 
31
struct st_io_cache;
 
32
typedef int (*IO_CACHE_CALLBACK)(struct st_io_cache*);
 
33
 
 
34
struct st_io_cache    /* Used when cacheing files */
 
35
{
35
36
  /* Offset in file corresponding to the first byte of unsigned char* buffer. */
36
37
  my_off_t pos_in_file;
37
38
  /*
77
78
    my_b_read() will call read_function to fetch the data. read_function
78
79
    must never be invoked directly.
79
80
  */
80
 
  int (*read_function)(io_cache_st* ,unsigned char *,size_t);
 
81
  int (*read_function)(struct st_io_cache *,unsigned char *,size_t);
81
82
  /*
82
83
    Same idea as in the case of read_function, except my_b_write() needs to
83
84
    be replaced with my_b_append() for a SEQ_READ_APPEND cache
84
85
  */
85
 
  int (*write_function)(io_cache_st* ,const unsigned char *,size_t);
 
86
  int (*write_function)(struct st_io_cache *,const unsigned char *,size_t);
86
87
  /*
87
88
    Specifies the type of the cache. Depending on the type of the cache
88
89
    certain operations might not be available and yield unpredicatable
89
90
    results. Details to be documented later
90
91
  */
91
 
  cache_type type;
 
92
  enum cache_type type;
92
93
  int error;
93
94
  /*
94
95
    Callbacks when the actual read I/O happens. These were added and
95
96
    are currently used for binary logging of LOAD DATA INFILE - when a
96
97
    block is read from the file, we create a block create/append event, and
97
 
    when io_cache_st is closed, we create an end event. These functions could,
 
98
    when IO_CACHE is closed, we create an end event. These functions could,
98
99
    of course be used for other things
99
100
  */
100
101
  IO_CACHE_CALLBACK pre_read;
124
125
    somewhere else
125
126
  */
126
127
  bool alloced_buffer;
 
128
#ifdef HAVE_AIOWAIT
 
129
  /*
 
130
    As inidicated by ifdef, this is for async I/O, which is not currently
 
131
    used (because it's not reliable on all systems)
 
132
  */
 
133
  uint32_t inited;
 
134
  my_off_t aio_read_pos;
 
135
  my_aio_result aio_result;
 
136
#endif
127
137
 
128
 
  io_cache_st() :
 
138
  st_io_cache() :
129
139
    pos_in_file(0),
130
140
    end_of_file(0),
131
141
    read_pos(0),
155
165
    read_length(0),
156
166
    myflags(0),
157
167
    alloced_buffer(0)
158
 
  { }
159
 
 
160
 
  int get();
161
 
  int block_write(const void*, size_t, my_off_t);
 
168
#ifdef HAVE_AIOWAIT
 
169
    ,
 
170
    inited(0),
 
171
    aio_read_pos(0),
 
172
    aio_result(0)
 
173
#endif
 
174
  { }
 
175
 
 
176
  ~st_io_cache()
 
177
  { }
 
178
 
162
179
  void close_cached_file();
163
180
  bool real_open_cached_file();
164
181
  int end_io_cache();
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);
 
182
  int init_io_cache(int file, size_t cachesize,
 
183
                    enum cache_type type, my_off_t seek_offset,
 
184
                    bool use_async_io, myf cache_myflags);
166
185
  void init_functions();
167
186
 
168
 
  bool reinit_io_cache(cache_type type_arg, my_off_t seek_offset, bool use_async_io, bool clear_cache);
 
187
  bool reinit_io_cache(enum cache_type type_arg,
 
188
                       my_off_t seek_offset,
 
189
                       bool use_async_io,
 
190
                       bool clear_cache);
169
191
  void setup_io_cache();
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
 
  }
 
192
  bool open_cached_file(const char *dir,
 
193
                        const char *prefix, size_t cache_size,
 
194
                        myf cache_myflags);
 
195
 
207
196
};
208
197
 
 
198
typedef struct st_io_cache IO_CACHE;    /* Used when cacheing files */
 
199
 
 
200
extern int _my_b_get(st_io_cache *info);
 
201
extern int _my_b_async_read(st_io_cache *info,unsigned char *Buffer,size_t Count);
 
202
 
 
203
extern int my_block_write(st_io_cache *info, const unsigned char *Buffer,
 
204
                          size_t Count, my_off_t pos);
 
205
extern int my_b_flush_io_cache(st_io_cache *info, int need_append_buffer_lock);
 
206
 
 
207
#define flush_io_cache(info) my_b_flush_io_cache((info),1)
 
208
 
209
209
} /* namespace internal */
210
210
} /* namespace drizzled */
 
211
 
 
212
#endif /* DRIZZLED_INTERNAL_IOCACHE_H */