Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a doneWaiting overload without the exception argument #146

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/fwtest/Framework/WaitingTaskHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
18 changes: 13 additions & 5 deletions src/fwtest/Framework/WaitingTaskWithArenaHolder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace edm {

WaitingTaskWithArenaHolder::~WaitingTaskWithArenaHolder() {
if (m_task) {
doneWaiting(std::exception_ptr{});
doneWaiting();
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions src/fwtest/Framework/WaitingTaskWithArenaHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/fwtest/bin/StreamSchedule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace edm {
(*iWorker)->doWorkAsync(*eventPtr, *eventSetup_, nextEventTask);
}
} else {
h.doneWaiting(std::exception_ptr{});
h.doneWaiting();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/fwtest/plugin-Test2/TestProducer2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Expand Down