File indexing completed on 2025-01-18 09:38:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_INTERPROCESS_DETAIL_WINAPI_MUTEX_WRAPPER_HPP
0012 #define BOOST_INTERPROCESS_DETAIL_WINAPI_MUTEX_WRAPPER_HPP
0013
0014 #ifndef BOOST_CONFIG_HPP
0015 # include <boost/config.hpp>
0016 #endif
0017 #
0018 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 # pragma once
0020 #endif
0021
0022 #include <boost/interprocess/detail/config_begin.hpp>
0023 #include <boost/interprocess/detail/workaround.hpp>
0024 #include <boost/interprocess/creation_tags.hpp>
0025 #include <boost/interprocess/permissions.hpp>
0026 #include <boost/interprocess/detail/win32_api.hpp>
0027 #include <boost/interprocess/sync/windows/winapi_wrapper_common.hpp>
0028 #include <boost/interprocess/errors.hpp>
0029 #include <boost/interprocess/exceptions.hpp>
0030 #include <limits>
0031
0032 namespace boost {
0033 namespace interprocess {
0034 namespace ipcdetail {
0035
0036 class winapi_mutex_functions
0037 {
0038 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0039
0040
0041 winapi_mutex_functions(const winapi_mutex_functions &);
0042 winapi_mutex_functions &operator=(const winapi_mutex_functions &);
0043 #endif
0044
0045 public:
0046 winapi_mutex_functions(void *mtx_hnd)
0047 : m_mtx_hnd(mtx_hnd)
0048 {}
0049
0050 void unlock()
0051 { winapi::release_mutex(m_mtx_hnd); }
0052
0053 void lock()
0054 { return winapi_wrapper_wait_for_single_object(m_mtx_hnd); }
0055
0056 bool try_lock()
0057 { return winapi_wrapper_try_wait_for_single_object(m_mtx_hnd); }
0058
0059 template<class TimePoint>
0060 bool timed_lock(const TimePoint &abs_time)
0061 { return winapi_wrapper_timed_wait_for_single_object(m_mtx_hnd, abs_time); }
0062
0063 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0064 protected:
0065 void *m_mtx_hnd;
0066 #endif
0067 };
0068
0069
0070 class winapi_mutex_wrapper
0071 : public winapi_mutex_functions
0072 {
0073 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0074
0075
0076 winapi_mutex_wrapper(const winapi_mutex_wrapper &);
0077 winapi_mutex_wrapper &operator=(const winapi_mutex_wrapper &);
0078 #endif
0079
0080
0081
0082
0083 public:
0084 winapi_mutex_wrapper(void *mtx_hnd = 0)
0085 : winapi_mutex_functions(mtx_hnd)
0086 {}
0087
0088 ~winapi_mutex_wrapper()
0089 { this->close(); }
0090
0091 void *release()
0092 {
0093 void *hnd = m_mtx_hnd;
0094 m_mtx_hnd = 0;
0095 return hnd;
0096 }
0097
0098 void *handle() const
0099 { return m_mtx_hnd; }
0100
0101 template<class CharT>
0102 bool open_or_create(const CharT *name, const permissions &perm)
0103 {
0104 if(m_mtx_hnd == 0){
0105 m_mtx_hnd = winapi::open_or_create_mutex
0106 ( name
0107 , false
0108 , (winapi::interprocess_security_attributes*)perm.get_permissions()
0109 );
0110 return m_mtx_hnd != 0;
0111 }
0112 else{
0113 return false;
0114 }
0115 }
0116
0117 void close()
0118 {
0119 if(m_mtx_hnd != 0){
0120 winapi::close_handle(m_mtx_hnd);
0121 m_mtx_hnd = 0;
0122 }
0123 }
0124
0125 void swap(winapi_mutex_wrapper &other)
0126 { void *tmp = m_mtx_hnd; m_mtx_hnd = other.m_mtx_hnd; other.m_mtx_hnd = tmp; }
0127 };
0128
0129 }
0130 }
0131 }
0132
0133 #include <boost/interprocess/detail/config_end.hpp>
0134
0135 #endif