19 #ifndef BLOCK_MUTEX_HPP
20 #define BLOCK_MUTEX_HPP
22 #include "Callback.hpp"
23 #include "SimulatedBlock.hpp"
24 #include <signaldata/UtilLock.hpp>
41 const Uint32 m_mutexId;
42 Uint32 m_activeMutexPtrI;
48 template<U
int32 MutexId>
57 Uint32 getHandle()
const;
58 void setHandle(Uint32 handle);
62 Uint32 m_activeMutexPtrI;
72 template<U
int32 MutexId>
91 const Uint32 m_mutexId;
97 Uint32 activePtrI, Uint32 mutexId);
101 MutexHandle::MutexHandle(Uint32
id) : m_mutexId(id) {
102 m_activeMutexPtrI = RNIL;
107 MutexHandle::isNull()
const {
108 return m_activeMutexPtrI == RNIL;
115 Mutex::release(mgr, m_activeMutexPtrI, m_mutexId);
116 m_activeMutexPtrI = RNIL;
120 template<U
int32 MutexId>
123 m_activeMutexPtrI = RNIL;
126 template<U
int32 MutexId>
130 return m_activeMutexPtrI == RNIL;
134 template<U
int32 MutexId>
139 Mutex::release(mgr, m_activeMutexPtrI, MutexId);
140 m_activeMutexPtrI = RNIL;
144 template<U
int32 MutexId>
149 return m_activeMutexPtrI;
152 template<U
int32 MutexId>
157 m_activeMutexPtrI = RNIL;
160 template<U
int32 MutexId>
165 if (m_activeMutexPtrI == RNIL)
167 m_activeMutexPtrI = val;
170 ErrorReporter::handleAssert(
"Mutex::setHandle mutex alreay inuse",
179 m_mutexId(mh.m_mutexId),
180 m_srcPtrI(mh.m_activeMutexPtrI){
186 template<U
int32 MutexId>
193 m_srcPtrI(mh.m_activeMutexPtrI){
208 Mutex::release(m_mgr, m_ptr.i, m_mutexId);
215 Mutex::isNull()
const {
216 return m_ptr.isNull();
223 if(m_mgr.seize(m_ptr)){
224 m_ptr.p->m_mutexId = m_mutexId;
225 m_ptr.p->m_callback = callback;
226 m_mgr.lock(m_signal, m_ptr,
227 ((exclusive ==
false) ? UtilLockReq::SharedLock : 0) |
228 ((notify ==
true) ? UtilLockReq::Notify : 0));
233 ErrorReporter::handleAssert(
"Mutex::lock mutex alreay inuse",
242 if(m_mgr.seize(m_ptr)){
243 m_ptr.p->m_mutexId = m_mutexId;
244 m_ptr.p->m_callback = callback;
245 m_mgr.lock(m_signal, m_ptr,
246 UtilLockReq::TryLock |
247 ((exclusive ==
false) ? UtilLockReq::SharedLock : 0));
252 ErrorReporter::handleAssert(
"Mutex::trylock mutex alreay inuse",
262 if(m_ptr.p->m_mutexId == m_mutexId){
263 m_ptr.p->m_callback = callback;
264 m_mgr.unlock(m_signal, m_ptr);
268 ErrorReporter::handleAssert(
"Mutex::unlock invalid mutex",
276 if(m_mgr.seize(m_ptr)){
277 m_ptr.p->m_mutexId = m_mutexId;
278 m_ptr.p->m_callback = callback;
279 m_mgr.create(m_signal, m_ptr);
284 ErrorReporter::handleAssert(
"Mutex::create mutex alreay inuse",
293 if(m_mgr.seize(m_ptr)){
294 m_ptr.p->m_mutexId = m_mutexId;
295 m_ptr.p->m_callback = callback;
296 m_mgr.destroy(m_signal, m_ptr);
301 ErrorReporter::handleAssert(
"Mutex::destroy mutex alreay inuse",