CriticalSectionBlock.H
Go to the documentation of this file.
1 // The contents of this file are subject to the Mozilla Public License
2 // Version 1.0 (the "License"); you may not use this file except in
3 // compliance with the License. You may obtain a copy of the License
4 // at http://www.mozilla.org/MPL/
5 //
6 // Software distributed under the License is distributed on an "AS IS"
7 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8 // the License for the specific language governing rights and
9 // limitations under the License.
10 //
11 // Contributor Henner Zeller <H.Zeller@acm.org>
12 
13 #ifndef __CRITICALSECTIONBLOCK_H
14 #define __CRITICALSECTIONBLOCK_H
15 
16 #include <critsec.h>
17 
71 private:
72  critsec_t *_critsec;
77  char _checkonceHackCounter;
78 
79 public:
84  : _critsec(critsec),
85  _checkonceHackCounter(1)
86  {
87  enter_critical_section(_critsec);
88  }
89 
93  inline bool checkonce() { return _checkonceHackCounter-- > 0; }
94 
99  leave_critical_section(_critsec);
100  }
101 };
102 
131 #define synchronized(cs) for(CriticalSectionBlock __currentlocked(cs);__currentlocked.checkonce();/* */)
132 
133 /*
134  * Local variables:
135  * c-basic-offset: 8
136  * End:
137  */
138 
139 #endif /* __CRITICALSECTIONBLOCK_H */
struct critsec critsec_t
critical section type definition
Definition: critsec.h:55
~CriticalSectionBlock()
destructor automatically unlocks the critical section.
#define leave_critical_section(cs)
leave critical section
Definition: critsec.h:101
CriticalSectionBlock(critsec_t *critsec)
Constructor locks the critical section.
bool checkonce()
don&#39;t use.
A CriticalSectionBlock locks a critical section for the lifetime of the CriticalSectionBlock.
int enter_critical_section(critsec_t *cs)
enter critical section
Interface: critical section management.

brickOS is released under the Mozilla Public License.
Original code copyright 1998-2005 by the authors.

Generated for brickOS C++ by doxygen 1.8.11