MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SignalCounter.hpp
1 /*
2  Copyright (C) 2003-2007 MySQL AB
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 SIGNAL_COUNTER_HPP
20 #define SIGNAL_COUNTER_HPP
21 
22 #include <NodeBitmask.hpp>
23 #include <ErrorReporter.hpp>
24 
26  friend struct NodeReceiverGroup;
27 
28 private:
29  Uint32 m_count;
30  NdbNodeBitmask m_nodes;
31 
32 public:
33  SignalCounter() { clearWaitingFor();}
34  void clearWaitingFor();
35 
39  void setWaitingFor(Uint32 nodeId);
40  void clearWaitingFor(Uint32 nodeId);
41  void forceClearWaitingFor(Uint32 nodeId);
42 
43  bool isWaitingFor(Uint32 nodeId) const;
44  bool done() const;
45 
46  const char * getText() const;
47 
48  SignalCounter& operator=(const NdbNodeBitmask & bitmask);
49  SignalCounter& operator=(const NodeReceiverGroup& rg);
50 
54  SignalCounter& operator=(Uint32 count);
55  SignalCounter& operator--(int);
56  SignalCounter& operator++(int);
57  SignalCounter& operator+=(Uint32);
58  Uint32 getCount() const;
59 };
60 
61 inline
62 void
64  if(!m_nodes.get(nodeId)){
65  m_nodes.set(nodeId);
66  m_count++;
67  return;
68  }
69  ErrorReporter::handleAssert("SignalCounter::set", __FILE__, __LINE__);
70 }
71 
72 inline
73 bool
74 SignalCounter::isWaitingFor(Uint32 nodeId) const {
75  return m_nodes.get(nodeId);
76 }
77 
78 inline
79 bool
80 SignalCounter::done() const {
81  return m_count == 0;
82 }
83 
84 inline
85 Uint32
86 SignalCounter::getCount() const {
87  return m_count;
88 }
89 
90 inline
91 void
92 SignalCounter::clearWaitingFor(Uint32 nodeId) {
93  if(m_nodes.get(nodeId) && m_count > 0){
94  m_count--;
95  m_nodes.clear(nodeId);
96  return;
97  }
98  ErrorReporter::handleAssert("SignalCounter::clear", __FILE__, __LINE__);
99 }
100 
101 inline
102 void
103 SignalCounter::clearWaitingFor(){
104  m_count = 0;
105  m_nodes.clear();
106 }
107 
108 inline
109 void
110 SignalCounter::forceClearWaitingFor(Uint32 nodeId){
111  if(isWaitingFor(nodeId)){
112  clearWaitingFor(nodeId);
113  }
114 }
115 
116 inline
118 SignalCounter::operator=(Uint32 count){
119  m_count = count;
120  m_nodes.clear();
121  return * this;
122 }
123 
124 inline
126 SignalCounter::operator--(int){
127  if(m_count > 0){
128  m_count--;
129  return * this;
130  }
131  ErrorReporter::handleAssert("SignalCounter::operator--", __FILE__, __LINE__);
132  return * this;
133 }
134 
135 inline
137 SignalCounter::operator++(int){
138  m_count++;
139  return * this;
140 }
141 
142 inline
144 SignalCounter::operator+=(Uint32 n){
145  m_count += n;
146  return * this;
147 }
148 
149 inline
150 const char *
151 SignalCounter::getText() const {
152  static char buf[255];
153  static char nodes[NdbNodeBitmask::TextLength+1];
154  BaseString::snprintf(buf, sizeof(buf), "[SignalCounter: m_count=%d %s]", m_count, m_nodes.getText(nodes));
155  return buf;
156 }
157 
158 inline
160 SignalCounter::operator=(const NdbNodeBitmask & bitmask){
161  m_nodes = bitmask;
162  m_count = bitmask.count();
163  return * this;
164 }
165 
166 inline
168 SignalCounter::operator=(const NodeReceiverGroup & rg){
169  assert(rg.m_nodes.find(65) == NodeBitmask::NotFound);
170  memcpy(&m_nodes, &rg.m_nodes, sizeof(m_nodes));
171  m_count = m_nodes.count();
172  return * this;
173 }
174 
175 #endif