Skip to content

Commit

Permalink
PROTON-2792: [C++] check that scheduled tasks are active under lock
Browse files Browse the repository at this point in the history
Previously we checked whether the tasks were active without locking
which was bad.
  • Loading branch information
astitcher authored and Cliff Jansen committed Mar 18, 2024
1 parent d8fe876 commit 674b0c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cpp/include/proton/work_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class work {
/// **Unsettled API**
///
/// Execute the piece of work
void operator()() { item_(); }
void operator()() const { item_(); }

~work() = default;

Expand Down
13 changes: 10 additions & 3 deletions cpp/src/proactor_container_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,16 @@ void container::impl::run_timer_jobs() {
// NB. We copied the due tasks in reverse order so execute from end

for (int i = tasks.size()-1; i>=0; --i) {
if(is_active_.count(tasks[i].w_handle)) {
tasks[i].task();
is_active_.erase(tasks[i].w_handle);
const auto& task = tasks[i];
bool active;

{
GUARD(deferred_lock_);
// NB. erase returns the number of items erased
active = is_active_.erase(task.w_handle);
}
if (active) {
task.task();
}
}
}
Expand Down

0 comments on commit 674b0c6

Please sign in to comment.