This is an automated email from the ASF dual-hosted git repository.

astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git


The following commit(s) were added to refs/heads/main by this push:
     new 4b48f7d24 PROTON-2792: [C++] check that scheduled tasks are active 
under lock
4b48f7d24 is described below

commit 4b48f7d24ca83f221039c4e47ce42752f3b104ad
Author: Andrew Stitcher <astitc...@apache.org>
AuthorDate: Thu Mar 7 21:19:03 2024 -0500

    PROTON-2792: [C++] check that scheduled tasks are active under lock
    
    [Reapplied as it was accidentally reverted]
    
    Previously we checked whether the tasks were active without locking
    which was bad.
---
 cpp/include/proton/work_queue.hpp   |  2 +-
 cpp/src/proactor_container_impl.cpp | 13 ++++++++++---
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/cpp/include/proton/work_queue.hpp 
b/cpp/include/proton/work_queue.hpp
index e917fa3ce..defe1aaa7 100644
--- a/cpp/include/proton/work_queue.hpp
+++ b/cpp/include/proton/work_queue.hpp
@@ -280,7 +280,7 @@ class work {
     /// **Unsettled API**
     ///
     /// Execute the piece of work
-    void operator()() { item_(); }
+    void operator()() const { item_(); }
 
     ~work() = default;
 
diff --git a/cpp/src/proactor_container_impl.cpp 
b/cpp/src/proactor_container_impl.cpp
index e965be730..228002e38 100644
--- a/cpp/src/proactor_container_impl.cpp
+++ b/cpp/src/proactor_container_impl.cpp
@@ -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();
         }
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to