int pmdEDUMgr::activateEDU ( EDUID eduID ) { int rc = EDB_OK ; unsigned int eduStatus = PMD_EDU_CREATING ; pmdEDUCB* eduCB = NULL; std::map<EDUID, pmdEDUCB*>::iterator it ; /************** CRITICAL SECTION ***********/ // we should lock the entire function in order to avoid // eduCB is deleted after we getting (*it).second _mutex.get() ; if ( _idleQueue.end () == ( it = _idleQueue.find ( eduID )) ) { if ( _runQueue.end () == ( it = _runQueue.find ( eduID )) ) { // we can't find EDU in idle list nor runqueue rc = EDB_SYS ; goto error ; } eduCB = ( *it ).second ; // in runqueue we may have creating/waiting status eduStatus = eduCB->getStatus () ; if ( PMD_IS_EDU_RUNNING ( eduStatus ) ) goto done ; if ( !PMD_IS_EDU_WAITING ( eduStatus ) && !PMD_IS_EDU_CREATING ( eduStatus ) ) { rc = EDB_EDU_INVAL_STATUS ; goto error ; } eduCB->setStatus ( PMD_EDU_RUNNING ) ; goto done ; } eduCB = ( *it ).second ; eduStatus = eduCB->getStatus () ; if ( PMD_IS_EDU_RUNNING ( eduStatus ) ) goto done ; // in idleQueue if ( !PMD_IS_EDU_IDLE ( eduStatus ) ) { rc = EDB_EDU_INVAL_STATUS ; goto error ; } // now the EDU status is idle, let's bring it to RUNNING _idleQueue.erase ( eduID ) ; eduCB->setStatus ( PMD_EDU_RUNNING ) ; _runQueue [ eduID ] = eduCB ; done : _mutex.release () ; return rc ; error : goto done ; }
int pmdEDUMgr::waitEDU(EDUID eduID) { int rc = EDB_OK; pmdEDUCB* eduCB = NULL; unsigned int eduStatus = PMD_EDU_CREATING; std::map<EDUID, pmdEDUCB*>::iterator it; _mutex.get_shared(); if (_runQueue.end() == (it = _runQueue.find(eduID))) { rc = EDB_SYS; goto error; } eduCB = (*it).second; eduStatus = eduCB->getStatus(); if (PMD_IS_EDU_WAITING(eduStatus)) { goto done; } if (!PMD_IS_EDU_RUNNING(eduStatus)) { rc = EDB_EDU_INVAL_STATUS; goto error; } eduCB->setStatus(PMD_EDU_WAITING); done: _mutex.release_shared(); return rc; error: goto done; }
int pmdEDUMgr::activateEDU(EDUID eduID) { int rc = EDB_OK; unsigned int eduStatus = PMD_EDU_CREATING; pmdEDUCB* eduCB = NULL; std::map<EDUID, pmdEDUCB*>::iterator it; _mutex.get(); if (_idleQueue.end() == (it = _idleQueue.find(eduID))) { if (_runQueue.end() == (it = _runQueue.find(eduID))) { rc = EDB_SYS; goto error; } eduCB = (*it).second; eduStatus = eduCB->getStatus(); if (PMD_IS_EDU_RUNNING(eduStatus)) { goto done; } if (!PMD_IS_EDU_WAITING(eduStatus) && !PMD_IS_EDU_CREATING(eduStatus)) { rc = EDB_EDU_INVAL_STATUS; goto error; } eduCB->setStatus(PMD_EDU_RUNNING); goto done; } eduCB = (*it).second; eduStatus = eduCB->getStatus(); if (PMD_IS_EDU_RUNNING(eduStatus)) { goto done; } if (!PMD_IS_EDU_IDLE(eduStatus)) { rc = EDB_EDU_INVAL_STATUS; goto error; } _idleQueue.erase(eduID); eduCB->setStatus(PMD_EDU_RUNNING); _runQueue[eduID] = eduCB; done: _mutex.release(); return rc; error: goto done; }
// change edu status from running to waiting int pmdEDUMgr::waitEDU ( EDUID eduID ) { int rc = EDB_OK ; pmdEDUCB* eduCB = NULL ; unsigned int eduStatus = PMD_EDU_CREATING ; std::map<EDUID, pmdEDUCB*>::iterator it ; /************** CRITICAL SECTION ***********/ // we should lock the entire function in order to avoid // eduCB is deleted after we getting (*it).second _mutex.get_shared () ; if ( _runQueue.end () == ( it = _runQueue.find ( eduID )) ) { // we can't find EDU in run queue rc = EDB_SYS ; goto error ; } eduCB = ( *it ).second ; eduStatus = eduCB->getStatus () ; // if it's already waiting, let's do nothing if ( PMD_IS_EDU_WAITING ( eduStatus ) ) goto done ; if ( !PMD_IS_EDU_RUNNING ( eduStatus ) ) { // if it's not running status rc = EDB_EDU_INVAL_STATUS ; goto error ; } eduCB->setStatus ( PMD_EDU_WAITING ) ; done : _mutex.release_shared () ; /************* END CRITICAL SECTION **************/ return rc ; error : goto done ; }