7 #ifndef __core_SafeShared_h__ 8 #define __core_SafeShared_h__ 18 virtual ~SafeSharedCore(
void) {}
20 virtual void safeLock(
void)
const =0;
21 virtual void safeUnlock(
void)
const =0;
22 virtual bool safeTryLock(
void)
const =0;
24 virtual void safeLockShared(
void)
const =0;
25 virtual void safeUnlockShared(
void)
const =0;
26 virtual bool safeTryLockShared(
void)
const =0;
30 class SafeSharedBase:
public SafeSharedCore
33 virtual ~SafeSharedBase(
void) {}
35 virtual Mutex *fe_thread_mutex(
void)
const =0;
38 class ClassSafeSharedBase:
public SafeSharedCore
41 virtual ~ClassSafeSharedBase(
void) {}
43 virtual Mutex *fe_class_thread_mutex(
void)
const =0;
47 class FE_DL_EXPORT trueClassSafeShared:
public ClassSafeSharedBase
51 virtual void safeLock(
void)
const 52 { fe_class_thread_mutex()->lock(); }
53 virtual void safeUnlock(
void)
const 54 { fe_class_thread_mutex()->unlock(); }
55 virtual bool safeTryLock(
void)
const 56 {
return fe_class_thread_mutex()->tryLock(); }
58 virtual void safeLockShared(
void)
const 59 { fe_class_thread_mutex()->lockReadOnly(); }
60 virtual void safeUnlockShared(
void)
const 61 { fe_class_thread_mutex()->unlockReadOnly(); }
62 virtual bool safeTryLockShared(
void)
const 63 {
return fe_class_thread_mutex()->tryLockReadOnly(); }
65 #if FE_SAFE_COUNTED_MUTEX 67 trueClassSafeShared(
void)
74 if(!feAsmSwapIncr(&ms_mutexCount,1) && !ms_pMutex)
77 Memory::markForDeath(ms_pMutex,&ms_mutexCount);
82 virtual ~trueClassSafeShared(
void)
91 if(!(feAsmSwapIncr(&ms_mutexCount,-1)-1))
99 virtual Mutex* fe_class_thread_mutex(
void)
const 108 static FE_DL_PUBLIC I32 ms_mutexCount;
109 static FE_DL_PUBLIC Mutex* ms_pMutex;
113 virtual Mutex* fe_class_thread_mutex(
void)
const 120 static FE_DL_PUBLIC Mutex ms_mutex;
125 template <
typename T>
126 class FE_DL_EXPORT trueObjectSafeShared :
public SafeSharedBase
130 trueObjectSafeShared(
void)
136 virtual ~trueObjectSafeShared(
void) {}
138 virtual Mutex *fe_thread_mutex(
void)
const 143 return const_cast<Mutex*
>(&m_fe_mutex);
146 virtual void safeLock(
void)
const 147 { fe_thread_mutex()->lock(); }
148 virtual void safeUnlock(
void)
const 149 { fe_thread_mutex()->unlock(); }
150 virtual bool safeTryLock(
void)
const 151 {
return fe_thread_mutex()->tryLock(); }
153 virtual void safeLockShared(
void)
const 154 { fe_thread_mutex()->lockReadOnly(); }
155 virtual void safeUnlockShared(
void)
const 156 { fe_thread_mutex()->unlockReadOnly(); }
157 virtual bool safeTryLockShared(
void)
const 158 {
return fe_thread_mutex()->tryLockReadOnly(); }
164 template <
typename T>
165 class FE_DL_EXPORT trueClassNotSafeShared :
public ClassSafeSharedBase
168 trueClassNotSafeShared(
void) {}
169 virtual ~trueClassNotSafeShared(
void) {}
171 virtual Mutex* fe_class_thread_mutex(
void)
const {
return NULL; }
173 virtual void safeLock(
void)
const {}
174 virtual void safeUnlock(
void)
const {}
175 virtual bool safeTryLock(
void)
const {
return false; }
177 virtual void safeLockShared(
void)
const {}
178 virtual void safeUnlockShared(
void)
const {}
179 virtual bool safeTryLockShared(
void)
const {
return false; }
183 template <
typename T>
184 class FE_DL_EXPORT trueNotSafeShared :
public SafeSharedBase
187 trueNotSafeShared(
void) {}
188 virtual ~trueNotSafeShared(
void) {}
190 virtual Mutex* fe_thread_mutex(
void)
const {
return NULL; }
192 virtual void safeLock(
void)
const {}
193 virtual void safeUnlock(
void)
const {}
194 virtual bool safeTryLock(
void)
const {
return false; }
196 virtual void safeLockShared(
void)
const {}
197 virtual void safeUnlockShared(
void)
const {}
198 virtual bool safeTryLockShared(
void)
const {
return false; }
202 #if FE_SAFE_COUNTED_MUTEX 204 FE_DL_PUBLIC Mutex* trueClassSafeShared<T>::ms_pMutex=NULL;
206 FE_DL_PUBLIC I32 trueClassSafeShared<T>::ms_mutexCount=0;
209 FE_DL_PUBLIC Mutex trueClassSafeShared<T>::ms_mutex;
212 #ifndef FE_DISABLE_THREAD_SAFE 217 public trueClassSafeShared<T> {};
221 public trueObjectSafeShared<T> {};
225 public trueNotSafeShared<T> {};
229 class FE_DL_EXPORT ClassSafeShared:
230 public trueNotClassSafeShared<T> {};
233 class FE_DL_EXPORT ObjectSafeShared:
234 public trueNotSafeShared<T> {};
237 class FE_DL_EXPORT NotSafeShared:
238 public trueNotSafeShared<T> {};
No locking for thread safety.
Definition: SafeShared.h:224
Class level locking for thread safety.
Definition: SafeShared.h:216
kernel
Definition: namespace.dox:3
Object level locking for thread safety.
Definition: SafeShared.h:220