1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
/* Key cache variable structures */
22
FLUSH_KEEP, /* flush block and keep it in the cache */
23
FLUSH_RELEASE, /* flush block and remove it from the cache */
24
FLUSH_IGNORE_CHANGED, /* remove block from the cache */
26
* As my_disable_flush_pagecache_blocks is always 0, the following option
27
* is strictly equivalent to FLUSH_KEEP
33
/* declare structures that is used by st_key_cache */
36
typedef struct st_block_link BLOCK_LINK;
37
struct st_keycache_page;
38
typedef struct st_keycache_page KEYCACHE_PAGE;
40
typedef struct st_hash_link HASH_LINK;
46
typedef uint64_t my_off_t;
47
struct st_my_thread_var;
50
/* info about requests in a waiting queue */
51
typedef struct st_keycache_wqueue
53
drizzled::internal::st_my_thread_var *last_thread; /* circular list of waiting threads */
56
#define CHANGED_BLOCKS_HASH 128 /* must be power of 2 */
59
The key cache structure
60
It also contains read-only statistics parameters.
63
typedef struct st_key_cache
65
bool key_cache_inited;
66
bool can_be_used; /* usage of cache for read/write is allowed */
68
uint32_t key_cache_block_size; /* size of the page buffer of a cache block */
70
int blocks; /* max number of blocks in the cache */
72
bool in_init; /* Set to 1 in MySQL during init/resize */
75
key_cache_inited(false),
77
key_cache_block_size(0),
84
} /* namespace drizzled */
86
/* The default key cache */
87
extern int init_key_cache(drizzled::KEY_CACHE *keycache, uint32_t key_cache_block_size,
88
size_t use_mem, uint32_t division_limit,
89
uint32_t age_threshold);
90
extern unsigned char *key_cache_read(drizzled::KEY_CACHE *keycache,
91
int file, drizzled::internal::my_off_t filepos, int level,
92
unsigned char *buff, uint32_t length,
93
uint32_t block_length,int return_buffer);
94
extern int key_cache_insert(drizzled::KEY_CACHE *keycache,
95
int file, drizzled::internal::my_off_t filepos, int level,
96
unsigned char *buff, uint32_t length);
97
extern int key_cache_write(drizzled::KEY_CACHE *keycache,
98
int file, drizzled::internal::my_off_t filepos, int level,
99
unsigned char *buff, uint32_t length,
100
uint32_t block_length,int force_write);
101
extern int flush_key_blocks(drizzled::KEY_CACHE *keycache,
102
int file, enum flush_type type);
103
extern void end_key_cache(drizzled::KEY_CACHE *keycache, bool cleanup);
106
Next highest power of two
109
my_round_up_to_next_power()
113
Next or equal power of 2
114
Note: 0 will return 0
117
Algorithm by Sean Anderson, according to:
118
http://graphics.stanford.edu/~seander/bithacks.html
119
(Orignal code public domain)
121
Comments shows how this works with 01100000000000000000000000001011
124
static inline uint32_t my_round_up_to_next_power(uint32_t v)
126
v--; /* 01100000000000000000000000001010 */
127
v|= v >> 1; /* 01110000000000000000000000001111 */
128
v|= v >> 2; /* 01111100000000000000000000001111 */
129
v|= v >> 4; /* 01111111110000000000000000001111 */
130
v|= v >> 8; /* 01111111111111111100000000001111 */
131
v|= v >> 16; /* 01111111111111111111111111111111 */
132
return v+1; /* 10000000000000000000000000000000 */