qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject qpid-proton git commit: PROTON-1605: c++: Use mutex instead of std::atomic in container impl
Date Wed, 04 Oct 2017 21:35:32 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master fdaff9c4c -> 714a8bd2e


PROTON-1605: c++: Use mutex instead of std::atomic in container impl


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/714a8bd2
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/714a8bd2
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/714a8bd2

Branch: refs/heads/master
Commit: 714a8bd2e739c7638441e0bc72785e2b9315559d
Parents: fdaff9c
Author: Alan Conway <aconway@redhat.com>
Authored: Wed Oct 4 17:12:35 2017 -0400
Committer: Alan Conway <aconway@redhat.com>
Committed: Wed Oct 4 17:12:35 2017 -0400

----------------------------------------------------------------------
 .../bindings/cpp/include/proton/container.hpp   |  2 +-
 .../cpp/src/include/proactor_container_impl.hpp |  6 ++----
 .../cpp/src/proactor_container_impl.cpp         | 21 ++++++++++++++++----
 3 files changed, 20 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/714a8bd2/proton-c/bindings/cpp/include/proton/container.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/include/proton/container.hpp b/proton-c/bindings/cpp/include/proton/container.hpp
index 8e12dc3..72155ba 100644
--- a/proton-c/bindings/cpp/include/proton/container.hpp
+++ b/proton-c/bindings/cpp/include/proton/container.hpp
@@ -37,7 +37,7 @@
 
 /// @cond INTERNAL
 /// True if the library can support multithreaded containers.
-#define PN_CPP_SUPPORTS_THREADS PN_CPP_HAS_STD_THREAD && PN_CPP_HAS_STD_MUTEX &&
PN_CPP_HAS_STD_ATOMIC
+#define PN_CPP_SUPPORTS_THREADS PN_CPP_HAS_STD_THREAD && PN_CPP_HAS_STD_MUTEX
 /// @endcond
 
 namespace proton {

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/714a8bd2/proton-c/bindings/cpp/src/include/proactor_container_impl.hpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/include/proactor_container_impl.hpp b/proton-c/bindings/cpp/src/include/proactor_container_impl.hpp
index 2204371..06dbcb5 100644
--- a/proton-c/bindings/cpp/src/include/proactor_container_impl.hpp
+++ b/proton-c/bindings/cpp/src/include/proactor_container_impl.hpp
@@ -44,20 +44,18 @@
 #include <vector>
 
 #if PN_CPP_SUPPORTS_THREADS
-#include <atomic>
 #include <mutex>
 # define MUTEX(x) std::mutex x;
 # define GUARD(x) std::lock_guard<std::mutex> g(x)
 # define ONCE_FLAG(x) std::once_flag x;
 # define CALL_ONCE(x, ...) std::call_once(x, __VA_ARGS__)
-# define ATOMIC_INT(x) std::atomic<int> x;
 #else
 # define MUTEX(x)
 # define GUARD(x)
 # define ONCE_FLAG(x)
 # define CALL_ONCE(x, f, o) ((o)->*(f))()
-# define ATOMIC_INT(x) int x;
 #endif
+
 struct pn_proactor_t;
 struct pn_listener_t;
 struct pn_event_t;
@@ -115,7 +113,7 @@ class container::impl {
     bool handle(pn_event_t*);
     void run_timer_jobs();
 
-    ATOMIC_INT(threads_)
+    int threads_;
     container& container_;
     MUTEX(lock_)
 

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/714a8bd2/proton-c/bindings/cpp/src/proactor_container_impl.cpp
----------------------------------------------------------------------
diff --git a/proton-c/bindings/cpp/src/proactor_container_impl.cpp b/proton-c/bindings/cpp/src/proactor_container_impl.cpp
index cd0fc79..30940ff 100644
--- a/proton-c/bindings/cpp/src/proactor_container_impl.cpp
+++ b/proton-c/bindings/cpp/src/proactor_container_impl.cpp
@@ -474,10 +474,12 @@ bool container::impl::handle(pn_event_t* event) {
         return false;
 
     // We only interrupt to stop threads
-    case PN_PROACTOR_INTERRUPT:
+    case PN_PROACTOR_INTERRUPT: {
         // Interrupt any other threads still running
+        GUARD(lock_);
         if (threads_>1) pn_proactor_interrupt(proactor_);
         return true;
+    }
 
     case PN_PROACTOR_TIMEOUT: {
         // Can get an immediate timeout, if we have a container event loop inject
@@ -613,7 +615,10 @@ bool container::impl::handle(pn_event_t* event) {
 }
 
 void container::impl::thread() {
-    ++threads_;
+    {
+        GUARD(lock_);
+        ++threads_;
+    }
     bool finished = false;
     do {
       pn_event_batch_t *events = pn_proactor_wait(proactor_);
@@ -636,7 +641,10 @@ void container::impl::thread() {
       }
       pn_proactor_done(proactor_, events);
     } while(!finished);
-    --threads_;
+    {
+        GUARD(lock_);
+        --threads_;
+    }
 }
 
 void container::impl::start_event() {
@@ -669,7 +677,12 @@ void container::impl::run(int threads) {
     thread();
 #endif
 
-    if (threads_==0) CALL_ONCE(stop_once_, &impl::stop_event, this);
+    bool last = false;
+    {
+        GUARD(lock_);
+        last =  threads_==0;
+    }
+    if (last) CALL_ONCE(stop_once_, &impl::stop_event, this);
 
     // Throw an exception if we disconnected the proactor because of an exception
     if (!disconnect_error_.empty()) {


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


Mime
View raw message