[asterisk-scf-commits] asterisk-scf/integration/ice-util-cpp.git branch "retry_deux" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Mar 21 13:01:56 CDT 2012


branch "retry_deux" has been updated
       via  994a7eb8876d5c83f2b6b9084da59e08175fc96e (commit)
      from  5246276cc8d2546abed711bd81705a864cdd16f2 (commit)

Summary of changes:
 .../AsteriskSCF/Operations/OperationContextCache.h |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)


- Log -----------------------------------------------------------------
commit 994a7eb8876d5c83f2b6b9084da59e08175fc96e
Author: David M. Lee <dlee at digium.com>
Date:   Wed Mar 21 13:01:45 2012 -0500

    Made ValueOperationContextCookie thread safe

diff --git a/include/AsteriskSCF/Operations/OperationContextCache.h b/include/AsteriskSCF/Operations/OperationContextCache.h
index c4374ce..5e607c5 100644
--- a/include/AsteriskSCF/Operations/OperationContextCache.h
+++ b/include/AsteriskSCF/Operations/OperationContextCache.h
@@ -15,7 +15,7 @@
  */
 #pragma once
 
-#include <boost/thread/shared_mutex.hpp>
+#include <boost/thread.hpp>
 #include <boost/enable_shared_from_this.hpp>
 #include <boost/shared_ptr.hpp>
 #include <IceUtil/Timer.h>
@@ -60,12 +60,14 @@ public:
     /** Set the value of this cookie. */
     void set(const T& v)
     {
+        boost::lock_guard<boost::mutex> lock(mMutex);
         val = v;
     }
 
     /** Set the exception value of this cookie. */
     void setException(const IceUtil::Exception& e)
     {
+        boost::lock_guard<boost::mutex> lock(mMutex);
         ex.reset(e.ice_clone());
     }
 
@@ -75,6 +77,7 @@ public:
      */
     T get() const
     {
+        boost::lock_guard<boost::mutex> lock(mMutex);
         if (ex)
         {
             ex->ice_throw();
@@ -83,6 +86,10 @@ public:
     }
 
 private:
+    // This class has a very high write-to-read ratio, and the chance of two
+    // reads happening concurrently are small. There would be no benefit from
+    // a shared_mutex, so just using a plain mutex instead.
+    mutable boost::mutex mMutex;
     boost::shared_ptr<IceUtil::Exception> ex;
     T val;
 };

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/ice-util-cpp.git



More information about the asterisk-scf-commits mailing list