VR-Link API Documentation for HLA 1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vlThreadSafe.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 1992-2010 VT MAK
3 ** All rights reserved.
4 ******************************************************************************/
9 #pragma once
10 
11 #include "vlMachineTypes.h"
12 
13 #include "vlMutex.h"
14 #include "vlScopedLock.h"
15 
16 #ifdef DtUSE_UTILITIES_NAMESPACE
17 namespace DtUSE_UTILITIES_NAMESPACE
18 {
19 #endif
20 
21 
22 
46 
48 {
49 public:
51  typedef void (*LockFunction)(void*);
52 
56 
58  virtual ~DtScopedSequenceLock();
59 
60 protected:
61 
63  DtScopedSequenceLock(void* object,LockFunction lockCB,LockFunction unlockCB);
64 
66  LockFunction myLockCallback;
67 
69  LockFunction myUnlockCallback;
70 
72  void* myObject;
73 };
74 
75 
102 
103 template <typename T>
105 {
106 #ifndef __solaris__
107 protected:
108 #else
109 public:
110 #endif
111  class LockedProxy;
112  class ConstLockedProxy;
113  friend class SequenceLockImpl;
114 public:
115 
116  // Preferred Constructor to ensure that the value is defined.
117  explicit DtThreadSafe(const T& value);
118 
119  // Fallback Constructor, there is a good chance that T does not have a valid default value on
120  // some systems (ie do not assume zero).
121  explicit DtThreadSafe();
122 
124  operator T() const;
125 
128  LockedProxy operator->();
129 
132  ConstLockedProxy operator->() const;
133 
135  DtThreadSafe<T>& operator =(const DtThreadSafe<T>& orig);
136 
138  DtThreadSafe<T>& operator =(const T& orig);
139 
143  DtScopedSequenceLock sequenceLock();
144 
145 #ifndef __solaris__
146 protected:
147 #else
148 public:
149 #endif
150 
154  {
155  public:
157  LockedProxy(T& value,DtMutex& mutex);
159  LockedProxy(const LockedProxy& orig);
161  ~LockedProxy();
162 
166  T* operator->();
167 
168  protected:
172  };
173 
177  {
178  public:
180  ConstLockedProxy(const T& value,DtMutex& mutex);
182  ConstLockedProxy(const ConstLockedProxy& orig);
184  ~ConstLockedProxy();
185 
189  const T* operator->();
190 
191  protected:
192  const T* myValue;
195  };
196 
197 
201  {
202  public:
205 
207  virtual ~SequenceLockImpl();
208 
210  static void lock(void* object);
211 
213  static void unlock(void* object);
214  };
215 
217  void lockObject();
218 
220  void unlockObject();
221 
227 
230 
232  mutable DtMutex myMutex;
233 };
234 
235 #define vlThreadSafe_inl_
236 #include "vlThreadSafe.inl"
237 #undef vlThreadSafe_inl_
238 
239 #ifdef DtUSE_UTILITIES_NAMESPACE
240 }
241 #endif
242 

Document ID: Generated on Mon Jun 22 21:18:40 EDT 2020 from SVN revision 213785
Copyright © 2005-2018 MAK Technologies. All Rights Reserved (www.mak.com)