Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:26:36

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
0004 // Software License, Version 1.0. (See accompanying file
0005 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // See http://www.boost.org/libs/interprocess for documentation.
0008 //
0009 //////////////////////////////////////////////////////////////////////////////
0010 
0011 #ifndef BOOST_INTERPROCESS_DETAIL_WINDOWS_MUTEX_HPP
0012 #define BOOST_INTERPROCESS_DETAIL_WINDOWS_MUTEX_HPP
0013 
0014 #ifndef BOOST_CONFIG_HPP
0015 #  include <boost/config.hpp>
0016 #endif
0017 0018 ">#
0019 #if defined(BOOST_HAS_PRAGMA_ONCE)
0020 #  pragma once
0021 #endif
0022 
0023 #include <boost/interprocess/detail/config_begin.hpp>
0024 #include <boost/interprocess/detail/workaround.hpp>
0025 #include <boost/interprocess/detail/win32_api.hpp>
0026 #include <boost/interprocess/detail/windows_intermodule_singleton.hpp>
0027 #include <boost/interprocess/sync/windows/sync_utils.hpp>
0028 #include <boost/interprocess/sync/windows/winapi_mutex_wrapper.hpp>
0029 #include <boost/interprocess/exceptions.hpp>
0030 #include <boost/interprocess/timed_utils.hpp>
0031 
0032 
0033 namespace boost {
0034 namespace interprocess {
0035 namespace ipcdetail {
0036 
0037 class winapi_mutex
0038 {
0039    winapi_mutex(const winapi_mutex &);
0040    winapi_mutex &operator=(const winapi_mutex &);
0041    public:
0042 
0043    winapi_mutex();
0044    ~winapi_mutex();
0045 
0046    void lock();
0047    bool try_lock();
0048    template<class TimePoint> bool timed_lock(const TimePoint &abs_time);
0049 
0050    template<class TimePoint> bool try_lock_until(const TimePoint &abs_time)
0051    {  return this->timed_lock(abs_time);  }
0052 
0053    template<class Duration>  bool try_lock_for(const Duration &dur)
0054    {  return this->timed_lock(duration_to_ustime(dur)); }
0055 
0056    void unlock();
0057    void take_ownership(){};
0058 
0059    private:
0060    const sync_id id_;
0061 };
0062 
0063 inline winapi_mutex::winapi_mutex()
0064    : id_()
0065 {
0066    sync_handles &handles =
0067       windows_intermodule_singleton<sync_handles>::get();
0068    //Create mutex with the initial count
0069    bool open_or_created;
0070    (void)handles.obtain_mutex(this->id_, this, &open_or_created);
0071    //The mutex must be created, never opened
0072    BOOST_ASSERT(open_or_created);
0073    BOOST_ASSERT(open_or_created && winapi::get_last_error() != winapi::error_already_exists);
0074    (void)open_or_created;
0075 }
0076 
0077 inline winapi_mutex::~winapi_mutex()
0078 {
0079    sync_handles &handles =
0080       windows_intermodule_singleton<sync_handles>::get();
0081    handles.destroy_handle(this->id_, this);
0082 }
0083 
0084 inline void winapi_mutex::lock(void)
0085 {
0086    sync_handles &handles =
0087       windows_intermodule_singleton<sync_handles>::get();
0088    //This can throw
0089    winapi_mutex_functions mut(handles.obtain_mutex(this->id_, this));
0090    mut.lock();
0091 }
0092 
0093 inline bool winapi_mutex::try_lock(void)
0094 {
0095    sync_handles &handles =
0096       windows_intermodule_singleton<sync_handles>::get();
0097    //This can throw
0098    winapi_mutex_functions mut(handles.obtain_mutex(this->id_, this));
0099    return mut.try_lock();
0100 }
0101 
0102 template<class TimePoint>
0103 inline bool winapi_mutex::timed_lock(const TimePoint &abs_time)
0104 {
0105    sync_handles &handles =
0106       windows_intermodule_singleton<sync_handles>::get();
0107    //This can throw
0108    winapi_mutex_functions mut(handles.obtain_mutex(this->id_, this));
0109    return mut.timed_lock(abs_time);
0110 }
0111 
0112 inline void winapi_mutex::unlock(void)
0113 {
0114    sync_handles &handles =
0115       windows_intermodule_singleton<sync_handles>::get();
0116    //This can throw
0117    winapi_mutex_functions mut(handles.obtain_mutex(this->id_, this));
0118    return mut.unlock();
0119 }
0120 
0121 }  //namespace ipcdetail {
0122 }  //namespace interprocess {
0123 }  //namespace boost {
0124 
0125 #include <boost/interprocess/detail/config_end.hpp>
0126 
0127 #endif   //BOOST_INTERPROCESS_DETAIL_WINDOWS_MUTEX_HPP