gatelib  2.1
g_mthread_CriticalSection.h
1 #pragma once
2 #include "g_mthread_MutexAbstract.h"
3 
4 #define G_UNIX_CRITICAL_SECTION_SIZEOF (sizeof(void*)*6)
5 
6 namespace g
7 {
8 namespace mthread
9 {
10 
11 //create an anonimous mutex
12 class G_LIB_ITEM CriticalSection : public MutexAbstract
13 {
14  G_COPY_CONSTRUCTOR_PROHIBITED(CriticalSection);
15 public:
16  CriticalSection ( );
17  virtual ~CriticalSection();
18 
19  void setNumMaxSpin ( GInt32_t aSpinMax );
20 
21  virtual void wait ( );
22  virtual bool wait ( GTimeoutSec_t aTimeOutSec );
23  virtual bool tryWait ( );
24  virtual void release ( );
25 
26  GInt32_t getNumRecursion ( ) const { return mNumRecursion; }
27  GInt64_t getThreadLockerId ( ) const { return mThreadLockerId; }
28 
29 private:
30  GInt32_t mNumRecursion;
31 
32 #if G_AUTOPTION_ON_WINDOWS
33  unsigned long mThreadLockerId;
34  long mNumWaiters;
35  unsigned long mNumSpinMax;
36  void* mHandleSemaphore;
37 #else
38  GInt64_t mThreadLockerId;
39 
40  g_raw_buffer<G_UNIX_CRITICAL_SECTION_SIZEOF> mUnixCriticalSectionBuffer;
41 #endif
42 };
43 
44 
45 }//namespace mthread
46 }//namespace g
Definition: g.mthread.ThreadSimpleEvent.h:5
Definition: g_mthread_CriticalSection.h:12
Definition: g_mthread_MutexAbstract.h:14