00001 // ZenLib::CriticalSection - CriticalSection functions 00002 // Copyright (C) 2007-2011 MediaArea.net SARL, Info@MediaArea.net 00003 // 00004 // This software is provided 'as-is', without any express or implied 00005 // warranty. In no event will the authors be held liable for any damages 00006 // arising from the use of this software. 00007 // 00008 // Permission is granted to anyone to use this software for any purpose, 00009 // including commercial applications, and to alter it and redistribute it 00010 // freely, subject to the following restrictions: 00011 // 00012 // 1. The origin of this software must not be misrepresented; you must not 00013 // claim that you wrote the original software. If you use this software 00014 // in a product, an acknowledgment in the product documentation would be 00015 // appreciated but is not required. 00016 // 2. Altered source versions must be plainly marked as such, and must not be 00017 // misrepresented as being the original software. 00018 // 3. This notice may not be removed or altered from any source distribution. 00019 // 00020 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00021 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00022 // 00023 // CriticalSection functions 00024 // 00025 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00026 00027 //--------------------------------------------------------------------------- 00028 #ifndef ZenLib_CriticalSectionH 00029 #define ZenLib_CriticalSectionH 00030 //--------------------------------------------------------------------------- 00031 00032 //--------------------------------------------------------------------------- 00033 #ifdef CS 00034 #undef CS //Solaris defines this somewhere 00035 #endif 00036 //--------------------------------------------------------------------------- 00037 00038 namespace ZenLib 00039 { 00040 00041 //*************************************************************************** 00042 /// @brief CriticalSection manipulation 00043 //*************************************************************************** 00044 00045 class CriticalSection 00046 { 00047 public : 00048 //Constructor/Destructor 00049 CriticalSection (); 00050 ~CriticalSection (); 00051 00052 //Enter/Leave 00053 void Enter(); 00054 void Leave(); 00055 00056 private : 00057 void* CritSect; 00058 }; 00059 00060 //*************************************************************************** 00061 /// @brief CriticalSectionLocker helper 00062 //*************************************************************************** 00063 00064 class CriticalSectionLocker 00065 { 00066 public: 00067 CriticalSectionLocker (ZenLib::CriticalSection &CS) 00068 { 00069 CritSec=&CS; 00070 CritSec->Enter(); 00071 } 00072 00073 ~CriticalSectionLocker () 00074 { 00075 CritSec->Leave(); 00076 } 00077 00078 private: 00079 ZenLib::CriticalSection *CritSec; 00080 }; 00081 00082 } //NameSpace 00083 00084 #endif