MAK Data Logger API Documentation for HLA
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
threadSafe.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 1992-2010 VT MAK
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 
11 #ifndef threadSafe_H_
12 #define threadSafe_H_
13 #include "lgrUtil.h"
14 
15 #include <vlutil/vlMutex.h>
16 #include <vlutil/vlScopedLock.h>
17 
18 namespace MAKLogger
19 {
20 
43 
45  {
46  public:
48  typedef void (*LockFunction)(void*);
49 
53 
55  virtual ~DtScopedSequenceLock();
56 
57  protected:
58 
60  DtScopedSequenceLock(void* object,LockFunction lockCB,LockFunction unlockCB);
61 
63  LockFunction myLockCallback;
64 
66  LockFunction myUnlockCallback;
67 
69  void* myObject;
70  };
71 
72 
99 
100  template <typename T>
102  {
103 #ifndef __solaris__
104  protected:
105 #else
106  public:
107 #endif
108  class LockedProxy;
109  class ConstLockedProxy;
110  friend class SequenceLockImpl;
111  public:
112 
113  DtThreadSafe(const T& value);
114 
116  operator T() const;
117 
121 
125 
128 
130  DtThreadSafe<T>& operator =(const T& orig);
131 
137 #ifndef __solaris__
138  protected:
139 #else
140  public:
141 #endif
142 
147  {
148  public:
150  LockedProxy(T& value,DtMutex& mutex);
152  LockedProxy(const LockedProxy& orig);
154  ~LockedProxy();
155 
159  T* operator->();
160 
161  protected:
163  DtMutex& myMutex;
164  DtScopedLock myLock;
165  };
166 
171  {
172  public:
174  ConstLockedProxy(const T& value,DtMutex& mutex);
176  ConstLockedProxy(const ConstLockedProxy& orig);
179 
183  const T* operator->();
184 
185  protected:
186  const T* myValue;
187  DtMutex& myMutex;
188  DtScopedLock myLock;
189  };
190 
191 
196  {
197  public:
200 
202  virtual ~SequenceLockImpl();
205  static void lock(void* object);
206 
208  static void unlock(void* object);
209  };
210 
212  void lockObject();
213 
215  void unlockObject();
216 
221  DtScopedLock* myExternalLock;
222 
224  DtMutex myLockMutex;
225 
227  mutable DtMutex myMutex;
228  };
229 
230 #define threadSafe_inl_
231 #include "threadSafe.inl"
232 #undef threadSafe_inl_
233 
234 }
235 
236 #endif
~LockedProxy()
Destructor, releases lock.
Definition: threadSafe.h:145
ConstLockedProxy(const T &value, DtMutex &mutex)
Constructor.
Definition: threadSafe.h:161
A scoped sequence lock.
Definition: threadSafe.h:44
DtScopedLock * myExternalLock
The external lock which allows the sequence lock.
Definition: threadSafe.h:221
LockedProxy(T &value, DtMutex &mutex)
Constructor.
Definition: threadSafe.h:127
const T * myValue
Definition: threadSafe.h:186
LockedProxy operator->()
Proxy pointer access operator.
Definition: threadSafe.h:52
DtScopedSequenceLock sequenceLock()
Request a sequence lock, this object will maintain a lock on the object during it&#39;s life-time...
Definition: threadSafe.h:92
#define DT_DLL_LGRUTIL
Definition: lgrUtil.h:19
LockFunction myLockCallback
The acquire lock callback.
Definition: threadSafe.h:63
DtThreadSafe(const T &value)
! DtThreadSafe Implementation
Definition: threadSafe.h:29
static void unlock(void *object)
Callback function which takes object (down-casts) and unlocks.
Definition: threadSafe.h:215
DtThreadSafe< T > & operator=(const DtThreadSafe< T > &orig)
Locked Copy operator,.
Definition: threadSafe.h:66
Private class that provides a locked call to the const object.
Definition: threadSafe.h:170
void * myObject
The object to pass to the callbacks.
Definition: threadSafe.h:69
DtMutex & myMutex
Definition: threadSafe.h:163
DtMutex & myMutex
Definition: threadSafe.h:187
static void lock(void *object)
Callback function which takes object (down-casts) and locks.
Definition: threadSafe.h:209
SequenceLockImpl(DtThreadSafe *object)
Constructor that takes the object to lock.
Definition: threadSafe.h:197
T * operator->()
Pointer redirect operator.
Definition: threadSafe.h:151
~ConstLockedProxy()
Destructor, releases lock.
Definition: threadSafe.h:181
DtScopedLock myLock
Definition: threadSafe.h:188
const T * operator->()
Pointer redirect operator.
Definition: threadSafe.h:187
Private class that provides a locked call to the object.
Definition: threadSafe.h:146
DtScopedLock myLock
Definition: threadSafe.h:164
Contains IMPORT/EXPORT macros for lgrUtil library.
a thread safe interface to a value.
Definition: threadSafe.h:101
void lockObject()
Lock the external object.
Definition: threadSafe.h:101
virtual ~SequenceLockImpl()
Destructor, does nothing.
Definition: threadSafe.h:203
Private class which implements the Sequence lock.
Definition: threadSafe.h:195
friend class SequenceLockImpl
Definition: threadSafe.h:109
void unlockObject()
Unlock the external object.
Definition: threadSafe.h:111
DtMutex myMutex
The mutex which is used to make the object threadsafe.
Definition: threadSafe.h:227
T myValue
Value which is to be thread safe.
Definition: threadSafe.h:218
DtMutex myLockMutex
The mutex which is used to lock when created the external lock.
Definition: threadSafe.h:224
ConstLockedProxy(const ConstLockedProxy &orig)
Copy Constructor, should not be necessary for optimized code.
Definition: threadSafe.h:171
T * myValue
Definition: threadSafe.h:162

Document ID: Generated on Thu Sep 2 15:35:22 EDT 2021 from SVN revision 233992
Copyright © 2021 MAK Technologies. All Rights Reserved (www.mak.com)