Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:32

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