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:
78 
79 public:
84  : _critsec(critsec),
86  {
88  }
89 
93  inline bool checkonce() { return _checkonceHackCounter-- > 0; }
94 
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 */
CriticalSectionBlock::CriticalSectionBlock
CriticalSectionBlock(critsec_t *critsec)
Constructor locks the critical section.
Definition: CriticalSectionBlock.H:83
CriticalSectionBlock
A CriticalSectionBlock locks a critical section for the lifetime of the CriticalSectionBlock.
Definition: CriticalSectionBlock.H:70
critsec
critical section data structure
Definition: critsec.h:48
CriticalSectionBlock::_checkonceHackCounter
char _checkonceHackCounter
little hack, to make it possible to implement the synchronized() macro with the for(;;) loop below.
Definition: CriticalSectionBlock.H:77
leave_critical_section
#define leave_critical_section(cs)
leave critical section
Definition: critsec.h:101
CriticalSectionBlock::~CriticalSectionBlock
~CriticalSectionBlock()
destructor automatically unlocks the critical section.
Definition: CriticalSectionBlock.H:98
enter_critical_section
int enter_critical_section(critsec_t *cs)
lock a critical section, or wait until it is available.
Definition: critsec.c:96
CriticalSectionBlock::_critsec
critsec_t * _critsec
Definition: CriticalSectionBlock.H:72
CriticalSectionBlock::checkonce
bool checkonce()
don't use.
Definition: CriticalSectionBlock.H:93

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

Generated for brickOS Kernel Developer by doxygen 1.8.16