sipxportlib  Version 3.3
OsCSem.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2006 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 #ifndef _OsCSem_h_
15 #define _OsCSem_h_
16 
17 // SYSTEM INCLUDES
18 
19 // APPLICATION INCLUDES
20 #include "os/OsDefs.h"
21 #include "os/OsSyncBase.h"
22 #include "os/OsBSem.h"
23 
24 // DEFINES
25 
26 //Uncomment next line to see semaphore errors when they occur
27 //#define OS_CSEM_DEBUG
28 
29 //Uncomment next line (as well as above line) to see all acquires and releases.
30 //#define OS_CSEM_DEBUG_SHOWALL
31 
32 // MACROS
33 // EXTERNAL FUNCTIONS
34 // EXTERNAL VARIABLES
35 // CONSTANTS
36 // STRUCTS
37 // TYPEDEFS
38 // FORWARD DECLARATIONS
39 
41 class OsCSemBase : public OsSyncBase
42 {
43 /* //////////////////////////// PUBLIC //////////////////////////////////// */
44 public:
45 
47  {
48  Q_FIFO = 0x0,
49  Q_PRIORITY = 0x1
50  };
51 
52 /* ============================ CREATORS ================================== */
53 
54 /* ============================ MANIPULATORS ============================== */
55 
57  virtual OsStatus acquire(const OsTime& rTimeout = OsTime::OS_INFINITY) = 0;
58 
60  virtual OsStatus tryAcquire(void) = 0;
65  virtual OsStatus release(void) = 0;
67 
68 
69 /* ============================ ACCESSORS ================================= */
70 
71 #ifdef OS_CSEM_DEBUG
72  virtual void show(void) ;
74 
76  virtual int getValue(void) ;
77 #endif
78 
79 /* ============================ INQUIRY =================================== */
80 
81 /* //////////////////////////// PROTECTED ///////////////////////////////// */
82 protected:
83 
84 #ifdef OS_CSEM_DEBUG
85  OsBSem mGuard;
86  int mQueueOptions;
88  int mInitialCount;
89  int mMaxCount;
90  int mCurCount;
91  int mHighCount;
92  int mLowCount;
93  int mNumAcquires;
94  int mNumReleases;
95 #endif
96 
98  OsCSemBase(const int queueOptions, const int maxCount,
99  const int initCount) ;
100 
102  virtual ~OsCSemBase() { };
103 
104 #ifdef OS_CSEM_DEBUG
105  void updateAcquireStats(void);
107 
109  void updateReleaseStats(void);
110 #endif
111 
112 /* //////////////////////////// PRIVATE /////////////////////////////////// */
113 private:
114 
115 
117  OsCSemBase(const OsCSemBase& rOsCSemBase);
118 
120  OsCSemBase& operator=(const OsCSemBase& rhs);
121 
122 };
123 
124 /* ============================ INLINE METHODS ============================ */
125 
130 #if defined(_WIN32)
131 # include "os/Wnt/OsCSemWnt.h"
132  typedef class OsCSemWnt OsCSem;
133 #elif defined(_VXWORKS)
134 # include "os/Vxw/OsCSemVxw.h"
135  typedef class OsCSemVxw OsCSem;
136 #elif defined(__pingtel_on_posix__)
137 # include "os/linux/OsCSemLinux.h"
138  typedef class OsCSemLinux OsCSem;
139 #else
140 # error Unsupported target platform.
141 #endif
142 
143 #endif // _OsCSem_h_
144 
Base class for the synchronization mechanisms in the OS abstraction layer.
Definition: OsSyncBase.h:46
QueueOptions
Definition: OsCSem.h:46
Definition: OsCSemLinux.h:32
queue blocked tasks on a first-in, first-out basis
Definition: OsCSem.h:48
OsStatus
Definition: OsStatus.h:27
virtual ~OsCSemBase()
Destructor.
Definition: OsCSem.h:102
virtual OsStatus tryAcquire(void)=0
Conditionally acquire the semaphore (i.e., don't block)
Definition: OsTime.h:45
virtual OsStatus release(void)=0
Release the semaphore.
Definition: OsCSemWnt.h:34
Counting semaphore.
Definition: OsCSem.h:41
Definition: OsTime.h:37
queue blocked tasks based on their priority
Definition: OsCSem.h:49
OsCSemBase(const int queueOptions, const int maxCount, const int initCount)
Default constructor.
Definition: OsCSemBase.cpp:40
virtual OsStatus acquire(const OsTime &rTimeout=OsTime::OS_INFINITY)=0
Block the task until the semaphore is acquired or the timeout expires.