Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85814 - trunk/boost/sync/detail/mutexes
From: andrey.semashev_at_[hidden]
Date: 2013-09-21 16:33:14


Author: andysem
Date: 2013-09-21 16:33:14 EDT (Sat, 21 Sep 2013)
New Revision: 85814
URL: http://svn.boost.org/trac/boost/changeset/85814

Log:
Simplified the code a little.

Text files modified:
   trunk/boost/sync/detail/mutexes/timed_mutex_windows.hpp | 55 ++++++++++++++++-----------------------
   1 files changed, 23 insertions(+), 32 deletions(-)

Modified: trunk/boost/sync/detail/mutexes/timed_mutex_windows.hpp
==============================================================================
--- trunk/boost/sync/detail/mutexes/timed_mutex_windows.hpp Sat Sep 21 16:17:00 2013 (r85813)
+++ trunk/boost/sync/detail/mutexes/timed_mutex_windows.hpp 2013-09-21 16:33:14 EDT (Sat, 21 Sep 2013) (r85814)
@@ -23,10 +23,8 @@
 #include <boost/assert.hpp>
 #include <boost/throw_exception.hpp>
 #include <boost/utility/enable_if.hpp>
-#include <boost/detail/winapi/handles.hpp>
 #include <boost/detail/winapi/synchronization.hpp>
 #include <boost/sync/exceptions/lock_error.hpp>
-#include <boost/sync/exceptions/resource_error.hpp>
 #include <boost/sync/detail/config.hpp>
 #include <boost/sync/detail/interlocked.hpp>
 #include <boost/sync/detail/time_traits.hpp>
@@ -104,44 +102,37 @@
 
         long old_count = m_mutex.m_active_count;
         m_mutex.mark_waiting_and_try_lock(old_count);
+ if ((old_count & mutex::lock_flag_value) == 0)
+ return true;
 
- if ((old_count & mutex::lock_flag_value) != 0)
+ const boost::detail::winapi::HANDLE_ evt = m_mutex.get_event();
+ sync::detail::system_duration::native_type time_left = t.get();
+ while (time_left > 0)
         {
- bool lock_acquired = false;
- boost::detail::winapi::HANDLE_ const evt = m_mutex.get_event();
-
- uint64_t time_left = t.get();
- do
+ const unsigned int dur = time_left > (std::numeric_limits< int >::max)() ?
+ static_cast< unsigned int >((std::numeric_limits< int >::max)()) : static_cast< unsigned int >(time_left);
+ const boost::detail::winapi::DWORD_ res = boost::detail::winapi::WaitForSingleObject(evt, dur);
+ switch (res)
             {
- const unsigned int dur = time_left > (std::numeric_limits< int >::max)() ?
- static_cast< unsigned int >((std::numeric_limits< int >::max)()) : static_cast< unsigned int >(time_left);
- const boost::detail::winapi::DWORD_ res = boost::detail::winapi::WaitForSingleObject(evt, dur);
- switch (res)
- {
- case boost::detail::winapi::wait_object_0:
- m_mutex.clear_waiting_and_try_lock(old_count);
- lock_acquired = (old_count & mutex::lock_flag_value) == 0;
- break;
-
- case boost::detail::winapi::wait_timeout:
- time_left -= dur;
- break;
-
- default:
- BOOST_ATOMIC_INTERLOCKED_EXCHANGE_ADD(&m_mutex.m_active_count, -1);
- BOOST_THROW_EXCEPTION(lock_error(res, "boost: timed_mutex timedlock failed in WaitForSingleObject"));
- }
- }
- while (!lock_acquired && time_left > 0);
+ case boost::detail::winapi::wait_object_0:
+ m_mutex.clear_waiting_and_try_lock(old_count);
+ if ((old_count & mutex::lock_flag_value) == 0)
+ return true;
+ break;
+
+ case boost::detail::winapi::wait_timeout:
+ time_left -= dur;
+ break;
 
- if (!lock_acquired)
- {
+ default:
                 BOOST_ATOMIC_INTERLOCKED_EXCHANGE_ADD(&m_mutex.m_active_count, -1);
- return false;
+ BOOST_THROW_EXCEPTION(lock_error(res, "boost: timed_mutex timedlock failed in WaitForSingleObject"));
             }
         }
 
- return true;
+ BOOST_ATOMIC_INTERLOCKED_EXCHANGE_ADD(&m_mutex.m_active_count, -1);
+
+ return false;
     }
 
     template< typename TimePoint >


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