1 /*
2    Copyright (c) 2003, 2021, Oracle and/or its affiliates.
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, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License, version 2.0, for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24 
25 #ifndef NODE_BITMASK_HPP
26 #define NODE_BITMASK_HPP
27 
28 #include "ndb_limits.h"
29 #include "kernel_types.h"
30 #include <Bitmask.hpp>
31 
32 #define JAM_FILE_ID 2
33 
34 
35 /**
36  * No of 32 bits words needed to store a node bitmask
37  *   containing all the nodes in the system
38  *   Both NDB nodes and API, MGM... nodes
39  *
40  * Note that this is used in a lot of signals
41  */
42 #define _NODE_BITMASK_SIZE 8
43 
44 /**
45  * No of 32 bits words needed to store a node bitmask
46  *   containing all the ndb nodes in the system
47  *
48  * Note that this is used in a lot of signals
49  */
50 #define _NDB_NODE_BITMASK_SIZE 2
51 
52 /**
53  * No of 32 bits word needed to store B bits for N nodes
54  */
55 #define NODE_ARRAY_SIZE(N, B) (((N)*(B)+31) >> 5)
56 
57 typedef Bitmask<(unsigned int)_NODE_BITMASK_SIZE> NodeBitmask;
58 typedef BitmaskPOD<(unsigned int)_NODE_BITMASK_SIZE> NodeBitmaskPOD;
59 
60 typedef Bitmask<(unsigned int)_NDB_NODE_BITMASK_SIZE> NdbNodeBitmask;
61 typedef BitmaskPOD<(unsigned int)_NDB_NODE_BITMASK_SIZE> NdbNodeBitmaskPOD;
62 
63 #define __NBM_SZ  ((MAX_NODES >> 5) + ((MAX_NODES & 31) != 0))
64 #define __NNBM_SZ ((MAX_NDB_NODES >> 5) + ((MAX_NDB_NODES & 31) != 0))
65 
66 #if ( __NBM_SZ > _NODE_BITMASK_SIZE)
67 #error "MAX_NODES can not fit into NODE_BITMASK_SIZE"
68 #endif
69 
70 #if ( __NNBM_SZ > _NDB_NODE_BITMASK_SIZE)
71 #error "MAX_NDB_NODES can not fit into NDB_NODE_BITMASK_SIZE"
72 #endif
73 
74 /**
75  * General B Bits operations
76  *
77  * Get(x, A[], B)
78  *   w = x >> S1
79  *   s = (x & S2) << S3
80  *   return (A[w] >> s) & S4
81  *
82  * Set(x, A[], v, B)
83  *   w    = x >> S1
84  *   s    = (x & S2) << S3
85  *   m    = ~(S4 << s)
86  *   t    = A[w] & m;
87  *   A[w] = t | ((v & S4) << s)
88  *
89  * B(Bits)    S1    S2    S3     S4
90  *    1        5    31     0      1
91  *    2        4    15     1      3
92  *    4        3     7     2     15
93  *    8        2     3     3    255
94  *   16        1     1     4  65535
95  *
96  * S1 = 5 - 2log(B)
97  * S2 = 2^S1 - 1
98  * S3 = 2log(B)
99  * S4 = 2^B - 1
100  */
101 
102 
103 #undef JAM_FILE_ID
104 
105 #endif
106