Boost logo

Boost-Commit :

From: anthony_at_[hidden]
Date: 2008-07-01 12:28:00


Author: anthonyw
Date: 2008-07-01 12:27:59 EDT (Tue, 01 Jul 2008)
New Revision: 46960
URL: http://svn.boost.org/trac/boost/changeset/46960

Log:
Added try_lock_upgrade to shared_mutex: second half of #1867 fix
Text files modified:
   trunk/boost/thread/win32/shared_mutex.hpp | 26 ++++++++++++++++++++++++++
   1 files changed, 26 insertions(+), 0 deletions(-)

Modified: trunk/boost/thread/win32/shared_mutex.hpp
==============================================================================
--- trunk/boost/thread/win32/shared_mutex.hpp (original)
+++ trunk/boost/thread/win32/shared_mutex.hpp 2008-07-01 12:27:59 EDT (Tue, 01 Jul 2008)
@@ -398,6 +398,32 @@
             }
         }
 
+ bool try_lock_upgrade()
+ {
+ state_data old_state=state;
+ for(;;)
+ {
+ state_data new_state=old_state;
+ if(new_state.exclusive || new_state.exclusive_waiting_blocked || new_state.upgrade)
+ {
+ return false;
+ }
+ else
+ {
+ ++new_state.shared_count;
+ new_state.upgrade=true;
+ }
+
+ state_data const current_state=interlocked_compare_exchange(&state,new_state,old_state);
+ if(current_state==old_state)
+ {
+ break;
+ }
+ old_state=current_state;
+ }
+ return true;
+ }
+
         void unlock_upgrade()
         {
             state_data old_state=state;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk