00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
00135
00136
00137
00138
00139 #endif