00001 #ifndef WINCMP_MISC_CCRITICALSECTION_H
00002 #define WINCMP_MISC_CCRITICALSECTION_H
00003 #if _MSC_VER >= 1000
00004 #pragma once
00005 #endif // _MSC_VER >= 1000
00006
00007 #include <Base/BaseDebug.h>
00008 #include <vector>
00009 namespace Spr {
00010
00011 class SPR_DLL WBCriticalSection{
00012 CRITICAL_SECTION cr;
00013 public:
00014 WBCriticalSection(){
00015 InitializeCriticalSection(&cr);
00016 }
00017 ~WBCriticalSection(){
00018 DeleteCriticalSection(&cr);
00019 }
00020 void Enter(){
00021 EnterCriticalSection(&cr);
00022 }
00023 void Leave(){
00024 LeaveCriticalSection(&cr);
00025 }
00026 };
00027
00028 struct WBAutoLock{
00029 WBCriticalSection& cr;
00030 WBAutoLock(WBCriticalSection& c):cr(c){
00031 cr.Enter();
00032 }
00033 ~WBAutoLock(){
00034 cr.Leave();
00035 }
00036 };
00037
00038 }
00039
00040 #endif