7 #ifndef __core_Safe_h__ 8 #define __core_Safe_h__ 12 #define SAFEGUARD FEASSERT(fe_thread_mutex()); \ 13 SafeGuard __fe_thread_safeguard( \ 15 #define SAFEGUARD_IF(X) FEASSERT(fe_thread_mutex()); \ 16 SafeGuard __fe_thread_safeguard( \ 18 #define SAFEUNLOCK __fe_thread_safeguard.unlock(); 19 #define SAFELOCK __fe_thread_safeguard.lock(); 21 #define SAFEGUARDCLASS FEASSERT(fe_class_thread_mutex()); \ 22 SafeGuard __fe_class_thread_safeguard( \ 23 fe_class_thread_mutex()); 24 #define SAFEGUARDCLASS_IF(X) FEASSERT(fe_class_thread_mutex()); \ 25 SafeGuard __fe_class_thread_safeguard( \ 26 fe_class_thread_mutex(),X); 27 #define SAFEUNLOCKCLASS __fe_class_thread_safeguard.unlock(); 28 #define SAFELOCKCLASS __fe_class_thread_safeguard.lock(); 36 virtual ~SafeBase(
void) {}
38 virtual RecursiveMutex* fe_thread_mutex(
void)
const =0;
44 virtual ~ClassSafeBase(
void) {}
46 virtual RecursiveMutex* fe_class_thread_mutex(
void)
const =0;
50 class FE_DL_EXPORT trueClassSafe :
public ClassSafeBase
53 class FE_DL_PUBLIC SafeGuard
56 SafeGuard(RecursiveMutex *mutex,BWORD a_truly=TRUE):
57 m_guard(*mutex,FALSE,a_truly) {}
58 void lock(
void) { m_guard.lock(); }
59 void unlock(
void) { m_guard.unlock(); }
61 RecursiveMutex::Guard&
62 guard(
void) {
return m_guard; }
65 RecursiveMutex::Guard m_guard;
68 #if FE_SAFE_COUNTED_MUTEX 76 if(!feAsmSwapIncr(&ms_mutexCount,1) && !ms_pMutex)
78 ms_pMutex=
new RecursiveMutex;
79 Memory::markForDeath(ms_pMutex,&ms_mutexCount);
84 virtual ~trueClassSafe(
void)
93 if(!(feAsmSwapIncr(&ms_mutexCount,-1)-1))
101 virtual RecursiveMutex* fe_class_thread_mutex(
void)
const 111 static FE_DL_PUBLIC I32 ms_mutexCount;
112 static FE_DL_PUBLIC RecursiveMutex* ms_pMutex;
114 virtual RecursiveMutex* fe_class_thread_mutex(
void)
const 120 static FE_DL_PUBLIC RecursiveMutex ms_mutex;
124 template <
typename T>
125 class FE_DL_EXPORT trueObjectSafe :
public SafeBase
128 class FE_DL_PUBLIC SafeGuard
131 SafeGuard(RecursiveMutex *mutex,BWORD a_truly=TRUE):
132 m_guard(*mutex,FALSE,a_truly) {}
133 void lock(
void) { m_guard.lock(); }
134 void unlock(
void) { m_guard.unlock(); }
136 RecursiveMutex::Guard& guard(
void)
139 RecursiveMutex::Guard m_guard;
145 SafeGuard guard(&m_fe_mutex);
147 virtual ~trueObjectSafe(
void) {}
149 virtual RecursiveMutex *fe_thread_mutex(
void)
const 154 return const_cast<RecursiveMutex*
>(&m_fe_mutex);
158 RecursiveMutex m_fe_mutex;
161 template <
typename T>
162 class FE_DL_EXPORT trueNotSafe :
public SafeBase
165 class FE_DL_PUBLIC SafeGuard
168 SafeGuard(RecursiveMutex *mutex,BWORD a_truly=TRUE) {}
174 virtual ~trueNotSafe(
void) {}
176 virtual RecursiveMutex* fe_thread_mutex(
void)
const {
return NULL; }
179 template <
typename T>
180 class FE_DL_EXPORT trueNotClassSafe :
public ClassSafeBase
183 class FE_DL_PUBLIC SafeGuard
186 SafeGuard(RecursiveMutex *mutex,BWORD a_truly=TRUE) {}
191 trueNotClassSafe(
void) {}
192 virtual ~trueNotClassSafe(
void) {}
194 virtual RecursiveMutex* fe_class_thread_mutex(
void)
const {
return NULL; }
197 #if FE_SAFE_COUNTED_MUTEX 199 FE_DL_PUBLIC RecursiveMutex* trueClassSafe<T>::ms_pMutex=NULL;
201 FE_DL_PUBLIC I32 trueClassSafe<T>::ms_mutexCount=0;
204 FE_DL_PUBLIC RecursiveMutex trueClassSafe<T>::ms_mutex;
207 class FE_DL_EXPORT GlobalHolder:
208 public trueClassSafe<GlobalHolder> {};
210 #ifndef FE_DISABLE_THREAD_SAFE 214 public trueClassSafe<T> {};
217 public trueObjectSafe<T> {};
219 template<
typename T>
class FE_DL_EXPORT
NotSafe:
220 public trueNotSafe<T> {};
223 template<
typename T>
class FE_DL_EXPORT ClassSafe:
224 public trueNotClassSafe<T> {};
226 template<
typename T>
class FE_DL_EXPORT ObjectSafe:
227 public trueNotSafe<T> {};
229 template<
typename T>
class FE_DL_EXPORT NotSafe:
230 public trueNotSafe<T> {};
Object level locking for thread safety.
Definition: Safe.h:216
Class level locking for thread safety.
Definition: Safe.h:213
No locking for thread safety.
Definition: Safe.h:219
kernel
Definition: namespace.dox:3