Mobile API Reference  MicroStrategy 2019
Semaphore.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : Semaphore.h
3 // AUTHOR : Douglas Meyer
4 // CREATION : 10/29/2001
5 // Copyright (C) MicroStrategy Incorporated 2001
6 //==============================================================================================
7 #ifndef MSynch_Semaphore_h
8 #define MSynch_Semaphore_h
9 
10 #include "Base/Defines/StrongPtr.h"
11 #include "Base/Defines/NoCopy.h"
13 
14 #include "Synch.h"
15 
16 namespace MSynch
17 {
20 
31  class Semaphore
32  {
33  public:
34 
37 
39 
41 
58  public MBase::NoCopy
59  {
60  public:
61  //The constructor does NOT attempt to wait for a resource.
62  SmartLock(Semaphore& irSemaphore);
63 
64  //If a resource is being held the destructor will automatically make the resource available
65  //If Dismiss was called before destruction then the resource will NOT be made available
66  ~SmartLock() throw();
67 
79  WaitForResourceResult WaitForResource(unsigned Int32 inMilliseconds);
80 
81  // Same as WaitForResource, but will not come back until the resource is available.
82  WaitForResourceResult WaitForeverForResource();
83 
84  //Causes the destructor to NOT make the resource available
85  void Dismiss() throw();
86 
87  //Release the resource back to the semaphore. It can only release the resource that
88  //it previously acquired. Dismiss has no effect on the operation of this method.
89  void ReleaseResource() throw();
90 
91  private:
92  Semaphore& mrSemaphore;
93  bool mbHoldingResource;
94  };
95 
96  //ResourceIsAvailable adds a resource to the pool.
97  virtual void ResourceIsAvailable() = 0;
98 
99  virtual void Delete() throw() = 0;
100 
101  private:
102  friend class SmartLock;
103 
115  virtual WaitForResourceResult WaitForResource(unsigned Int32 inMilliseconds) = 0;
116 
117  // Same as WaitForResource, but will not come back until the resource is available.
118  virtual WaitForResourceResult WaitForeverForResource() = 0;
119  };
120 
121  // this typedef is obsolete
123 
128  unsigned Int32 inInitialAvailableResourceCount,
129  unsigned Int32 inMaximumResourceCount);
130 
131 }
132 
133 #endif // MSynch_Semaphore_h
friend class SmartLock
Definition: Semaphore.h:102
virtual void Delete()=0
Definition: Semaphore.h:38
Definition: ReferenceCountedImpl.h:18
MBase::ReturnPtr< Semaphore, MBase::DeleteOperatorGeneric< Semaphore > > ReturnPtr
Definition: Semaphore.h:36
DLL_SYNCH_EXIM Semaphore * CreateSemaphore(unsigned Int32 inInitialAvailableResourceCount, unsigned Int32 inMaximumResourceCount)
MBase::StrongPtr< Semaphore, MBase::DeleteOperatorGeneric< Semaphore > > Ptr
Definition: Semaphore.h:35
#define Int32
Definition: BasicTypes.h:20
#define DLL_SYNCH_EXIM
Definition: Synch.h:17
WaitForResourceResult
Definition: Semaphore.h:38
Definition: StrongPtr.h:50
Definition: Semaphore.h:31
SmartLock is intended to be created in the stack only.
Definition: Semaphore.h:57
Definition: NoCopy.h:21
virtual void ResourceIsAvailable()=0
Definition: Semaphore.h:38
Definition: ReturnPtr.h:22