1 /* Copyright (c) 2003, 2006, 2007 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 Street, Fifth Floor, Boston, MA 02110-1301, USA */
23 STATIC_CONST( WOPAGE_WORDS
= GLOBAL_PAGE_SIZE_WORDS
- 2 );
27 Uint32 m_data
[WOPAGE_WORDS
];
35 Record_info m_record_info
;
37 WOPage
* m_current_page
;
39 Uint32 m_current_page_no
;
41 Uint16 m_current_ref_count
;
45 void init(const Record_info
& ri
, const Pool_context
& pc
);
46 bool seize(Ptr
<void>&);
47 void release(Ptr
<void>);
48 void * getPtr(Uint32 i
);
51 bool seize_new_page(Ptr
<void>&);
52 void release_not_current(Ptr
<void>);
54 void handle_invalid_release(Ptr
<void>);
55 void handle_invalid_get_ptr(Uint32 i
);
56 void handle_inconsistent_release(Ptr
<void>);
61 WOPool::seize(Ptr
<void>& ptr
)
63 Uint32 pos
= m_current_pos
;
64 Uint32 size
= m_record_info
.m_size
;
65 WOPage
*pageP
= m_current_page
;
66 if (likely(pos
+ size
< WOPage::WOPAGE_WORDS
))
68 ptr
.i
= (m_current_page_no
<< POOL_RECORD_BITS
) + pos
;
69 ptr
.p
= (pageP
->m_data
+ pos
);
70 pageP
->m_data
[pos
+m_record_info
.m_offset_magic
] = ~(Uint32
)m_record_info
.m_type_id
;
71 m_current_pos
= pos
+ size
;
72 m_current_ref_count
++;
76 return seize_new_page(ptr
);
81 WOPool::release(Ptr
<void> ptr
)
83 Uint32 cur_page
= m_current_page_no
;
84 Uint32 ptr_page
= ptr
.i
>> POOL_RECORD_BITS
;
85 Uint32
*magic_ptr
= (((Uint32
*)ptr
.p
)+m_record_info
.m_offset_magic
);
86 Uint32 magic_val
= *magic_ptr
;
88 if (likely(magic_val
== ~(Uint32
)m_record_info
.m_type_id
))
91 if (cur_page
== ptr_page
)
93 if (m_current_ref_count
== 1)
97 m_current_ref_count
--;
100 return release_not_current(ptr
);
102 handle_invalid_release(ptr
);
107 WOPool::getPtr(Uint32 i
)
109 Uint32 page_no
= i
>> POOL_RECORD_BITS
;
110 Uint32 page_idx
= i
& POOL_RECORD_MASK
;
111 WOPage
* page
= m_memroot
+ page_no
;
112 Uint32
* record
= page
->m_data
+ page_idx
;
113 Uint32 magic_val
= * (record
+ m_record_info
.m_offset_magic
);
114 if (likely(magic_val
== ~(Uint32
)m_record_info
.m_type_id
))
118 handle_invalid_get_ptr(i
);
119 return 0; /* purify: deadcode */