summaryrefslogtreecommitdiff
path: root/boost/interprocess/sync/windows/mutex.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/interprocess/sync/windows/mutex.hpp')
-rw-r--r--boost/interprocess/sync/windows/mutex.hpp63
1 files changed, 20 insertions, 43 deletions
diff --git a/boost/interprocess/sync/windows/mutex.hpp b/boost/interprocess/sync/windows/mutex.hpp
index 5eca522339..477acd396a 100644
--- a/boost/interprocess/sync/windows/mutex.hpp
+++ b/boost/interprocess/sync/windows/mutex.hpp
@@ -19,8 +19,9 @@
#include <boost/interprocess/detail/workaround.hpp>
#include <boost/interprocess/detail/posix_time_types_wrk.hpp>
#include <boost/interprocess/detail/win32_api.hpp>
-#include <boost/interprocess/detail/intermodule_singleton.hpp>
+#include <boost/interprocess/detail/windows_intermodule_singleton.hpp>
#include <boost/interprocess/sync/windows/sync_utils.hpp>
+#include <boost/interprocess/sync/windows/winapi_mutex_wrapper.hpp>
#include <boost/interprocess/exceptions.hpp>
@@ -47,85 +48,61 @@ class windows_mutex
const sync_id id_;
};
-inline windows_mutex::windows_mutex()
- : id_()
+inline windows_mutex::windows_mutex()
+ : id_(this)
{
sync_handles &handles =
- intermodule_singleton<sync_handles>::get();
+ windows_intermodule_singleton<sync_handles>::get();
//Create mutex with the initial count
bool open_or_created;
- handles.obtain_mutex(this->id_, &open_or_created);
+ (void)handles.obtain_mutex(this->id_, &open_or_created);
//The mutex must be created, never opened
assert(open_or_created);
assert(open_or_created && winapi::get_last_error() != winapi::error_already_exists);
(void)open_or_created;
}
-inline windows_mutex::~windows_mutex()
+inline windows_mutex::~windows_mutex()
{
sync_handles &handles =
- intermodule_singleton<sync_handles>::get();
+ windows_intermodule_singleton<sync_handles>::get();
handles.destroy_handle(this->id_);
}
inline void windows_mutex::lock(void)
{
sync_handles &handles =
- intermodule_singleton<sync_handles>::get();
+ windows_intermodule_singleton<sync_handles>::get();
//This can throw
- void *hnd = handles.obtain_mutex(this->id_);
- unsigned long ret = winapi::wait_for_single_object(hnd, winapi::infinite_time);
- if(ret == winapi::wait_failed){
- error_info err(winapi::get_last_error());
- throw interprocess_exception(err);
- }
+ winapi_mutex_functions mut(handles.obtain_mutex(this->id_));
+ mut.lock();
}
inline bool windows_mutex::try_lock(void)
{
sync_handles &handles =
- intermodule_singleton<sync_handles>::get();
+ windows_intermodule_singleton<sync_handles>::get();
//This can throw
- void *hnd = handles.obtain_mutex(this->id_);
- unsigned long ret = winapi::wait_for_single_object(hnd, 0);
- if(ret == winapi::wait_failed){
- error_info err(winapi::get_last_error());
- throw interprocess_exception(err);
- }
- return ret != winapi::wait_timeout;
+ winapi_mutex_functions mut(handles.obtain_mutex(this->id_));
+ return mut.try_lock();
}
inline bool windows_mutex::timed_lock(const boost::posix_time::ptime &abs_time)
{
- if(abs_time == boost::posix_time::pos_infin){
- this->lock();
- return true;
- }
- boost::posix_time::ptime now
- = boost::posix_time::microsec_clock::universal_time();
-
- unsigned long ms = (unsigned long)(abs_time-now).total_milliseconds();
sync_handles &handles =
- intermodule_singleton<sync_handles>::get();
+ windows_intermodule_singleton<sync_handles>::get();
//This can throw
- void *hnd = handles.obtain_mutex(this->id_);
- unsigned long ret = winapi::wait_for_single_object(hnd, ms);
- if(ret == winapi::wait_failed){
- error_info err(winapi::get_last_error());
- throw interprocess_exception(err);
- }
- return ret != winapi::wait_timeout;
+ winapi_mutex_functions mut(handles.obtain_mutex(this->id_));
+ return mut.timed_lock(abs_time);
}
inline void windows_mutex::unlock(void)
{
sync_handles &handles =
- intermodule_singleton<sync_handles>::get();
+ windows_intermodule_singleton<sync_handles>::get();
//This can throw
- void *hnd = handles.obtain_mutex(this->id_);
- int ret = winapi::release_mutex(hnd);
- (void)ret;
- assert(ret);
+ winapi_mutex_functions mut(handles.obtain_mutex(this->id_));
+ return mut.unlock();
}
} //namespace ipcdetail {