Mobile API Reference  MicroStrategy 2019
CriticalSection.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : CriticalSection.h
3 // AUTHOR : Jing Ning
4 // CREATION : 9/26/01
5 // Copyright (C) MicroStrategy Incorporated 2001
6 //==============================================================================================
7 #ifndef MSynch_CriticialSection_h
8 #define MSynch_CriticialSection_h
9 
10 #include "Base/Defines/StrongPtr.h"
11 #include "Base/Defines/NoCopy.h"
12 
13 #include "Synch.h"
14 #include "LockCategories.h"
15 
16 namespace MSynch
17 {
19 
25  {
26  public:
27 
30 
32 
38  public MBase::NoCopy
39  {
40  public:
41  // OPTIMIZATION WARNING! The methods on SmartLock are inlined
42  // on purpose for performance reasons.
43  SmartLock(CriticalSection& irCriticalSection):
44  mrCriticalSection(irCriticalSection),
45  mbLocked(true)
46  {
47  mrCriticalSection.Lock();
48  }
49 
50  ~SmartLock() throw()
51  {
52  if (mbLocked)
53  {
54  this->Unlock();
55  }
56  }
57 
58  void Lock()
59  {
60  _ASSERTE(!mbLocked);
61  mrCriticalSection.Lock();
62  mbLocked = true;
63  }
64 
65  void Unlock() throw()
66  {
67  _ASSERTE(mbLocked);
68  mrCriticalSection.Unlock();
69  mbLocked = false;
70  }
71 
72  private:
73  //These members may never be changed or added to.
74  CriticalSection& mrCriticalSection;
75  bool mbLocked;
76  };
77 
79 
82  virtual void SetLockCategory(EnumDSSLockStackCategory iLockStackCategory) = 0;
83 
84  virtual void Delete() throw() = 0;
85 
86  protected:
87  friend class SmartLock;
88 
95  virtual void Lock() = 0;
96 
98  virtual void Unlock() throw() = 0;
99 
100  public:
101  // Pretend these two methods don't exist.
102  // They are only for supporting obsolete
103  // interfaces that have explicit lock/unlock
106  };
107 
108  // this typedef is obsolete
110 
116 
128 }
129 
130 #endif // MSynch_CriticialSection_h
virtual void Unlock()=0
leave the critical section, any waiting thread may enter it now
DLL_SYNCH_EXIM CriticalSection * CreateCriticalSection(EnumDSSLockStackCategory iLockStackCategory=DssLkStkCatNotNestingLock)
void Unlock()
Definition: CriticalSection.h:65
#define _ASSERTE(x)
Definition: Asserte.h:40
MBase::StrongPtr< CriticalSection, MBase::DeleteOperatorGeneric< CriticalSection > > Ptr
Definition: CriticalSection.h:28
Definition: ReferenceCountedImpl.h:18
DLL_SYNCH_EXIM CriticalSection * GetBootstrapCriticalSection()
MBase::ReturnPtr< CriticalSection, MBase::DeleteOperatorGeneric< CriticalSection > > ReturnPtr
Definition: CriticalSection.h:29
virtual void Exception_unsafe_Unlock__which_should_NOT_be_used_because_of_imminent_deadlocks__Use_SmartLock_instead()=0
virtual void SetLockCategory(EnumDSSLockStackCategory iLockStackCategory)=0
SetLockCategory for "late category binding".
#define DLL_SYNCH_EXIM
Definition: Synch.h:17
virtual void Exception_unsafe_Lock__which_should_NOT_be_used_because_of_imminent_deadlocks__Use_SmartLock_instead()=0
SmartLock(CriticalSection &irCriticalSection)
Definition: CriticalSection.h:43
~SmartLock()
Definition: CriticalSection.h:50
Definition: LockCategories.h:35
Definition: StrongPtr.h:50
virtual void Lock()=0
CriticalSection allows only one thread at a time to pass.
Definition: CriticalSection.h:24
Definition: NoCopy.h:21
SmartLock interface.
Definition: CriticalSection.h:37
virtual void Delete()=0
EnumDSSLockStackCategory
Definition: LockCategories.h:32
Definition: ReturnPtr.h:22
void Lock()
Definition: CriticalSection.h:58