20 #include "SimulatedBlock.hpp"
22 #include <signaldata/UtilLock.hpp>
26 m_activeMutexes(m_mutexPool) {
30 SimulatedBlock::MutexManager::setSize(Uint32 maxNoOfActiveMutexes){
31 return m_mutexPool.
setSize(maxNoOfActiveMutexes);
35 SimulatedBlock::MutexManager::getSize()
const {
36 return m_mutexPool.getSize();
40 SimulatedBlock::MutexManager::seize(ActiveMutexPtr& ptr){
41 return m_activeMutexes.seize(ptr);
45 SimulatedBlock::MutexManager::release(Uint32 activeMutexPtrI){
46 m_activeMutexes.release(activeMutexPtrI);
50 SimulatedBlock::MutexManager::getPtr(ActiveMutexPtr& ptr){
51 m_activeMutexes.getPtr(ptr);
55 SimulatedBlock::MutexManager::reference()
const {
56 return m_block.reference();
64 m_block.progError(line, err_code, extra);
68 SimulatedBlock::MutexManager::create(
Signal* signal, ActiveMutexPtr& ptr){
71 req->senderData = ptr.i;
72 req->senderRef = m_block.reference();
73 req->lockId = ptr.p->m_mutexId;
74 req->lockType = UtilCreateLockReq::Mutex;
76 m_block.sendSignal(DBUTIL_REF,
77 GSN_UTIL_CREATE_LOCK_REQ,
79 UtilCreateLockReq::SignalLength,
82 ptr.p->m_gsn = GSN_UTIL_CREATE_LOCK_REQ;
86 SimulatedBlock::MutexManager::execUTIL_CREATE_LOCK_REF(
Signal* signal){
90 m_activeMutexes.getPtr(ptr, ref->senderData);
91 ndbrequire(ptr.p->m_gsn == GSN_UTIL_CREATE_LOCK_REQ);
92 ndbrequire(ptr.p->m_mutexId == ref->lockId);
95 m_block.execute(signal, ptr.p->m_callback, ref->errorCode);
99 SimulatedBlock::MutexManager::execUTIL_CREATE_LOCK_CONF(
Signal* signal){
103 m_activeMutexes.getPtr(ptr, conf->senderData);
104 ndbrequire(ptr.p->m_gsn == GSN_UTIL_CREATE_LOCK_REQ);
105 ndbrequire(ptr.p->m_mutexId == conf->lockId);
108 m_block.execute(signal, ptr.p->m_callback, 0);
113 SimulatedBlock::MutexManager::destroy(
Signal* signal, ActiveMutexPtr& ptr){
116 req->senderData = ptr.i;
117 req->senderRef = m_block.reference();
118 req->lockId = ptr.p->m_mutexId;
120 m_block.sendSignal(DBUTIL_REF,
121 GSN_UTIL_DESTROY_LOCK_REQ,
123 UtilDestroyLockReq::SignalLength,
126 ptr.p->m_gsn = GSN_UTIL_DESTROY_LOCK_REQ;
130 SimulatedBlock::MutexManager::execUTIL_DESTORY_LOCK_REF(
Signal* signal){
133 m_activeMutexes.getPtr(ptr, ref->senderData);
134 ndbrequire(ptr.p->m_gsn == GSN_UTIL_DESTROY_LOCK_REQ);
135 ndbrequire(ptr.p->m_mutexId == ref->lockId);
138 m_block.execute(signal, ptr.p->m_callback, ref->errorCode);
142 SimulatedBlock::MutexManager::execUTIL_DESTORY_LOCK_CONF(
Signal* signal){
145 m_activeMutexes.getPtr(ptr, conf->senderData);
146 ndbrequire(ptr.p->m_gsn == GSN_UTIL_DESTROY_LOCK_REQ);
147 ndbrequire(ptr.p->m_mutexId == conf->lockId);
150 m_block.execute(signal, ptr.p->m_callback, 0);
155 SimulatedBlock::MutexManager::lock(
Signal* signal,
160 req->senderData = ptr.i;
161 req->senderRef = m_block.reference();
162 req->lockId = ptr.p->m_mutexId;
163 req->requestInfo =
flags;
164 req->extra = ptr.p->m_callback.m_callbackData;
166 m_block.sendSignal(DBUTIL_REF,
169 UtilLockReq::SignalLength,
172 ptr.p->m_gsn = GSN_UTIL_LOCK_REQ;
176 SimulatedBlock::MutexManager::execUTIL_LOCK_REF(
Signal* signal){
179 m_activeMutexes.getPtr(ptr, ref->senderData);
180 ndbrequire(ptr.p->m_gsn == GSN_UTIL_LOCK_REQ);
181 ndbrequire(ptr.p->m_mutexId == ref->lockId);
183 bool notify = ref->errorCode == UtilLockRef::InLockQueue;
184 CallbackFunction fun = ptr.p->m_callback.m_callbackFunction;
190 m_block.execute(signal, ptr.p->m_callback, ref->errorCode);
195 ptr.p->m_callback.m_callbackFunction = fun;
200 SimulatedBlock::MutexManager::execUTIL_LOCK_CONF(
Signal* signal){
203 m_activeMutexes.getPtr(ptr, conf->senderData);
204 ndbrequire(ptr.p->m_gsn == GSN_UTIL_LOCK_REQ);
205 ndbrequire(ptr.p->m_mutexId == conf->lockId);
208 m_block.execute(signal, ptr.p->m_callback, 0);
212 SimulatedBlock::MutexManager::unlock(
Signal* signal, ActiveMutexPtr& ptr){
214 req->senderData = ptr.i;
215 req->senderRef = m_block.reference();
216 req->lockId = ptr.p->m_mutexId;
218 m_block.sendSignal(DBUTIL_REF,
221 UtilUnlockReq::SignalLength,
224 ptr.p->m_gsn = GSN_UTIL_UNLOCK_REQ;
228 SimulatedBlock::MutexManager::execUTIL_UNLOCK_REF(
Signal* signal){
231 m_activeMutexes.getPtr(ptr, ref->senderData);
232 ndbrequire(ptr.p->m_gsn == GSN_UTIL_UNLOCK_REQ);
233 ndbrequire(ptr.p->m_mutexId == ref->lockId);
236 m_block.execute(signal, ptr.p->m_callback, ref->errorCode);
240 SimulatedBlock::MutexManager::execUTIL_UNLOCK_CONF(
Signal* signal){
243 m_activeMutexes.getPtr(ptr, conf->senderData);
244 ndbrequire(ptr.p->m_gsn == GSN_UTIL_UNLOCK_REQ);
245 ndbrequire(ptr.p->m_mutexId == conf->lockId);
248 m_block.execute(signal, ptr.p->m_callback, 0);
253 Uint32 activePtrI, Uint32 mutexId){
257 if(ptr.p->m_gsn == 0 && ptr.p->m_mutexId == mutexId){
258 mgr.release(activePtrI);
262 if(ptr.p->m_mutexId != mutexId)
263 ErrorReporter::handleAssert(
"MutexHandle::release invalid handle",
265 ErrorReporter::handleAssert(
"MutexHandle::release of mutex inuse",
273 if(m_ptr.p->m_mutexId == m_mutexId){
275 { &SimulatedBlock::ignoreMutexUnlockCallback, m_ptr.i };
276 m_ptr.p->m_callback = c;
277 m_mgr.unlock(m_signal, m_ptr);