NeoPZ
TPZTaskGroup.cpp
Go to the documentation of this file.
1 /*
2  * File: TPZTaskGroup.cpp
3  * Author: thiago
4  *
5  * Created on 1 de Agosto de 2018, 17:28
6  */
7 
8 #include "TPZTaskGroup.h"
9 #include <mutex>
10 #include <condition_variable>
11 
13 }
14 
16 }
17 
19 }
20 
22  std::unique_lock<std::mutex> lock(fMutex);
23  fPendingTasks.erase(task);
24  if (fPendingTasks.empty()){
25  fObservers.notify_all();
26  }
27 }
28 
30  std::unique_lock<std::mutex> lock(fMutex);
31  fPendingTasks.insert(task);
32 }
33 
35  std::unique_lock<std::mutex> lock(fMutex);
36  fObservers.wait(lock, [this] {
37  return fPendingTasks.empty();
38  });
39 }
40 
41 long unsigned int TPZTaskGroup::Active() {
42  return fPendingTasks.size();
43 }
std::condition_variable fObservers
Definition: TPZTaskGroup.h:30
long unsigned int Active()
Helper class for ordering the tasks that the user have requested.
Definition: TPZTask.h:18
std::mutex fMutex
Definition: TPZTaskGroup.h:29
std::set< TPZTask * > fPendingTasks
Definition: TPZTaskGroup.h:31
void Notify(TPZTask *task)
virtual ~TPZTaskGroup()
void RegisterTask(TPZTask *task)