sipxportlib  Version 3.3
OsLock.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006-2021 SIPez LLC.
3 // Licensed to SIPfoundry under a Contributor Agreement.
4 //
5 // Copyright (C) 2004-2006 SIPfoundry Inc.
6 // Licensed by SIPfoundry under the LGPL license.
7 //
8 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
9 // Licensed to SIPfoundry under a Contributor Agreement.
10 //
11 // $$
13 
14 
15 #ifndef _OsLock_h_
16 #define _OsLock_h_
17 
18 // SYSTEM INCLUDES
19 
20 // APPLICATION INCLUDES
21 #include <os/OsSyncBase.h>
22 
23 // DEFINES
24 // MACROS
25 // EXTERNAL FUNCTIONS
26 // EXTERNAL VARIABLES
27 // CONSTANTS
28 // STRUCTS
29 // TYPEDEFS
30 // FORWARD DECLARATIONS
31 
52 class OsLock
53 {
54 /* //////////////////////////// PUBLIC //////////////////////////////////// */
55 public:
56  typedef enum TakeStateEnum
57  {
63 /* ============================ CREATORS ================================== */
64 
66  OsLock(OsSyncBase& rSemaphore, void (*lockStateCallback)(OsLockTakeState state, void* data) = NULL, void* callbackData = NULL)
67  : mrSemaphore(rSemaphore),
68  mStateCallback(lockStateCallback),
69  mCallbackData(callbackData)
70  {
71  if (mStateCallback) mStateCallback(PreAcquire, mCallbackData);
72  rSemaphore.acquire();
73  if (mStateCallback) mStateCallback(PostAcquire, mCallbackData);
74  };
75 
77  virtual
79  {
80  mrSemaphore.release();
81  if (mStateCallback) mStateCallback(PostRelease, mCallbackData);
82  };
83 
84 /* ============================ MANIPULATORS ============================== */
85 
86 /* ============================ ACCESSORS ================================= */
87 
88 /* ============================ INQUIRY =================================== */
89 
90 /* //////////////////////////// PROTECTED ///////////////////////////////// */
91 protected:
92 
93 /* //////////////////////////// PRIVATE /////////////////////////////////// */
94 private:
95  OsSyncBase& mrSemaphore;
96 
98  OsLock();
99 
101  OsLock(const OsLock& rOsLock);
102 
104  OsLock& operator=(const OsLock& rhs);
105 
106  void (*mStateCallback)(OsLockTakeState state, void* data);
107  void* mCallbackData;
108 };
109 
110 /* ============================ INLINE METHODS ============================ */
111 
112 #endif // _OsLock_h_
113 
virtual ~OsLock()
Destructor.
Definition: OsLock.h:78
Definition: OsLock.h:58
Base class for the synchronization mechanisms in the OS abstraction layer.
Definition: OsSyncBase.h:46
Lock class for mutual exclusion in a critical section.
Definition: OsLock.h:52
OsLock(OsSyncBase &rSemaphore, void(*lockStateCallback)(OsLockTakeState state, void *data)=NULL, void *callbackData=NULL)
Constructor.
Definition: OsLock.h:66
#define NULL
Definition: UtlDefs.h:29
Definition: OsLock.h:60
Definition: OsLock.h:59
enum OsLock::TakeStateEnum OsLockTakeState
Definition: OsLock.h:61
virtual OsStatus acquire(const OsTime &rTimeout=OsTime::OS_INFINITY)=0
Block until the sync object is acquired or the timeout expires.
virtual OsStatus release(void)=0
Release the sync object.
TakeStateEnum
Definition: OsLock.h:56