activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nmitt...@apache.org
Subject svn commit: r553856 - in /activemq/activemq-cpp/trunk/src/main/activemq/concurrent: Mutex.cpp Mutex.h
Date Fri, 06 Jul 2007 12:16:09 GMT
Author: nmittler
Date: Fri Jul  6 05:16:08 2007
New Revision: 553856

URL: http://svn.apache.org/viewvc?view=rev&rev=553856
Log:
AMQCPP-128 - made some small changes to Mutex class to help avoid race conditions with multiple
threads trying to lock the same mutex.

Modified:
    activemq/activemq-cpp/trunk/src/main/activemq/concurrent/Mutex.cpp
    activemq/activemq-cpp/trunk/src/main/activemq/concurrent/Mutex.h

Modified: activemq/activemq-cpp/trunk/src/main/activemq/concurrent/Mutex.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/concurrent/Mutex.cpp?view=diff&rev=553856&r1=553855&r2=553856
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/concurrent/Mutex.cpp (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/concurrent/Mutex.cpp Fri Jul  6 05:16:08
2007
@@ -52,7 +52,9 @@
 ////////////////////////////////////////////////////////////////////////////////
 void Mutex::lock() throw( exceptions::ActiveMQException )
 {
-    if(isLockOwner())
+	int threadId = Thread::getId();
+	
+    if(threadId == lock_owner)
     {
         lock_count++;
     }
@@ -64,8 +66,8 @@
         EnterCriticalSection(&mutex);
 #endif
 
-        lock_count = 1;
-        lock_owner = Thread::getId();
+        lock_owner = threadId;
+        lock_count = 1;        
     }         
 }
   

Modified: activemq/activemq-cpp/trunk/src/main/activemq/concurrent/Mutex.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/main/activemq/concurrent/Mutex.h?view=diff&rev=553856&r1=553855&r2=553856
==============================================================================
--- activemq/activemq-cpp/trunk/src/main/activemq/concurrent/Mutex.h (original)
+++ activemq/activemq-cpp/trunk/src/main/activemq/concurrent/Mutex.h Fri Jul  6 05:16:08 2007
@@ -71,8 +71,8 @@
         #endif
       
         // Lock Status Members
-        int           lock_count;
-        unsigned long lock_owner;
+        volatile int           lock_count;
+        volatile unsigned long lock_owner;
 
     public:
 
@@ -134,10 +134,9 @@
    
         /**
          * Check if the calling thread is the Lock Owner
-         * @retuns true if the caller is the lock owner
+         * @retun true if the caller is the lock owner
          */
-        bool isLockOwner()
-        {
+        bool isLockOwner(){
             return lock_owner == Thread::getId();
         }
       



Mime
View raw message