7 #define FE_MTX_COUNT (FE_CODEGEN<FE_DEBUG) 9 #ifndef __platform_mutex_h__ 10 #define __platform_mutex_h__ 13 #include "boost/thread.hpp" 14 #define FE_YIELD boost::thread::yield 15 #define FE_SLEEP(s, ns) \ 16 struct boost::xtime boost_time; \ 17 boost_time.sec=seconds; \ 18 boost_time.nsec=nanoseconds; \ 19 boost::thread::sleep(boost_time); 23 #include "boost/thread.hpp" 24 #include "boost/thread/thread.hpp" 25 #include "boost/thread/tss.hpp" 26 #include "boost/thread/condition.hpp" 27 typedef boost::shared_mutex mutex;
28 typedef boost::recursive_mutex recursive_mutex;
29 #define FE_YIELD boost::thread::yield 30 #define FE_SLEEP(s, ns) \ 31 struct boost::xtime boost_time; \ 32 boost_time.sec=seconds; \ 33 boost_time.nsec=nanoseconds; \ 34 boost::thread::sleep(boost_time); 35 #define FE_LOCK(s, m) s.lock() 36 #define FE_UNLOCK(s) s.unlock() 37 #define FE_M_LOCK(m) m->lock() 38 #define FE_M_UNLOCK(m) m->unlock() 39 #define FE_M_TRY_LOCK(m) m->try_lock() 40 #define FE_M_LOCK_SHARED(m) m->lock_shared() 41 #define FE_M_UNLOCK_SHARED(m) m->unlock_shared() 42 #define FE_M_TRY_LOCK_SHARED(m) m->try_lock_shared() 46 #include "tbb/mutex.h" 47 #include "tbb/recursive_mutex.h" 48 #include "tbb/spin_rw_mutex.h" 49 #include "tbb/tick_count.h" 50 #include "tbb/tbb_thread.h" 51 typedef tbb::spin_rw_mutex mutex;
52 typedef tbb::recursive_mutex recursive_mutex;
53 #define FE_YIELD tbb::this_tbb_thread::yield 54 #define FE_SLEEP(s, ns) \ 55 tbb::tick_count::interval_t t(((double)s) + (((double)ns) * 1.0e-9)); \ 56 tbb::this_tbb_thread::sleep(t) 57 #define FE_LOCK(s, m) s.acquire(m) 58 #define FE_UNLOCK(s) s.release() 59 #define FE_M_LOCK(m) m->lock() 60 #define FE_M_UNLOCK(m) m->unlock() 61 #define FE_M_TRY_LOCK(m) m->try_lock() 62 #define FE_M_LOCK_SHARED(m) m->lock_read() 63 #define FE_M_UNLOCK_SHARED(m) m->unlock() 64 #define FE_M_TRY_LOCK_SHARED(m) m->try_lock_read() 83 typedef void* (FE_CDECL MutexInitFunction)(
bool a_recursive);
84 typedef bool (FE_CDECL MutexLockFunction)(
bool a_recursive,
void* a_pRawMutex,
85 bool a_un,
bool a_try,
bool a_readOnly);
86 typedef void (FE_CDECL MutexFinishFunction)(
bool a_recursive,
void* a_pRawMutex);
88 typedef void* (FE_CDECL MutexGuardInitFunction)(
89 bool a_recursive,
void* a_pRawMutex,
bool a_readOnly);
90 typedef bool (FE_CDECL MutexGuardLockFunction)(
bool a_recursive,
void* a_pRawGuard,
91 bool a_un,
bool a_try,
bool a_readOnly);
92 typedef void (FE_CDECL MutexGuardFinishFunction)(
bool a_recursive,
void* a_pRawGuard,
95 typedef void* (FE_CDECL MutexConditionInitFunction)(
void);
96 typedef bool (FE_CDECL MutexConditionWaitFunction)(
void* a_pRawCondition,
97 bool a_recursive,
void* a_pRawGuard,
bool a_readOnly);
98 typedef bool (FE_CDECL MutexConditionNotifyFunction)(
void* a_pRawCondition,
bool a_all);
99 typedef void (FE_CDECL MutexConditionFinishFunction)(
void* a_pRawCondition);
103 FE_MEM_PORT
extern MutexInitFunction* gs_fnMutexInit;
104 FE_MEM_PORT
extern MutexLockFunction* gs_fnMutexLock;
105 FE_MEM_PORT
extern MutexFinishFunction* gs_fnMutexFinish;
107 FE_MEM_PORT
extern MutexGuardInitFunction* gs_fnMutexGuardInit;
108 FE_MEM_PORT
extern MutexGuardLockFunction* gs_fnMutexGuardLock;
109 FE_MEM_PORT
extern MutexGuardFinishFunction* gs_fnMutexGuardFinish;
111 FE_MEM_PORT
extern MutexConditionInitFunction* gs_fnMutexConditionInit;
112 FE_MEM_PORT
extern MutexConditionWaitFunction* gs_fnMutexConditionWait;
113 FE_MEM_PORT
extern MutexConditionNotifyFunction* gs_fnMutexConditionNotify;
114 FE_MEM_PORT
extern MutexConditionFinishFunction* gs_fnMutexConditionFinish;
116 FE_MEM_PORT
extern String gs_mutexSupport;
117 FE_MEM_PORT
extern BWORD gs_mutexChecked;
118 FE_MEM_PORT
extern DL_Loader* gs_pMutexLoader;
120 class FE_DL_PUBLIC FE_DL_EXPORT Mutex
123 Mutex(BWORD a_recursive=FALSE);
126 static BWORD supported(
void) {
return (gs_fnMutexInit!=NULL); }
127 static String support(
void) {
return gs_mutexSupport; }
132 BWORD lockReadOnly(
void);
133 BWORD unlockReadOnly(
void);
134 BWORD tryLockReadOnly(
void);
139 friend class Mutex::Condition;
142 Guard(Mutex& a_rMutex,BWORD a_readOnly=FALSE,
162 BWORD wait(Guard& a_rGuard);
163 BWORD notifyOne(
void);
164 BWORD notifyAll(
void);
169 void* m_pRawCondition;
172 static void replaceInitFunction(MutexInitFunction* a_fnInit)
173 { gs_fnMutexInit=a_fnInit; }
174 static void replaceLockFunction(MutexLockFunction* a_fnLock)
175 { gs_fnMutexLock=a_fnLock; }
176 static void replaceFinishFunction(MutexFinishFunction* a_fnFinish)
177 { gs_fnMutexFinish=a_fnFinish; }
179 static void replaceGuardInitFunction(MutexGuardInitFunction* a_fnGuardInit)
180 { gs_fnMutexGuardInit=a_fnGuardInit; }
181 static void replaceGuardLockFunction(MutexGuardLockFunction* a_fnGuardLock)
182 { gs_fnMutexGuardLock=a_fnGuardLock; }
183 static void replaceGuardFinishFunction(
184 MutexGuardFinishFunction* a_fnGuardFinish)
185 { gs_fnMutexGuardFinish=a_fnGuardFinish; }
187 static void replaceConditionInitFunction(
188 MutexConditionInitFunction* a_fnConditionInit)
189 { gs_fnMutexConditionInit=a_fnConditionInit; }
190 static void replaceConditionWaitFunction(
191 MutexConditionWaitFunction* a_fnConditionWait)
192 { gs_fnMutexConditionWait=a_fnConditionWait; }
193 static void replaceConditionNotifyFunction(
194 MutexConditionNotifyFunction* a_fnConditionNotify)
195 { gs_fnMutexConditionNotify=a_fnConditionNotify; }
196 static void replaceConditionFinishFunction(
197 MutexConditionFinishFunction* a_fnConditionFinish)
198 { gs_fnMutexConditionFinish=a_fnConditionFinish; }
200 static BWORD confirm(String a_hint=
"");
201 static BWORD clearFunctionPointers(
void);
202 static BWORD dismiss(
void);
221 class FE_DL_PUBLIC FE_DL_EXPORT RecursiveMutex:
public Mutex
224 RecursiveMutex(
void):
kernel
Definition: namespace.dox:3