MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DynArr256.hpp
1 /*
2  Copyright (C) 2006, 2007 MySQL AB, 2009 Sun Microsystems, Inc.
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #ifndef DYNARR256_HPP
20 #define DYNARR256_HPP
21 
22 #include "Pool.hpp"
23 #include <NdbMutex.h>
24 
25 class DynArr256;
26 struct DA256Page;
27 
29 {
30  friend class DynArr256;
31 public:
32  DynArr256Pool();
33 
34  void init(Uint32 type_id, const Pool_context& pc);
35  void init(NdbMutex*, Uint32 type_id, const Pool_context& pc);
36 
37 protected:
38  Uint32 m_type_id;
39  Uint32 m_first_free;
40  Pool_context m_ctx;
41  struct DA256Page* m_memroot;
42  NdbMutex * m_mutex;
43 
44 private:
45  Uint32 seize();
46  void release(Uint32);
47 };
48 
49 class DynArr256
50 {
51 public:
52  struct Head
53  {
54  Head() { m_ptr_i = RNIL; m_sz = 0;}
55 
56  Uint32 m_ptr_i;
57  Uint32 m_sz;
58 
59  bool isEmpty() const { return m_sz == 0;}
60  };
61 
62  DynArr256(DynArr256Pool & pool, Head& head) :
63  m_head(head), m_pool(pool){}
64 
65  Uint32* set(Uint32 pos);
66  Uint32* get(Uint32 pos) const ;
67 
69  {
70  Uint32 m_sz;
71  Uint32 m_pos;
72  Uint32 m_ptr_i[5];
73  };
74 
75  void init(ReleaseIterator&);
81  Uint32 release(ReleaseIterator&, Uint32* retptr);
82 protected:
83  Head & m_head;
84  DynArr256Pool & m_pool;
85 
86  bool expand(Uint32 pos);
87  void handle_invalid_ptr(Uint32 pos, Uint32 ptrI, Uint32 p0);
88 };
89 
90 #endif