1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_INTERPROCESS_DETAIL_WINDOWS_MUTEX_HPP
12 #define BOOST_INTERPROCESS_DETAIL_WINDOWS_MUTEX_HPP
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
22 #include <boost/interprocess/detail/config_begin.hpp>
23 #include <boost/interprocess/detail/workaround.hpp>
24 #include <boost/interprocess/detail/posix_time_types_wrk.hpp>
25 #include <boost/interprocess/detail/win32_api.hpp>
26 #include <boost/interprocess/detail/windows_intermodule_singleton.hpp>
27 #include <boost/interprocess/sync/windows/sync_utils.hpp>
28 #include <boost/interprocess/sync/windows/winapi_mutex_wrapper.hpp>
29 #include <boost/interprocess/exceptions.hpp>
33 namespace interprocess {
38 windows_mutex(const windows_mutex &);
39 windows_mutex &operator=(const windows_mutex &);
47 bool timed_lock(const boost::posix_time::ptime &abs_time);
49 void take_ownership(){};
55 inline windows_mutex::windows_mutex()
58 sync_handles &handles =
59 windows_intermodule_singleton<sync_handles>::get();
60 //Create mutex with the initial count
62 (void)handles.obtain_mutex(this->id_, &open_or_created);
63 //The mutex must be created, never opened
64 BOOST_ASSERT(open_or_created);
65 BOOST_ASSERT(open_or_created && winapi::get_last_error() != winapi::error_already_exists);
66 (void)open_or_created;
69 inline windows_mutex::~windows_mutex()
71 sync_handles &handles =
72 windows_intermodule_singleton<sync_handles>::get();
73 handles.destroy_handle(this->id_);
76 inline void windows_mutex::lock(void)
78 sync_handles &handles =
79 windows_intermodule_singleton<sync_handles>::get();
81 winapi_mutex_functions mut(handles.obtain_mutex(this->id_));
85 inline bool windows_mutex::try_lock(void)
87 sync_handles &handles =
88 windows_intermodule_singleton<sync_handles>::get();
90 winapi_mutex_functions mut(handles.obtain_mutex(this->id_));
91 return mut.try_lock();
94 inline bool windows_mutex::timed_lock(const boost::posix_time::ptime &abs_time)
96 sync_handles &handles =
97 windows_intermodule_singleton<sync_handles>::get();
99 winapi_mutex_functions mut(handles.obtain_mutex(this->id_));
100 return mut.timed_lock(abs_time);
103 inline void windows_mutex::unlock(void)
105 sync_handles &handles =
106 windows_intermodule_singleton<sync_handles>::get();
108 winapi_mutex_functions mut(handles.obtain_mutex(this->id_));
112 } //namespace ipcdetail {
113 } //namespace interprocess {
114 } //namespace boost {
116 #include <boost/interprocess/detail/config_end.hpp>
118 #endif //BOOST_INTERPROCESS_DETAIL_WINDOWS_MUTEX_HPP