Back to home page

EIC code displayed by LXR

 
 

    


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

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