File indexing completed on 2024-04-06 12:11:55
0001 #ifndef FWCore_Concurrency_FinalWaitingTask_h
0002 #define FWCore_Concurrency_FinalWaitingTask_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include "oneapi/tbb/task_group.h"
0025
0026
0027 #include "FWCore/Concurrency/interface/WaitingTask.h"
0028
0029
0030 namespace edm {
0031 class FinalWaitingTask : public WaitingTask {
0032 public:
0033 FinalWaitingTask() = delete;
0034 explicit FinalWaitingTask(tbb::task_group& iGroup)
0035 : m_group{&iGroup}, m_handle{iGroup.defer([]() {})}, m_done{false} {}
0036
0037 void execute() final { m_done = true; }
0038
0039 [[nodiscard]] bool done() const noexcept { return m_done.load(); }
0040
0041 void wait() {
0042 m_group->wait();
0043 if (exceptionPtr()) {
0044 std::rethrow_exception(exceptionPtr());
0045 }
0046 }
0047 std::exception_ptr waitNoThrow() {
0048 m_group->wait();
0049 return exceptionPtr();
0050 }
0051
0052 private:
0053 void recycle() final { m_group->run(std::move(m_handle)); }
0054 tbb::task_group* m_group;
0055 tbb::task_handle m_handle;
0056 std::atomic<bool> m_done;
0057 };
0058
0059 }
0060 #endif