Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

include/c++/CriticalSectionBlock.H

Go to the documentation of this file.
00001 // The contents of this file are subject to the Mozilla Public License
00002 // Version 1.0 (the "License"); you may not use this file except in
00003 // compliance with the License. You may obtain a copy of the License
00004 // at http://www.mozilla.org/MPL/
00005 // 
00006 // Software distributed under the License is distributed on an "AS IS"
00007 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00008 // the License for the specific language governing rights and
00009 // limitations under the License.
00010 //
00011 // Contributor Henner Zeller <H.Zeller@acm.org>
00012 
00013 #ifndef __CRITICALSECTIONBLOCK_H
00014 #define __CRITICALSECTIONBLOCK_H
00015 
00016 #include <critsec.h>
00017 
00070 class CriticalSectionBlock {
00071 private:
00072         critsec_t *_critsec;
00077         char   _checkonceHackCounter;
00078 
00079 public:
00083         CriticalSectionBlock (critsec_t *critsec) 
00084                 : _critsec(critsec),
00085                   _checkonceHackCounter(1)
00086         { 
00087                 enter_critical_section(_critsec);
00088         }
00089         
00093         inline bool checkonce() { return _checkonceHackCounter-- > 0; }
00094 
00098         ~CriticalSectionBlock () {
00099                 leave_critical_section(_critsec);
00100         }
00101 };
00102 
00131 #define synchronized(cs) for(CriticalSectionBlock __currentlocked(cs);__currentlocked.checkonce();/* */)
00132 
00133 /* 
00134  * Local variables:
00135  * c-basic-offset: 8
00136  * End:
00137  */
00138 
00139 #endif /* __CRITICALSECTIONBLOCK_H */

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

Generated on Mon Feb 16 21:02:10 2004 for brickOS Kernel Developer by doxygen 1.3.5