Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-05 08:04:43

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