MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RWPool.hpp
1 /*
2  Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #ifndef RWPOOL_HPP
19 #define RWPOOL_HPP
20 
21 #include "Pool.hpp"
22 
23 struct RWPage
24 {
25  STATIC_CONST( RWPAGE_WORDS = GLOBAL_PAGE_SIZE_WORDS - 4 );
26 
27  Uint32 m_type_id;
28  Uint16 m_first_free;
29  Uint16 m_ref_count;
30  Uint32 m_next_page;
31  Uint32 m_prev_page;
32  Uint32 m_data[RWPAGE_WORDS];
33 };
34 
38 struct RWPool
39 {
40  Record_info m_record_info;
41  RWPage* m_memroot;
42  RWPage* m_current_page;
43  Pool_context m_ctx;
44  Uint32 m_first_free_page;
45  Uint32 m_current_page_no;
46  Uint16 m_current_pos;
47  Uint16 m_current_first_free;
48  Uint16 m_current_ref_count;
49 public:
50  RWPool();
51 
52  void init(const Record_info& ri, const Pool_context& pc);
53  bool seize(Ptr<void>&);
54  void release(Ptr<void>);
55  void * getPtr(Uint32 i);
56  void * getPtr(const Record_info&ri, Uint32 i);
57 
58  STATIC_CONST( WORDS_PER_PAGE = RWPage::RWPAGE_WORDS );
59 
60 private:
61  void handle_invalid_release(Ptr<void>) ATTRIBUTE_NORETURN;
62  void handle_invalid_get_ptr(Uint32 i) ATTRIBUTE_NORETURN;
63 };
64 
65 inline
66 void*
67 RWPool::getPtr(Uint32 i)
68 {
69  Uint32 page_no = i >> POOL_RECORD_BITS;
70  Uint32 page_idx = i & POOL_RECORD_MASK;
71  RWPage * page = m_memroot + page_no;
72  Uint32 * record = page->m_data + page_idx;
73  Uint32 magic_val = * (record + m_record_info.m_offset_magic);
74  if (likely(magic_val == ~(Uint32)m_record_info.m_type_id))
75  {
76  return record;
77  }
78  handle_invalid_get_ptr(i);
79  return 0; /* purify: deadcode */
80 }
81 
82 inline
83 void*
84 RWPool::getPtr(const Record_info &ri, Uint32 i)
85 {
86  Uint32 page_no = i >> POOL_RECORD_BITS;
87  Uint32 page_idx = i & POOL_RECORD_MASK;
88  RWPage * page = m_memroot + page_no;
89  Uint32 * record = page->m_data + page_idx;
90  Uint32 magic_val = * (record + ri.m_offset_magic);
91  if (likely(magic_val == ~(Uint32)ri.m_type_id))
92  {
93  return record;
94  }
95  handle_invalid_get_ptr(i);
96  return 0; /* purify: deadcode */
97 }
98 
99 #endif