Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-11 08:13:57

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 // Parts of the pthread code come from Boost Threads code:
0012 //
0013 //////////////////////////////////////////////////////////////////////////////
0014 //
0015 // Copyright (C) 2001-2003
0016 // William E. Kempf
0017 //
0018 // Permission to use, copy, modify, distribute and sell this software
0019 // and its documentation for any purpose is hereby granted without fee,
0020 // provided that the above copyright notice appear in all copies and
0021 // that both that copyright notice and this permission notice appear
0022 // in supporting documentation.  William E. Kempf makes no representations
0023 // about the suitability of this software for any purpose.
0024 // It is provided "as is" without express or implied warranty.
0025 //////////////////////////////////////////////////////////////////////////////
0026 
0027 #ifndef BOOST_INTERPROCESS_RECURSIVE_MUTEX_HPP
0028 #define BOOST_INTERPROCESS_RECURSIVE_MUTEX_HPP
0029 
0030 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0031 
0032 #ifndef BOOST_CONFIG_HPP
0033 #  include <boost/config.hpp>
0034 #endif
0035 #
0036 #if defined(BOOST_HAS_PRAGMA_ONCE)
0037 #  pragma once
0038 #endif
0039 
0040 #include <boost/interprocess/detail/config_begin.hpp>
0041 #include <boost/interprocess/detail/workaround.hpp>
0042 #include <boost/interprocess/timed_utils.hpp>
0043 #include <boost/interprocess/sync/detail/common_algorithms.hpp>
0044 #include <boost/assert.hpp>
0045 
0046 #if   !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION) && \
0047        defined(BOOST_INTERPROCESS_POSIX_PROCESS_SHARED) && \
0048        defined (BOOST_INTERPROCESS_POSIX_RECURSIVE_MUTEXES)
0049    #include <boost/interprocess/sync/posix/recursive_mutex.hpp>
0050    #define BOOST_INTERPROCESS_RECURSIVE_MUTEX_USE_POSIX
0051 #elif !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION) && defined (BOOST_INTERPROCESS_WINDOWS)
0052    //Experimental...
0053    #include <boost/interprocess/sync/windows/recursive_mutex.hpp>
0054    #define BOOST_INTERPROCESS_RECURSIVE_MUTEX_USE_WINAPI
0055 #else
0056    //spin_recursive_mutex is used
0057    #include <boost/interprocess/sync/spin/recursive_mutex.hpp>
0058    namespace boost {
0059    namespace interprocess {
0060    namespace ipcdetail{
0061    namespace robust_emulation_helpers {
0062 
0063    template<class T>
0064    class mutex_traits;
0065 
0066    }}}}
0067 #endif
0068 
0069 #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0070 
0071 //!\file
0072 //!Describes interprocess_recursive_mutex and shared_recursive_try_mutex classes
0073 
0074 namespace boost {
0075 namespace interprocess {
0076 
0077 //!Wraps a interprocess_mutex that can be placed in shared memory and can be
0078 //!shared between processes. Allows several locking calls by the same
0079 //!process. Allows timed lock tries
0080 class interprocess_recursive_mutex
0081 {
0082    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0083    //Non-copyable
0084    interprocess_recursive_mutex(const interprocess_recursive_mutex &);
0085    interprocess_recursive_mutex &operator=(const interprocess_recursive_mutex &);
0086    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0087    public:
0088    //!Constructor.
0089    //!Throws interprocess_exception on error.
0090    interprocess_recursive_mutex();
0091 
0092    //!Destructor. If any process uses the mutex after the destructor is called
0093    //!the result is undefined. Does not throw.
0094   ~interprocess_recursive_mutex();
0095 
0096    //!Effects: The calling thread tries to obtain ownership of the mutex, and
0097    //!   if another thread has ownership of the mutex, it waits until it can
0098    //!   obtain the ownership. If a thread takes ownership of the mutex the
0099    //!   mutex must be unlocked by the same mutex. The mutex must be unlocked
0100    //!   the same number of times it is locked.
0101    //!Throws: interprocess_exception on error.
0102    //! 
0103    //!Note: A program shall not deadlock if the thread that has ownership calls 
0104    //!   this function. 
0105    void lock();
0106 
0107    //!Tries to lock the interprocess_mutex, returns false when interprocess_mutex
0108    //!is already locked, returns true when success. The mutex must be unlocked
0109    //!the same number of times it is locked.
0110    //!Throws: interprocess_exception if a severe error is found
0111    //! 
0112    //!Note: A program shall not deadlock if the thread that has ownership calls 
0113    //!   this function. 
0114    bool try_lock();
0115 
0116    //!Tries to lock the interprocess_mutex, if interprocess_mutex can't be locked before
0117    //!abs_time time, returns false. The mutex must be unlocked
0118    //!   the same number of times it is locked.
0119    //!Throws: interprocess_exception if a severe error is found
0120    //! 
0121    //!Note: A program shall not deadlock if the thread that has ownership calls 
0122    //!   this function.
0123    template<class TimePoint>
0124    bool timed_lock(const TimePoint &abs_time);
0125 
0126    //!Same as `timed_lock`, but this function is modeled after the
0127    //!standard library interface.
0128    template<class TimePoint> bool try_lock_until(const TimePoint &abs_time)
0129    {  return this->timed_lock(abs_time);  }
0130 
0131    //!Same as `timed_lock`, but this function is modeled after the
0132    //!standard library interface.
0133    template<class Duration>  bool try_lock_for(const Duration &dur)
0134    {  return this->timed_lock(ipcdetail::duration_to_ustime(dur)); }
0135 
0136    //!Effects: The calling thread releases the exclusive ownership of the mutex.
0137    //!   If the mutex supports recursive locking, the mutex must be unlocked the
0138    //!   same number of times it is locked.
0139    //!Throws: interprocess_exception on error.
0140    void unlock();
0141    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0142    private:
0143 
0144    #if defined(BOOST_INTERPROCESS_RECURSIVE_MUTEX_USE_POSIX)
0145       ipcdetail::posix_recursive_mutex mutex;
0146    #elif defined(BOOST_INTERPROCESS_RECURSIVE_MUTEX_USE_WINAPI)
0147       ipcdetail::winapi_recursive_mutex mutex;
0148    #else
0149       void take_ownership(){ mutex.take_ownership(); }
0150       friend class ipcdetail::robust_emulation_helpers::mutex_traits<interprocess_recursive_mutex>;
0151       ipcdetail::spin_recursive_mutex mutex;
0152    #endif
0153    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0154 };
0155 
0156 }  //namespace interprocess {
0157 }  //namespace boost {
0158 
0159 namespace boost {
0160 namespace interprocess {
0161 
0162 inline interprocess_recursive_mutex::interprocess_recursive_mutex(){}
0163 
0164 inline interprocess_recursive_mutex::~interprocess_recursive_mutex(){}
0165 
0166 inline void interprocess_recursive_mutex::lock()
0167 {  ipcdetail::timeout_when_locking_aware_lock(mutex);  }
0168 
0169 inline bool interprocess_recursive_mutex::try_lock()
0170 { return mutex.try_lock(); }
0171 
0172 template<class TimePoint>
0173 inline bool interprocess_recursive_mutex::timed_lock(const TimePoint &abs_time)
0174 { return mutex.timed_lock(abs_time); }
0175 
0176 inline void interprocess_recursive_mutex::unlock()
0177 { mutex.unlock(); }
0178 
0179 }  //namespace interprocess {
0180 }  //namespace boost {
0181 
0182 #include <boost/interprocess/detail/config_end.hpp>
0183 
0184 #endif   //BOOST_INTERPROCESS_RECURSIVE_MUTEX_HPP