📄 warcriticalsection.h
字号:
/** A fast locking class for * code and data locks. * * * #include "WarCriticalSection.h" <BR> * * */#ifndef WAR_CRITICAL_SECTION_H#define WAR_CRITICAL_SECTION_H/* SYSTEM INCLUDES */#ifndef WAR_ASSERT_H_INCLUDED# define WAR_ASSERT_H_INCLUDED# include <assert.h>#endif#if defined(HAVE_PTHREAD_H) && !defined(WAR_PTHREAD_H_INCLUDED)# define WAR_PTHREAD_H_INCLUDED# include <pthread.h>#endif/* PROJECT INCLUDES */#ifndef WAR_EXCEPTION_H# include "WarException.h"#endif/* LOCAL INCLUDES *//* FORWARD REFERENCES */class WarThreadEvent;#ifdef __cplusplusextern "C" {#endif/****************** BEGIN OLD STYLE C spesific ********//****************** END OLD STYLE C spesific **********/#ifdef __cplusplus }#endif/****************** BEGIN C++ spesific ****************/#ifdef __cplusplusclass WarCriticalSection {public: // LIFECYCLE /** * Default constructor. * * @exception WarException on error */ WarCriticalSection(bool allowRecursive = false) throw(WarException); /** * Destructor. */ ~WarCriticalSection(void); // OPERATORS /** */ inline void Lock() throw(WarException) {#ifdef WIN32 ::EnterCriticalSection(&mHandle);#elif defined(HAVE_PTHREAD_H) int err = pthread_mutex_lock(&mHandle); if (err) WarThrow(WarError(WAR_THREADERR_MUTEX_LOCK_FAILED, err), NULL);#else# error "no threadlib"#endif#ifdef _DEBUG ++mNumLocks; if (!mDoRecursive) assert(mNumLocks == 1);#endif } /** */ inline void Unlock() throw(WarException) {#ifdef _DEBUG --mNumLocks; assert(mNumLocks >= 0); if (!mDoRecursive) assert(mNumLocks == 0);#endif #ifdef WIN32 ::LeaveCriticalSection(&mHandle);#elif defined(HAVE_PTHREAD_H) int err = pthread_mutex_unlock(&mHandle); if (err) WarThrow(WarError(WAR_THREADERR_MUTEX_UNLOCK_FAILED, err), NULL);#else# error "no threadlib"#endif } // OPERATIONS // ACCESS // INQUIRY#ifdef _DEBUG inline int GetLockCount() const { return mNumLocks; }#endif protected:private: friend class WarThreadEvent; war_critsec_t mHandle; bool mDoRecursive; // Recursive locs on a therad#ifdef _DEBUG int mNumLocks;#endif};/* INLINE METHODS *//* EXTERNAL REFERENCES */#endif /* __cplusplus *//****************** END C++ spesific ******************/#endif /* _WAR_CRITICAL_SECTION_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -