Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:55

0001 #ifndef FWCore_Concurrency_FinalWaitingTask_h
0002 #define FWCore_Concurrency_FinalWaitingTask_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Concurrency
0006 // Class  :     FinalWaitingTask
0007 //
0008 /**\class FinalWaitingTask FinalWaitingTask.h "FWCore/Concurrency/interface/FinalWaitingTask.h"
0009 
0010  Description: [one line class summary]
0011 
0012  Usage:
0013    Use this class on the stack to signal the final task to be run.
0014    Call done() to check to see if the task was run and check value of
0015    exceptionPtr() to see if an exception was thrown by any task in the group.
0016 
0017 */
0018 //
0019 // Original Author:  Christopher Jones
0020 //         Created:  Tue, 12 Jul 2022 18:45:15 GMT
0021 //
0022 
0023 // system include files
0024 #include "oneapi/tbb/task_group.h"
0025 
0026 // user include files
0027 #include "FWCore/Concurrency/interface/WaitingTask.h"
0028 
0029 // forward declarations
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 }  // namespace edm
0060 #endif