00001 /* Copyright (c) MediaArea.net SARL. All Rights Reserved. 00002 * 00003 * Use of this source code is governed by a zlib-style license that can 00004 * be found in the License.txt file in the root of the source tree. 00005 */ 00006 00007 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00008 // 00009 // CriticalSection functions 00010 // 00011 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00012 00013 //--------------------------------------------------------------------------- 00014 #ifndef ZenLib_CriticalSectionH 00015 #define ZenLib_CriticalSectionH 00016 //--------------------------------------------------------------------------- 00017 00018 //--------------------------------------------------------------------------- 00019 #ifdef CS 00020 #undef CS //Solaris defines this somewhere 00021 #endif 00022 //--------------------------------------------------------------------------- 00023 00024 namespace ZenLib 00025 { 00026 00027 //*************************************************************************** 00028 /// @brief CriticalSection manipulation 00029 //*************************************************************************** 00030 00031 class CriticalSection 00032 { 00033 public : 00034 //Constructor/Destructor 00035 CriticalSection (); 00036 ~CriticalSection (); 00037 00038 //Enter/Leave 00039 void Enter(); 00040 void Leave(); 00041 00042 private : 00043 void* CritSect; 00044 }; 00045 00046 //*************************************************************************** 00047 /// @brief CriticalSectionLocker helper 00048 //*************************************************************************** 00049 00050 class CriticalSectionLocker 00051 { 00052 public: 00053 CriticalSectionLocker (ZenLib::CriticalSection &CS) 00054 { 00055 CritSec=&CS; 00056 CritSec->Enter(); 00057 } 00058 00059 ~CriticalSectionLocker () 00060 { 00061 CritSec->Leave(); 00062 } 00063 00064 private: 00065 ZenLib::CriticalSection *CritSec; 00066 }; 00067 00068 } //NameSpace 00069 00070 #endif