Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-01 08:18:07

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 #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/detail/win32_api.hpp>
0025 #include <boost/interprocess/detail/windows_intermodule_singleton.hpp>
0026 #include <boost/interprocess/sync/windows/sync_utils.hpp>
0027 #include <boost/interprocess/sync/windows/winapi_mutex_wrapper.hpp>
0028 #include <boost/interprocess/exceptions.hpp>
0029 #include <boost/interprocess/timed_utils.hpp>
0030 
0031 
0032 namespace boost {
0033 namespace interprocess {
0034 namespace ipcdetail {
0035 
0036 class winapi_mutex
0037 {
0038    winapi_mutex(const winapi_mutex &);
0039    winapi_mutex &operator=(const winapi_mutex &);
0040    public:
0041 
0042    winapi_mutex();
0043    ~winapi_mutex();
0044 
0045    void lock();
0046    bool try_lock();
0047    template<class TimePoint> bool timed_lock(const TimePoint &abs_time);
0048 
0049    template<class TimePoint> bool try_lock_until(const TimePoint &abs_time)
0050    {  return this->timed_lock(abs_time);  }
0051 
0052    template<class Duration>  bool try_lock_for(const Duration &dur)
0053    {  return this->timed_lock(duration_to_ustime(dur)); }
0054 
0055    void unlock();
0056    void take_ownership(){};
0057 
0058    private:
0059    const sync_id id_;
0060 };
0061 
0062 inline winapi_mutex::winapi_mutex()
0063    : id_()
0064 {
0065    sync_handles &handles =
0066       windows_intermodule_singleton<sync_handles>::get();
0067    //Create mutex with the initial count
0068    bool open_or_created;
0069    (void)handles.obtain_mutex(this->id_, this, &open_or_created);
0070    //The mutex must be created, never opened
0071    BOOST_ASSERT(open_or_created);
0072    BOOST_ASSERT(open_or_created && winapi::get_last_error() != winapi::error_already_exists);
0073    (void)open_or_created;
0074 }
0075 
0076 inline winapi_mutex::~winapi_mutex()
0077 {
0078    sync_handles &handles =
0079       windows_intermodule_singleton<sync_handles>::get();
0080    handles.destroy_handle(this->id_, this);
0081 }
0082 
0083 inline void winapi_mutex::lock(void)
0084 {
0085    sync_handles &handles =
0086       windows_intermodule_singleton<sync_handles>::get();
0087    //This can throw
0088    winapi_mutex_functions mut(handles.obtain_mutex(this->id_, this));
0089    mut.lock();
0090 }
0091 
0092 inline bool winapi_mutex::try_lock(void)
0093 {
0094    sync_handles &handles =
0095       windows_intermodule_singleton<sync_handles>::get();
0096    //This can throw
0097    winapi_mutex_functions mut(handles.obtain_mutex(this->id_, this));
0098    return mut.try_lock();
0099 }
0100 
0101 template<class TimePoint>
0102 inline bool winapi_mutex::timed_lock(const TimePoint &abs_time)
0103 {
0104    sync_handles &handles =
0105       windows_intermodule_singleton<sync_handles>::get();
0106    //This can throw
0107    winapi_mutex_functions mut(handles.obtain_mutex(this->id_, this));
0108    return mut.timed_lock(abs_time);
0109 }
0110 
0111 inline void winapi_mutex::unlock(void)
0112 {
0113    sync_handles &handles =
0114       windows_intermodule_singleton<sync_handles>::get();
0115    //This can throw
0116    winapi_mutex_functions mut(handles.obtain_mutex(this->id_, this));
0117    return mut.unlock();
0118 }
0119 
0120 }  //namespace ipcdetail {
0121 }  //namespace interprocess {
0122 }  //namespace boost {
0123 
0124 #include <boost/interprocess/detail/config_end.hpp>
0125 
0126 #endif   //BOOST_INTERPROCESS_DETAIL_WINDOWS_MUTEX_HPP