20 #include <ndbd_exit_codes.h>
23 #define REC_NIL GLOBAL_PAGE_SIZE_WORDS
27 memset(
this, 0,
sizeof(*
this));
28 m_current_pos = RWPage::RWPAGE_WORDS;
29 m_current_first_free = REC_NIL;
30 m_first_free_page = RNIL;
38 m_record_info.m_size = ((ri.m_size + 3) >> 2);
39 m_record_info.m_offset_magic = ((ri.m_offset_magic + 3) >> 2);
40 m_record_info.m_offset_next_pool = ((ri.m_offset_next_pool + 3) >> 2);
42 ndbout_c(
"RWPool::init(%x, %d)",ri.m_type_id, m_record_info.m_size);
48 Uint32 pos = m_current_pos;
49 Uint32
size = m_record_info.m_size;
50 Uint32 off = m_record_info.m_offset_magic;
51 RWPage *pageP = m_current_page;
52 if (likely(m_current_first_free != REC_NIL))
55 pos = m_current_first_free;
56 ptr.i = (m_current_page_no << POOL_RECORD_BITS) + pos;
57 ptr.p = pageP->m_data + pos;
58 pageP->m_data[pos+off] = ~(Uint32)m_record_info.m_type_id;
59 m_current_ref_count++;
60 m_current_first_free = pageP->m_data[pos+m_record_info.m_offset_next_pool];
63 else if (pos + size < RWPage::RWPAGE_WORDS)
66 ptr.i = (m_current_page_no << POOL_RECORD_BITS) + pos;
67 ptr.p = (pageP->m_data + pos);
68 pageP->m_data[pos+off] = ~(Uint32)m_record_info.m_type_id;
69 m_current_ref_count++;
70 m_current_pos = pos + size;
76 m_current_page->m_first_free = REC_NIL;
77 m_current_page->m_next_page = RNIL;
78 m_current_page->m_prev_page = RNIL;
79 m_current_page->m_type_id = m_record_info.m_type_id;
80 m_current_page->m_ref_count = m_current_ref_count;
83 if (m_first_free_page != RNIL)
85 pageP = m_current_page = m_memroot + m_first_free_page;
86 m_current_page_no = m_first_free_page;
87 m_current_pos = RWPage::RWPAGE_WORDS;
88 m_current_first_free = m_current_page->m_first_free;
89 m_first_free_page = m_current_page->m_next_page;
90 m_current_ref_count = m_current_page->m_ref_count;
91 if (m_first_free_page != RNIL)
93 (m_memroot + m_first_free_page)->m_prev_page = RNIL;
98 m_current_ref_count = 0;
101 Uint32 page_no = RNIL;
105 m_current_page_no = page_no;
106 pageP = m_current_page =
page;
107 m_current_first_free = REC_NIL;
108 page->m_type_id = m_record_info.m_type_id;
113 m_current_page_no = RNIL;
114 m_current_pos = RWPage::RWPAGE_WORDS;
115 m_current_first_free = REC_NIL;
123 Uint32 cur_page = m_current_page_no;
124 Uint32 ptr_page = ptr.i >> POOL_RECORD_BITS;
125 Uint32 *record_ptr = (Uint32*)ptr.p;
126 Uint32 magic_val = * (record_ptr + m_record_info.m_offset_magic);
128 if (likely(magic_val == ~(Uint32)m_record_info.m_type_id))
130 * (record_ptr + m_record_info.m_offset_magic) = 0;
131 if (cur_page == ptr_page)
133 * (record_ptr + m_record_info.m_offset_next_pool) = m_current_first_free;
134 assert(m_current_ref_count);
135 m_current_ref_count--;
136 m_current_first_free = ptr.i & POOL_RECORD_MASK;
141 RWPage* page = m_memroot + ptr_page;
142 Uint32 ref_cnt = page->m_ref_count;
143 Uint32 ff = page->m_first_free;
145 * (record_ptr + m_record_info.m_offset_next_pool) = ff;
146 page->m_first_free = ptr.i & POOL_RECORD_MASK;
147 page->m_ref_count = ref_cnt - 1;
154 Uint32 ffp = m_first_free_page;
157 RWPage* next = (m_memroot + ffp);
158 assert(next->m_prev_page == RNIL);
159 next->m_prev_page = ptr_page;
161 page->m_next_page = ffp;
162 page->m_prev_page = RNIL;
163 m_first_free_page = ptr_page;
166 else if(ref_cnt == 1)
171 Uint32 prev = page->m_prev_page;
172 Uint32 next = page->m_next_page;
175 (m_memroot + prev)->m_next_page = next;
179 assert(m_first_free_page == ptr_page);
180 m_first_free_page = next;
185 (m_memroot + next)->m_prev_page = prev;
192 handle_invalid_release(ptr);
196 RWPool::handle_invalid_release(
Ptr<void> ptr)
200 Uint32 pos = ptr.i & POOL_RECORD_MASK;
201 Uint32 pageI = ptr.i >> POOL_RECORD_BITS;
202 Uint32 * record_ptr_p = (Uint32*)ptr.p;
203 Uint32 * record_ptr_i = (m_memroot+pageI)->m_data + pos;
205 Uint32 magic = * (record_ptr_p + m_record_info.m_offset_magic);
207 "Invalid memory release: ptr (%x %p %p) magic: (%.8x %.8x) memroot: %p page: %x",
208 ptr.i, ptr.p, record_ptr_i, magic, m_record_info.m_type_id,
210 (m_memroot+pageI)->m_type_id);
216 RWPool::handle_invalid_get_ptr(Uint32 ptrI)
220 Uint32 pos = ptrI & POOL_RECORD_MASK;
221 Uint32 pageI = ptrI >> POOL_RECORD_BITS;
222 Uint32 * record_ptr_i = (m_memroot+pageI)->m_data + pos;
224 Uint32 magic = * (record_ptr_i + m_record_info.m_offset_magic);
226 "Invalid memory access: ptr (%x %p) magic: (%.8x %.8x) memroot: %p page: %x",
227 ptrI, record_ptr_i, magic, m_record_info.m_type_id,
229 (m_memroot+pageI)->m_type_id);