18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#ifndef DRIZZLED_INTERNAL_IOCACHE_H
22
#define DRIZZLED_INTERNAL_IOCACHE_H
24
#include <drizzled/internal/my_sys.h>
21
#ifndef MYSYS_IOCACHE_H
22
#define MYSYS_IOCACHE_H
24
#include <mysys/my_sys.h>
26
#if defined(__cplusplus)
31
30
struct st_io_cache;
32
31
typedef int (*IO_CACHE_CALLBACK)(struct st_io_cache*);
34
struct st_io_cache /* Used when cacheing files */
33
typedef struct st_io_cache_share
35
pthread_mutex_t mutex; /* To sync on reads into buffer. */
36
pthread_cond_t cond; /* To wait for signals. */
37
pthread_cond_t cond_writer; /* For a synchronized writer. */
38
/* Offset in file corresponding to the first byte of buffer. */
40
/* If a synchronized write cache is the source of the data. */
41
struct st_io_cache *source_cache;
42
unsigned char *buffer; /* The read buffer. */
43
unsigned char *read_end; /* Behind last valid byte of buffer. */
44
int running_threads; /* threads not in lock. */
45
int total_threads; /* threads sharing the cache. */
46
int error; /* Last error. */
49
typedef struct st_io_cache /* Used when cacheing files */
36
51
/* Offset in file corresponding to the first byte of unsigned char* buffer. */
37
52
my_off_t pos_in_file;
72
87
unsigned char **current_pos, **current_end;
89
The lock is for append buffer used in SEQ_READ_APPEND cache
90
need mutex copying from append buffer to read buffer.
92
pthread_mutex_t append_buffer_lock;
94
The following is used when several threads are reading the
95
same file in parallel. They are synchronized on disk
96
accesses reading the cached part of the file asynchronously.
97
It should be set to NULL to disable the feature. Only
98
READ_CACHE mode is supported.
100
IO_CACHE_SHARE *share;
74
102
A caller will use my_b_read() macro to read from the cache
75
103
if the data is already in cache, it will be simply copied with
76
104
memcpy() and internal variables will be accordinging updated with
134
162
my_off_t aio_read_pos;
135
163
my_aio_result aio_result;
179
void close_cached_file();
180
bool real_open_cached_file();
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);
185
void init_functions();
187
bool reinit_io_cache(enum cache_type type_arg,
188
my_off_t seek_offset,
191
void setup_io_cache();
192
bool open_cached_file(const char *dir,
193
const char *prefix, size_t cache_size,
198
typedef struct st_io_cache IO_CACHE; /* Used when cacheing files */
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);
203
extern int my_block_write(st_io_cache *info, const unsigned char *Buffer,
167
/* tell write offset in the SEQ_APPEND cache */
168
int my_b_copy_to_file(IO_CACHE *cache, FILE *file);
169
my_off_t my_b_append_tell(IO_CACHE* info);
170
my_off_t my_b_safe_tell(IO_CACHE* info); /* picks the correct tell() */
172
extern int init_io_cache(IO_CACHE *info,File file,size_t cachesize,
173
enum cache_type type,my_off_t seek_offset,
174
bool use_async_io, myf cache_myflags);
175
extern bool reinit_io_cache(IO_CACHE *info,enum cache_type type,
176
my_off_t seek_offset,bool use_async_io,
178
extern void setup_io_cache(IO_CACHE* info);
179
extern int _my_b_read(IO_CACHE *info,unsigned char *Buffer,size_t Count);
180
extern int _my_b_read_r(IO_CACHE *info,unsigned char *Buffer,size_t Count);
181
extern void init_io_cache_share(IO_CACHE *read_cache, IO_CACHE_SHARE *cshare,
182
IO_CACHE *write_cache, uint32_t num_threads);
183
extern void remove_io_thread(IO_CACHE *info);
184
extern int _my_b_seq_read(IO_CACHE *info,unsigned char *Buffer,size_t Count);
185
extern int _my_b_get(IO_CACHE *info);
186
extern int _my_b_async_read(IO_CACHE *info,unsigned char *Buffer,size_t Count);
187
extern int _my_b_write(IO_CACHE *info,const unsigned char *Buffer,
189
extern int my_b_append(IO_CACHE *info,const unsigned char *Buffer,
191
extern int my_b_safe_write(IO_CACHE *info,const unsigned char *Buffer,
194
extern int my_block_write(IO_CACHE *info, const unsigned char *Buffer,
204
195
size_t Count, my_off_t pos);
205
extern int my_b_flush_io_cache(st_io_cache *info, int need_append_buffer_lock);
196
extern int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock);
207
198
#define flush_io_cache(info) my_b_flush_io_cache((info),1)
209
} /* namespace internal */
210
} /* namespace drizzled */
212
#endif /* DRIZZLED_INTERNAL_IOCACHE_H */
200
extern int end_io_cache(IO_CACHE *info);
201
extern size_t my_b_fill(IO_CACHE *info);
202
extern void my_b_seek(IO_CACHE *info,my_off_t pos);
203
extern size_t my_b_gets(IO_CACHE *info, char *to, size_t max_length);
204
extern my_off_t my_b_filelength(IO_CACHE *info);
205
extern size_t my_b_printf(IO_CACHE *info, const char* fmt, ...);
206
extern size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list ap);
207
extern bool open_cached_file(IO_CACHE *cache,const char *dir,
208
const char *prefix, size_t cache_size,
210
extern bool real_open_cached_file(IO_CACHE *cache);
211
extern void close_cached_file(IO_CACHE *cache);
213
#if defined(__cplusplus)
217
#endif /* MYSYS_IOCACHE_H */