Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86476 - trunk/boost/interprocess/sync/windows
From: igaztanaga_at_[hidden]
Date: 2013-10-27 08:28:56


Author: igaztanaga
Date: 2013-10-27 08:28:55 EDT (Sun, 27 Oct 2013)
New Revision: 86476
URL: http://svn.boost.org/trac/boost/changeset/86476

Log:
Fixes #9285

Text files modified:
   trunk/boost/interprocess/sync/windows/winapi_mutex_wrapper.hpp | 38 +++++++++++++++++++++++---------------
   1 files changed, 23 insertions(+), 15 deletions(-)

Modified: trunk/boost/interprocess/sync/windows/winapi_mutex_wrapper.hpp
==============================================================================
--- trunk/boost/interprocess/sync/windows/winapi_mutex_wrapper.hpp Sun Oct 27 08:16:43 2013 (r86475)
+++ trunk/boost/interprocess/sync/windows/winapi_mutex_wrapper.hpp 2013-10-27 08:28:55 EDT (Sun, 27 Oct 2013) (r86476)
@@ -77,18 +77,23 @@
          this->lock();
          return true;
       }
-
- unsigned long ret = winapi::wait_for_single_object
- (m_mtx_hnd, (abs_time - microsec_clock::universal_time()).total_milliseconds());
- if(ret == winapi::wait_object_0){
- return true;
- }
- else if(ret == winapi::wait_timeout){
+ const boost::posix_time::ptime cur_time = microsec_clock::universal_time();
+ if(abs_time < cur_time){
          return false;
       }
       else{
- error_info err = system_error_code();
- throw interprocess_exception(err);
+ unsigned long ret = winapi::wait_for_single_object
+ (m_mtx_hnd, (abs_time - cur_time).total_milliseconds());
+ if(ret == winapi::wait_object_0){
+ return true;
+ }
+ else if(ret == winapi::wait_timeout){
+ return false;
+ }
+ else{
+ error_info err = system_error_code();
+ throw interprocess_exception(err);
+ }
       }
    }
 
@@ -109,8 +114,11 @@
    winapi_mutex_wrapper &operator=(const winapi_mutex_wrapper &);
    /// @endcond
 
+ //Note that Windows API does not return winapi::invalid_handle_value
+ //when failing to create/open a mutex, but a nullptr
+
    public:
- winapi_mutex_wrapper(void *mtx_hnd = winapi::invalid_handle_value)
+ winapi_mutex_wrapper(void *mtx_hnd = 0)
       : winapi_mutex_functions(mtx_hnd)
    {}
 
@@ -120,7 +128,7 @@
    void *release()
    {
       void *hnd = m_mtx_hnd;
- m_mtx_hnd = winapi::invalid_handle_value;
+ m_mtx_hnd = 0;
       return hnd;
    }
 
@@ -129,13 +137,13 @@
 
    bool open_or_create(const char *name, const permissions &perm)
    {
- if(m_mtx_hnd == winapi::invalid_handle_value){
+ if(m_mtx_hnd == 0){
          m_mtx_hnd = winapi::open_or_create_mutex
             ( name
             , false
             , (winapi::interprocess_security_attributes*)perm.get_permissions()
             );
- return m_mtx_hnd != winapi::invalid_handle_value;
+ return m_mtx_hnd != 0;
       }
       else{
          return false;
@@ -144,9 +152,9 @@
 
    void close()
    {
- if(m_mtx_hnd != winapi::invalid_handle_value){
+ if(m_mtx_hnd != 0){
          winapi::close_handle(m_mtx_hnd);
- m_mtx_hnd = winapi::invalid_handle_value;
+ m_mtx_hnd = 0;
       }
    }
 


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