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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
19
#include <ndb_global.h>
20
#include <kernel_types.h>
25
* Type id is 11 bits record type, and 5 bits resource id
26
* -> 2048 different kind of records and 32 different resource groups
28
* Resource id is used to handle configuration parameters
30
* see blocks/records_types.hpp
33
#define RG_MASK ((1 << RG_BITS) - 1)
34
#define MAKE_TID(TID,RG) ((TID << RG_BITS) | RG)
39
#define POOL_RECORD_BITS 13
40
#define POOL_RECORD_MASK ((1 << POOL_RECORD_BITS) - 1)
50
Uint16 m_offset_next_pool;
51
Uint16 m_offset_magic;
68
class SimulatedBlock* m_block;
76
* Alloc consekutive pages
78
* @param i : out : i value of first page
79
* @return : pointer to first page (NULL if failed)
81
* Will handle resource limit
83
void* alloc_page(Uint32 type_id, Uint32 *i);
88
* @param i : in : i value of first page
89
* @param p : in : pointer to first page
91
void release_page(Uint32 type_id, Uint32 i);
94
* Alloc consekutive pages
96
* @param cnt : in/out : no of requested pages,
97
* return no of allocated (undefined return NULL)
98
* out will never be > in
99
* @param i : out : i value of first page
100
* @param min : in : will never allocate less than min
101
* @return : pointer to first page (NULL if failed)
103
* Will handle resource limit
105
void* alloc_pages(Uint32 type_id, Uint32 *i, Uint32 *cnt, Uint32 min =1);
110
* @param i : in : i value of first page
111
* @param p : in : pointer to first page
112
* @param cnt : in : no of pages to release
114
void release_pages(Uint32 type_id, Uint32 i, Uint32 cnt);
119
void handleAbort(int code, const char* msg);
122
template <typename T>
127
inline bool isNull() const { return i == RNIL; }
128
inline void setNull() { i = RNIL; }
131
template <typename T>
136
inline bool isNull() const { return i == RNIL; }
137
inline void setNull() { i = RNIL; }
140
#ifdef XX_DOCUMENTATION_XX
142
* Any pool should implement the following
147
Record_info m_record_info;
149
void init(const Record_info& ri, const Pool_context& pc);
150
void init(const Record_info& ri, const Pool_context& pc);
152
bool seize(Ptr<void>&);
153
void release(Ptr<void>);
154
void * getPtr(Uint32 i);
158
template <typename T, typename P>
164
void init(Uint32 type_id, const Pool_context& pc);
165
void wo_pool_init(Uint32 type_id, const Pool_context& pc);
168
* Update p value for ptr according to i value
170
void getPtr(Ptr<T> &);
171
void getPtr(ConstPtr<T> &) const;
174
* Get pointer for i value
176
T * getPtr(Uint32 i);
177
const T * getConstPtr(Uint32 i) const;
180
* Update p & i value for ptr according to <b>i</b> value
182
void getPtr(Ptr<T> &, Uint32 i);
183
void getPtr(ConstPtr<T> &, Uint32 i) const;
186
* Allocate an object from pool - update Ptr
190
bool seize(Ptr<T> &);
193
* Return an object to pool
195
void release(Uint32 i);
198
* Return an object to pool
200
void release(Ptr<T>);
205
template <typename T, typename P>
207
RecordPool<T, P>::RecordPool()
211
template <typename T, typename P>
214
RecordPool<T, P>::init(Uint32 type_id, const Pool_context& pc)
217
const char * off_base = (char*)&tmp;
218
const char * off_next = (char*)&tmp.nextPool;
219
const char * off_magic = (char*)&tmp.m_magic;
222
ri.m_size = sizeof(T);
223
ri.m_offset_next_pool = Uint32(off_next - off_base);
224
ri.m_offset_magic = Uint32(off_magic - off_base);
225
ri.m_type_id = type_id;
229
template <typename T, typename P>
232
RecordPool<T, P>::wo_pool_init(Uint32 type_id, const Pool_context& pc)
235
const char * off_base = (char*)&tmp;
236
const char * off_magic = (char*)&tmp.m_magic;
239
ri.m_size = sizeof(T);
240
ri.m_offset_next_pool = 0;
241
ri.m_offset_magic = Uint32(off_magic - off_base);
242
ri.m_type_id = type_id;
246
template <typename T, typename P>
248
RecordPool<T, P>::~RecordPool()
253
template <typename T, typename P>
256
RecordPool<T, P>::getPtr(Ptr<T> & ptr)
258
ptr.p = static_cast<T*>(m_pool.getPtr(ptr.i));
261
template <typename T, typename P>
264
RecordPool<T, P>::getPtr(ConstPtr<T> & ptr) const
266
ptr.p = static_cast<const T*>(m_pool.getPtr(ptr.i));
269
template <typename T, typename P>
272
RecordPool<T, P>::getPtr(Ptr<T> & ptr, Uint32 i)
275
ptr.p = static_cast<T*>(m_pool.getPtr(ptr.i));
278
template <typename T, typename P>
281
RecordPool<T, P>::getPtr(ConstPtr<T> & ptr, Uint32 i) const
284
ptr.p = static_cast<const T*>(m_pool.getPtr(ptr.i));
287
template <typename T, typename P>
290
RecordPool<T, P>::getPtr(Uint32 i)
292
return static_cast<T*>(m_pool.getPtr(i));
295
template <typename T, typename P>
298
RecordPool<T, P>::getConstPtr(Uint32 i) const
300
return static_cast<const T*>(m_pool.getPtr(i));
303
template <typename T, typename P>
306
RecordPool<T, P>::seize(Ptr<T> & ptr)
309
bool ret = m_pool.seize(tmp);
313
ptr.p = static_cast<T*>(tmp.p);
318
template <typename T, typename P>
321
RecordPool<T, P>::release(Uint32 i)
325
ptr.p = m_pool.getPtr(i);
329
template <typename T, typename P>
332
RecordPool<T, P>::release(Ptr<T> ptr)