1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2011-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_WINAPI_MUTEX_WRAPPER_HPP
12 #define BOOST_INTERPROCESS_DETAIL_WINAPI_MUTEX_WRAPPER_HPP
18 #include <boost/interprocess/detail/config_begin.hpp>
19 #include <boost/interprocess/detail/workaround.hpp>
20 #include <boost/interprocess/creation_tags.hpp>
21 #include <boost/interprocess/permissions.hpp>
22 #include <boost/interprocess/detail/win32_api.hpp>
23 #include <boost/interprocess/detail/posix_time_types_wrk.hpp>
24 #include <boost/interprocess/sync/windows/winapi_wrapper_common.hpp>
25 #include <boost/interprocess/errors.hpp>
26 #include <boost/interprocess/exceptions.hpp>
30 namespace interprocess {
33 class winapi_mutex_functions
35 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
38 winapi_mutex_functions(const winapi_mutex_functions &);
39 winapi_mutex_functions &operator=(const winapi_mutex_functions &);
40 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
43 winapi_mutex_functions(void *mtx_hnd)
48 { winapi::release_mutex(m_mtx_hnd); }
51 { return winapi_wrapper_wait_for_single_object(m_mtx_hnd); }
54 { return winapi_wrapper_try_wait_for_single_object(m_mtx_hnd); }
56 bool timed_lock(const boost::posix_time::ptime &abs_time)
57 { return winapi_wrapper_timed_wait_for_single_object(m_mtx_hnd, abs_time); }
59 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
62 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
65 //Swappable mutex wrapper
66 class winapi_mutex_wrapper
67 : public winapi_mutex_functions
69 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
72 winapi_mutex_wrapper(const winapi_mutex_wrapper &);
73 winapi_mutex_wrapper &operator=(const winapi_mutex_wrapper &);
74 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
76 //Note that Windows API does not return winapi::invalid_handle_value
77 //when failing to create/open a mutex, but a nullptr
80 winapi_mutex_wrapper(void *mtx_hnd = 0)
81 : winapi_mutex_functions(mtx_hnd)
84 ~winapi_mutex_wrapper()
89 void *hnd = m_mtx_hnd;
97 bool open_or_create(const char *name, const permissions &perm)
100 m_mtx_hnd = winapi::open_or_create_mutex
103 , (winapi::interprocess_security_attributes*)perm.get_permissions()
105 return m_mtx_hnd != 0;
115 winapi::close_handle(m_mtx_hnd);
120 void swap(winapi_mutex_wrapper &other)
121 { void *tmp = m_mtx_hnd; m_mtx_hnd = other.m_mtx_hnd; other.m_mtx_hnd = tmp; }
124 } //namespace ipcdetail {
125 } //namespace interprocess {
126 } //namespace boost {
128 #include <boost/interprocess/detail/config_end.hpp>
130 #endif //BOOST_INTERPROCESS_DETAIL_WINAPI_MUTEX_WRAPPER_HPP