From a18cc5c514137aafc295a04e2bb61e1fc1945af2 Mon Sep 17 00:00:00 2001 From: Andrea Bocci Date: Thu, 3 Dec 2020 10:11:27 +0100 Subject: [PATCH] Add a doneWaiting overload without the exception argument --- src/fwtest/Framework/WaitingTaskHolder.h | 14 +++++++++----- .../Framework/WaitingTaskWithArenaHolder.cc | 18 +++++++++++++----- .../Framework/WaitingTaskWithArenaHolder.h | 6 ++++++ src/fwtest/bin/StreamSchedule.cc | 2 +- src/fwtest/plugin-Test2/TestProducer2.cc | 2 +- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/fwtest/Framework/WaitingTaskHolder.h b/src/fwtest/Framework/WaitingTaskHolder.h index d74c5d8ed..9cc1b5c66 100644 --- a/src/fwtest/Framework/WaitingTaskHolder.h +++ b/src/fwtest/Framework/WaitingTaskHolder.h @@ -34,7 +34,7 @@ namespace edm { explicit WaitingTaskHolder(edm::WaitingTask* iTask) : m_task(iTask) { m_task->increment_ref_count(); } ~WaitingTaskHolder() { if (m_task) { - doneWaiting(std::exception_ptr{}); + doneWaiting(); } } @@ -66,10 +66,7 @@ namespace edm { } } - void doneWaiting(std::exception_ptr iExcept) { - if (iExcept) { - m_task->dependentTaskFailed(iExcept); - } + void doneWaiting() { //spawn can run the task before we finish // doneWaiting and some other thread might // try to reuse this object. Resetting @@ -81,6 +78,13 @@ namespace edm { } } + void doneWaiting(std::exception_ptr iExcept) { + if (iExcept) { + m_task->dependentTaskFailed(iExcept); + } + doneWaiting(); + } + private: // ---------- member data -------------------------------- WaitingTask* m_task; diff --git a/src/fwtest/Framework/WaitingTaskWithArenaHolder.cc b/src/fwtest/Framework/WaitingTaskWithArenaHolder.cc index 7c852d041..d7c88001e 100644 --- a/src/fwtest/Framework/WaitingTaskWithArenaHolder.cc +++ b/src/fwtest/Framework/WaitingTaskWithArenaHolder.cc @@ -24,7 +24,7 @@ namespace edm { WaitingTaskWithArenaHolder::~WaitingTaskWithArenaHolder() { if (m_task) { - doneWaiting(std::exception_ptr{}); + doneWaiting(); } } @@ -58,10 +58,7 @@ namespace edm { // into the correct arena of threads. Use of the arena allows doneWaiting // to be called from a thread outside the arena of threads that will manage // the task. doneWaiting can be called from a non-TBB thread. - void WaitingTaskWithArenaHolder::doneWaiting(std::exception_ptr iExcept) { - if (iExcept) { - m_task->dependentTaskFailed(iExcept); - } + void WaitingTaskWithArenaHolder::doneWaiting() { //enqueue can run the task before we finish // doneWaiting and some other thread might // try to reuse this object. Resetting @@ -75,6 +72,17 @@ namespace edm { } } + // This spawns the task. The arena is needed to get the task spawned + // into the correct arena of threads. Use of the arena allows doneWaiting + // to be called from a thread outside the arena of threads that will manage + // the task. doneWaiting can be called from a non-TBB thread. + void WaitingTaskWithArenaHolder::doneWaiting(std::exception_ptr iExcept) { + if (iExcept) { + m_task->dependentTaskFailed(iExcept); + } + doneWaiting(); + } + // This next function is useful if you know from the context that // m_arena (which is set when the constructor was executes) is the // same arena in which you want to execute the doneWaiting function. diff --git a/src/fwtest/Framework/WaitingTaskWithArenaHolder.h b/src/fwtest/Framework/WaitingTaskWithArenaHolder.h index 4b14febfb..bab615686 100644 --- a/src/fwtest/Framework/WaitingTaskWithArenaHolder.h +++ b/src/fwtest/Framework/WaitingTaskWithArenaHolder.h @@ -48,6 +48,12 @@ namespace edm { WaitingTaskWithArenaHolder& operator=(WaitingTaskWithArenaHolder&& iRHS); + // This spawns the task. The arena is needed to get the task spawned + // into the correct arena of threads. Use of the arena allows doneWaiting + // to be called from a thread outside the arena of threads that will manage + // the task. doneWaiting can be called from a non-TBB thread. + void doneWaiting(); + // This spawns the task. The arena is needed to get the task spawned // into the correct arena of threads. Use of the arena allows doneWaiting // to be called from a thread outside the arena of threads that will manage diff --git a/src/fwtest/bin/StreamSchedule.cc b/src/fwtest/bin/StreamSchedule.cc index 8636bce24..2f1360fef 100644 --- a/src/fwtest/bin/StreamSchedule.cc +++ b/src/fwtest/bin/StreamSchedule.cc @@ -82,7 +82,7 @@ namespace edm { (*iWorker)->doWorkAsync(*eventPtr, *eventSetup_, nextEventTask); } } else { - h.doneWaiting(std::exception_ptr{}); + h.doneWaiting(); } } diff --git a/src/fwtest/plugin-Test2/TestProducer2.cc b/src/fwtest/plugin-Test2/TestProducer2.cc index 6df7bdb0d..6f88839ae 100644 --- a/src/fwtest/plugin-Test2/TestProducer2.cc +++ b/src/fwtest/plugin-Test2/TestProducer2.cc @@ -39,7 +39,7 @@ void TestProducer2::acquire(edm::Event const& event, future_ = std::async([holder = std::move(holder)]() mutable { using namespace std::chrono_literals; std::this_thread::sleep_for(1s); - holder.doneWaiting(std::exception_ptr()); + holder.doneWaiting(); return 42; });