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

« back to all changes in this revision

Viewing changes to storage/ndb/src/kernel/vm/SignalCounter.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 SIGNAL_COUNTER_HPP
 
17
#define SIGNAL_COUNTER_HPP
 
18
 
 
19
#include <NodeBitmask.hpp>
 
20
#include <ErrorReporter.hpp>
 
21
 
 
22
class SignalCounter {
 
23
  friend struct NodeReceiverGroup;
 
24
  
 
25
private:
 
26
  Uint32 m_count;
 
27
  NdbNodeBitmask m_nodes;
 
28
 
 
29
public:
 
30
  SignalCounter() { clearWaitingFor();}
 
31
  void clearWaitingFor();
 
32
  
 
33
  /**
 
34
   * When sending to different node
 
35
   */
 
36
  void setWaitingFor(Uint32 nodeId);
 
37
  void clearWaitingFor(Uint32 nodeId);
 
38
  void forceClearWaitingFor(Uint32 nodeId);
 
39
  
 
40
  bool isWaitingFor(Uint32 nodeId) const;
 
41
  bool done() const;
 
42
 
 
43
  const char * getText() const;
 
44
 
 
45
  SignalCounter& operator=(const NdbNodeBitmask & bitmask);
 
46
  SignalCounter& operator=(const NodeReceiverGroup& rg) { 
 
47
    return (* this) = rg.m_nodes;
 
48
  }
 
49
 
 
50
  /**
 
51
   * When sending to same node
 
52
   */
 
53
  SignalCounter& operator=(Uint32 count);
 
54
  SignalCounter& operator--(int);
 
55
  SignalCounter& operator++(int);
 
56
  SignalCounter& operator+=(Uint32);
 
57
  Uint32 getCount() const;
 
58
};
 
59
 
 
60
inline
 
61
void 
 
62
SignalCounter::setWaitingFor(Uint32 nodeId) {
 
63
  if(!m_nodes.get(nodeId)){
 
64
    m_nodes.set(nodeId);
 
65
    m_count++;
 
66
    return;
 
67
  }
 
68
  ErrorReporter::handleAssert("SignalCounter::set", __FILE__, __LINE__);
 
69
}
 
70
 
 
71
inline
 
72
bool
 
73
SignalCounter::isWaitingFor(Uint32 nodeId) const {
 
74
  return m_nodes.get(nodeId);
 
75
}
 
76
 
 
77
inline
 
78
bool
 
79
SignalCounter::done() const {
 
80
  return m_count == 0;
 
81
}
 
82
 
 
83
inline
 
84
Uint32
 
85
SignalCounter::getCount() const {
 
86
  return m_count;
 
87
}
 
88
 
 
89
inline
 
90
void
 
91
SignalCounter::clearWaitingFor(Uint32 nodeId) {
 
92
  if(m_nodes.get(nodeId) && m_count > 0){
 
93
    m_count--;
 
94
    m_nodes.clear(nodeId);
 
95
    return;
 
96
  }
 
97
  ErrorReporter::handleAssert("SignalCounter::clear", __FILE__, __LINE__);
 
98
}
 
99
 
 
100
inline
 
101
void
 
102
SignalCounter::clearWaitingFor(){
 
103
  m_count = 0;
 
104
  m_nodes.clear();
 
105
}
 
106
 
 
107
inline
 
108
void
 
109
SignalCounter::forceClearWaitingFor(Uint32 nodeId){
 
110
  if(isWaitingFor(nodeId)){
 
111
    clearWaitingFor(nodeId);
 
112
  }
 
113
}
 
114
 
 
115
inline
 
116
SignalCounter&
 
117
SignalCounter::operator=(Uint32 count){
 
118
  m_count = count;
 
119
  m_nodes.clear();
 
120
  return * this;
 
121
}
 
122
 
 
123
inline
 
124
SignalCounter&
 
125
SignalCounter::operator--(int){
 
126
  if(m_count > 0){
 
127
    m_count--;
 
128
    return * this;
 
129
  }
 
130
  ErrorReporter::handleAssert("SignalCounter::operator--", __FILE__, __LINE__);
 
131
  return * this;
 
132
}
 
133
 
 
134
inline
 
135
SignalCounter&
 
136
SignalCounter::operator++(int){
 
137
  m_count++;
 
138
  return * this;
 
139
}
 
140
 
 
141
inline
 
142
SignalCounter&
 
143
SignalCounter::operator+=(Uint32 n){
 
144
  m_count += n;
 
145
  return * this;
 
146
}
 
147
 
 
148
inline
 
149
const char *
 
150
SignalCounter::getText() const {
 
151
  static char buf[255];
 
152
  static char nodes[NodeBitmask::TextLength+1];
 
153
  BaseString::snprintf(buf, sizeof(buf), "[SignalCounter: m_count=%d %s]", m_count, m_nodes.getText(nodes));
 
154
  return buf;
 
155
}
 
156
 
 
157
inline
 
158
SignalCounter&
 
159
SignalCounter::operator=(const NdbNodeBitmask & bitmask){
 
160
  m_nodes = bitmask;
 
161
  m_count = bitmask.count();
 
162
  return * this;
 
163
}
 
164
 
 
165
#endif