00001 #ifndef CRITICALSECTION_H 00002 #define CRITICALSECTION_H 00003 00004 #include <abuse/abuse.h> 00005 00006 class CriticalSection 00007 { 00008 public: 00009 CriticalSection(); 00010 CriticalSection(const CriticalSection& other); 00011 ~CriticalSection(); 00012 void operator=(const CriticalSection& other); 00013 void enter(); 00014 void leave(); 00015 operator CRITICAL_SECTION&(); 00016 private: 00017 CRITICAL_SECTION m_cs; 00018 int* m_nRefs; 00019 }; 00020 00021 class Locker 00022 { 00023 public: 00024 Locker(CriticalSection& c):m_c(c){m_c.enter();} 00025 ~Locker(){m_c.leave();} 00026 private: 00027 CriticalSection& m_c; 00028 }; 00029 00030 #define LOCK(n) Locker l(n); 00031 #endif