void LoadModelThread::worker() { RoadRunner *rri = NULL; mWasStarted = true; mIsWorking = true; //Any thread working on this Job list need to increment this one Mutex::ScopedLock lock(mNrOfWorkersMutex); mNrOfWorkers++; mNrOfWorkersMutex.unlock(); while(!mIsTimeToDie) { { //Scope for scoped lock Mutex::ScopedLock lock(mJobsMutex); if(mJobs.size() == 0) { RRPLOG(tlp::lDebug5)<<"Waiting for jobs in loadSBML worker"; //mJobsCondition.wait(mJobsMutex); break; } if(mIsTimeToDie) { break; //ends the life of the thread.. } else { //Get a job rri = mJobs.front(); mJobs.pop_front(); } } //Causes the scoped lock to unlock //Do the job if(rri) { RRPLOG(lDebug2)<<"Loading model into instance: "<<rri->getInstanceID(); if(mModelFileName.size()) { rri->load(mModelFileName, &mLoadSBMLOptions); } else if(mSBML.size()) { rri->load(mSBML, &mLoadSBMLOptions); } } else { RRPLOG(lError)<<"Null job pointer...!"; } } RRPLOG(lDebug)<<"Exiting Load Model thread: "<<mThread.id(); mIsWorking = false; Mutex::ScopedLock lock2(mNrOfWorkersMutex); mNrOfWorkers--; }
void SimulateThread::worker() { mWasStarted = true; mIsWorking = true; Mutex::ScopedLock lock(mNrOfWorkersMutex); mNrOfWorkers++; mNrOfWorkersMutex.unlock(); RoadRunner *rri = NULL; ////////////////////////////////// while(!mIsTimeToDie) { { //Scope for the mutex lock... Mutex::ScopedLock lock(mJobsMutex); if(mJobs.size() == 0 )//|| mIsTimeToDie) { break; //ends the life of the thread.. } rri = mJobs.front(); mJobs.pop_front(); } //Causes the scoped lock to unlock //Do the job if(rri) { Log(lInfo)<<"Simulating RR instance: "<<rri->getInstanceID(); if(!rri->simulate2()) { Log(lError)<<"Failed simulating instance: "<<rri->getInstanceID(); } } else { Log(lError)<<"Null job pointer...!"; } } Log(lDebug)<<"Exiting Simulate thread: "<<mThread.id(); mIsWorking = false; Mutex::ScopedLock lock2(mNrOfWorkersMutex); mNrOfWorkers--; }