~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/ndb/include/kernel/NodeBitmask.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#ifndef NODE_BITMASK_HPP
 
17
#define NODE_BITMASK_HPP
 
18
 
 
19
#include <ndb_limits.h>
 
20
#include <kernel_types.h>
 
21
#include <Bitmask.hpp>
 
22
 
 
23
/**
 
24
 * No of 32 bits words needed to store a node bitmask
 
25
 *   containing all the nodes in the system
 
26
 *   Both NDB nodes and API, MGM... nodes
 
27
 *
 
28
 * Note that this is used in a lot of signals
 
29
 */
 
30
#define _NODE_BITMASK_SIZE 2
 
31
 
 
32
/**
 
33
 * No of 32 bits words needed to store a node bitmask
 
34
 *   containing all the ndb nodes in the system
 
35
 *
 
36
 * Note that this is used in a lot of signals
 
37
 */
 
38
#define _NDB_NODE_BITMASK_SIZE 2
 
39
 
 
40
/**
 
41
 * No of 32 bits word needed to store B bits for N nodes
 
42
 */
 
43
#define NODE_ARRAY_SIZE(N, B) (((N)*(B)+31) >> 5)
 
44
 
 
45
typedef Bitmask<(unsigned int)_NODE_BITMASK_SIZE> NodeBitmask;
 
46
 
 
47
typedef Bitmask<(unsigned int)_NDB_NODE_BITMASK_SIZE> NdbNodeBitmask;
 
48
 
 
49
#define __NBM_SZ  ((MAX_NODES >> 5) + ((MAX_NODES & 31) != 0))
 
50
#define __NNBM_SZ ((MAX_NDB_NODES >> 5) + ((MAX_NDB_NODES & 31) != 0))
 
51
 
 
52
#if ( __NBM_SZ > _NODE_BITMASK_SIZE)
 
53
#error "MAX_NODES can not fit into NODE_BITMASK_SIZE"
 
54
#endif
 
55
 
 
56
#if ( __NNBM_SZ > _NDB_NODE_BITMASK_SIZE)
 
57
#error "MAX_NDB_NODES can not fit into NDB_NODE_BITMASK_SIZE"
 
58
#endif
 
59
 
 
60
/**
 
61
 * General B Bits operations
 
62
 *
 
63
 * Get(x, A[], B)
 
64
 *   w = x >> S1
 
65
 *   s = (x & S2) << S3
 
66
 *   return (A[w] >> s) & S4
 
67
 *
 
68
 * Set(x, A[], v, B)
 
69
 *   w    = x >> S1
 
70
 *   s    = (x & S2) << S3
 
71
 *   m    = ~(S4 << s)
 
72
 *   t    = A[w] & m;
 
73
 *   A[w] = t | ((v & S4) << s)
 
74
 *
 
75
 * B(Bits)    S1    S2    S3     S4
 
76
 *    1        5    31     0      1
 
77
 *    2        4    15     1      3
 
78
 *    4        3     7     2     15
 
79
 *    8        2     3     3    255
 
80
 *   16        1     1     4  65535
 
81
 *
 
82
 * S1 = 5 - 2log(B)
 
83
 * S2 = 2^S1 - 1
 
84
 * S3 = 2log(B)
 
85
 * S4 = 2^B - 1
 
86
 */
 
87
 
 
88
#endif