sipxportlib  Version 3.3
OsSyncBase.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 
15 #ifndef _OsSyncBase_h_
16 #define _OsSyncBase_h_
17 
18 // SYSTEM INCLUDES
19 
20 // APPLICATION INCLUDES
21 #include "os/OsDefs.h"
22 #include "os/OsStatus.h"
23 #include "os/OsTime.h"
24 
25 // DEFINES
26 // If OS_SYNC_DEBUG, enable debugging information for binary semaphores and
27 // mutexes.
28 // #define OS_SYNC_DEBUG
29 
30 #ifdef OS_SYNC_DEBUG
31 # include "os/OsDateTime.h"
32 #endif
33 
34 // MACROS
35 // EXTERNAL FUNCTIONS
36 // EXTERNAL VARIABLES
37 // CONSTANTS
38 // STRUCTS
39 // TYPEDEFS
40 
41 // FORWARD DECLARATIONS
42 
47 {
48 /* //////////////////////////// PUBLIC //////////////////////////////////// */
49 public:
50 
52  virtual
53  ~OsSyncBase() { };
54 
55 /* ============================ CREATORS ================================== */
56 
57 /* ============================ MANIPULATORS ============================== */
58 
60  OsSyncBase& operator=(const OsSyncBase& rhs);
61 
63  virtual OsStatus acquire(const OsTime& rTimeout = OsTime::OS_INFINITY) = 0;
64 
66  virtual OsStatus tryAcquire(void) = 0;
71  virtual OsStatus release(void) = 0;
73 
74 /* ============================ ACCESSORS ================================= */
75 
76 /* ============================ INQUIRY =================================== */
77 
78 /* //////////////////////////// PROTECTED ///////////////////////////////// */
79 protected:
80 
81 #ifdef OS_SYNC_DEBUG
82  typedef enum
84  {
85  crumbUnused,
86  crumbCreated,
87  crumbAcquired,
88  crumbReleased,
89  crumbDeleted
90  } OsSyncOperation;
91 #endif
92 
93 # ifdef OS_SYNC_DEBUG
94 
96  class OsSyncCrumbs
97  {
98 # define NUMBER_OF_CRUMBS 6
99 
100  public:
101 
103  OsSyncCrumbs() :
104  mCrumb(0)
105  {
106  mTrail[mCrumb].operation = crumbCreated;
107  mTrail[mCrumb].taskId = 0; // default; parent constructor should call dropCrumb
108  for ( unsigned int crumb=1; crumb < NUMBER_OF_CRUMBS; crumb++ )
109  {
110  mTrail[crumb].operation = crumbUnused;
111  mTrail[crumb].taskId = 0;
112  }
113  }
114 
116  void dropCrumb(int id, OsSyncOperation op)
117  {
118  mCrumb = (mCrumb + 1) % NUMBER_OF_CRUMBS;
119  mTrail[mCrumb].operation = op;
120  mTrail[mCrumb].taskId = id;
121  OsDateTime::getCurTime(mTrail[mCrumb].time);
122  }
123 
124  ~OsSyncCrumbs()
125  {
126  // better if the destructor in the object calls, but make sure there is something.
127  dropCrumb(0, crumbDeleted);
128  }
129 
130  private:
131 
132  unsigned int mCrumb;
133  struct
134  {
135  OsSyncOperation operation;
136  unsigned int taskId;
137  OsTime time;
138  } mTrail[NUMBER_OF_CRUMBS];
139  } mSyncCrumbs;
140 
141 # endif
142 
144  OsSyncBase() { };
145 
146 /* //////////////////////////// PRIVATE /////////////////////////////////// */
147 private:
148 
150  OsSyncBase(const OsSyncBase& rOsSyncBase);
151 
152 };
153 
154 /* ============================ INLINE METHODS ============================ */
155 
156 #endif // _OsSyncBase_h_
157 
Base class for the synchronization mechanisms in the OS abstraction layer.
Definition: OsSyncBase.h:46
virtual ~OsSyncBase()
Destructor.
Definition: OsSyncBase.h:53
OsSyncBase & operator=(const OsSyncBase &rhs)
Assignment operator.
time_t __cdecl time(time_t *ptt)
OsStatus
Definition: OsStatus.h:27
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.
Definition: OsTime.h:45
OsSyncBase()
Default constructor.
Definition: OsSyncBase.h:144
Definition: OsTime.h:37
virtual OsStatus tryAcquire(void)=0
Conditionally acquire the semaphore (i.e., don&#39;t block)