Line data Source code
1 : #include <optional> 2 : #include <mutex> 3 : #include <algorithm> 4 : 5 : #include "SpComputeEngine.hpp" 6 : #include "TaskGraph/SpAbstractTaskGraph.hpp" 7 : #include "Task/SpAbstractTask.hpp" 8 : #include "SpWorker.hpp" 9 : 10 140 : void SpComputeEngine::stopIfNotAlreadyStopped() { 11 140 : if(!hasBeenStopped) { 12 : { 13 104 : std::unique_lock<std::mutex> computeEngineLock(ceMutex); 14 204 : for(auto& w : workers) { 15 152 : w->setStopFlag(true); 16 : } 17 : } 18 : 19 52 : ceCondVar.notify_all(); 20 : 21 204 : for(auto& w : workers) { 22 152 : w->waitForThread(); 23 : } 24 : 25 52 : hasBeenStopped = true; 26 : } 27 140 : } 28 : 29 437 : void SpComputeEngine::wait(SpWorker& worker, SpAbstractTaskGraph* atg) { 30 874 : std::unique_lock<std::mutex> ceLock(ceMutex); 31 437 : updateWorkerCounters<false, true>(worker.getType(), +1); 32 1850 : ceCondVar.wait(ceLock, [&]() { return worker.hasBeenStopped() || areThereAnyWorkersToMigrate() || areThereAnyReadyTasks() || (atg && atg->isFinished());}); 33 437 : updateWorkerCounters<false, true>(worker.getType(), -1); 34 437 : }