MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RefConvert.hpp
1 /*
2  Copyright (C) 2003, 2005, 2006, 2008 MySQL AB, 2008, 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 REFCONVERT_H
20 #define REFCONVERT_H
21 
22 #include <assert.h>
23 #include "kernel_types.h"
24 #include "ndb_limits.h"
25 
26 /*
27  * In multithreaded kernel, BlockNumber includes the main block
28  * number in lower 9 bits and the instance in upper 7 bits.
29  */
30 
31 inline
32 BlockNumber blockToMain(Uint32 block){
33  assert(block < (1 << 16));
34  return (BlockNumber)(block & ((1 << NDBMT_BLOCK_BITS) - 1));
35 }
36 
37 inline
38 BlockInstance blockToInstance(Uint32 block){
39  assert(block < (1 << 16));
40  return (BlockNumber)(block >> NDBMT_BLOCK_BITS);
41 }
42 
43 inline
44 BlockNumber numberToBlock(Uint32 main, Uint32 instance)
45 {
46  assert(main < (1 << NDBMT_BLOCK_BITS) &&
47  instance < (1 << NDBMT_BLOCK_INSTANCE_BITS));
48  return (BlockNumber)(main | (instance << NDBMT_BLOCK_BITS));
49 }
50 
54 inline
55 NodeId refToNode(Uint32 ref){
56  return (NodeId)(ref & ((1 << 16) - 1));
57 }
58 
62 inline
63 BlockNumber refToBlock(Uint32 ref){
64  return (BlockNumber)(ref >> 16);
65 }
66 
71 inline
72 BlockNumber refToMain(Uint32 ref){
73  return (BlockNumber)((ref >> 16) & ((1 << NDBMT_BLOCK_BITS) - 1));
74 }
75 
79 inline
80 BlockInstance refToInstance(Uint32 ref){
81  return (BlockInstance)(ref >> (16 + NDBMT_BLOCK_BITS));
82 }
83 
87 inline
88 BlockReference numberToRef(Uint32 block, Uint32 node){
89  assert(node < (1 << 16) && block < (1 << 16));
90  return (BlockReference)(node | (block << 16));
91 }
92 
96 inline
97 BlockReference numberToRef(Uint32 main, Uint32 instance, Uint32 node){
98  assert(node < (1 << 16) &&
99  main < (1 << NDBMT_BLOCK_BITS) &&
100  instance < (1 << NDBMT_BLOCK_INSTANCE_BITS));
101  return (BlockReference)(node |
102  (main << 16) |
103  (instance << (16 + NDBMT_BLOCK_BITS)));
104 }
105 
106 #endif
107