Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-19 07:54:41

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_NAMED_RECURSIVE_MUTEX_HPP
0012 #define BOOST_INTERPROCESS_NAMED_RECURSIVE_MUTEX_HPP
0013 
0014 #ifndef BOOST_CONFIG_HPP
0015 #  include <boost/config.hpp>
0016 #endif
0017 0018 ">#
0019 #if defined(BOOST_HAS_PRAGMA_ONCE)
0020 #  pragma once
0021 #endif
0022 
0023 #include <boost/interprocess/detail/config_begin.hpp>
0024 #include <boost/interprocess/detail/workaround.hpp>
0025 #include <boost/interprocess/creation_tags.hpp>
0026 #include <boost/interprocess/permissions.hpp>
0027 #include <boost/interprocess/timed_utils.hpp>
0028 
0029 #if !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION) && defined (BOOST_INTERPROCESS_WINDOWS)
0030    #include <boost/interprocess/sync/windows/named_recursive_mutex.hpp>
0031    #define BOOST_INTERPROCESS_NAMED_RECURSIVE_MUTEX_USE_WINAPI
0032 #else
0033    #include <boost/interprocess/sync/shm/named_recursive_mutex.hpp>
0034 #endif
0035 
0036 //!\file
0037 //!Describes a named named_recursive_mutex class for inter-process synchronization
0038 
0039 namespace boost {
0040 namespace interprocess {
0041 
0042 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0043 namespace ipcdetail{ class interprocess_tester; }
0044 #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0045 
0046 //!A recursive mutex with a global name, so it can be found from different
0047 //!processes. This mutex can't be placed in shared memory, and
0048 //!each process should have it's own named_recursive_mutex.
0049 class named_recursive_mutex
0050 {
0051    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0052    //Non-copyable
0053    named_recursive_mutex();
0054    named_recursive_mutex(const named_recursive_mutex &);
0055    named_recursive_mutex &operator=(const named_recursive_mutex &);
0056    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0057    public:
0058 
0059    //!Creates a global recursive_mutex with a name.
0060    //!If the recursive_mutex can't be created throws interprocess_exception
0061    named_recursive_mutex(create_only_t, const char *name, const permissions &perm = permissions());
0062 
0063    //!Opens or creates a global recursive_mutex with a name.
0064    //!If the recursive_mutex is created, this call is equivalent to
0065    //!named_recursive_mutex(create_only_t, ... )
0066    //!If the recursive_mutex is already created, this call is equivalent
0067    //!named_recursive_mutex(open_only_t, ... )
0068    //!Does not throw
0069    named_recursive_mutex(open_or_create_t, const char *name, const permissions &perm = permissions());
0070 
0071    //!Opens a global recursive_mutex with a name if that recursive_mutex is previously
0072    //!created. If it is not previously created this function throws
0073    //!interprocess_exception.
0074    named_recursive_mutex(open_only_t, const char *name);
0075 
0076    #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0077 
0078    //!Creates a global recursive_mutex with a name.
0079    //!If the recursive_mutex can't be created throws interprocess_exception
0080    //! 
0081    //!Note: This function is only available on operating systems with
0082    //!      native wchar_t APIs (e.g. Windows).
0083    named_recursive_mutex(create_only_t, const wchar_t *name, const permissions &perm = permissions());
0084 
0085    //!Opens or creates a global recursive_mutex with a name.
0086    //!If the recursive_mutex is created, this call is equivalent to
0087    //!named_recursive_mutex(create_only_t, ... )
0088    //!If the recursive_mutex is already created, this call is equivalent
0089    //!named_recursive_mutex(open_only_t, ... )
0090    //!Does not throw
0091    //! 
0092    //!Note: This function is only available on operating systems with
0093    //!      native wchar_t APIs (e.g. Windows).
0094    named_recursive_mutex(open_or_create_t, const wchar_t *name, const permissions &perm = permissions());
0095 
0096    //!Opens a global recursive_mutex with a name if that recursive_mutex is previously
0097    //!created. If it is not previously created this function throws
0098    //!interprocess_exception.
0099    //! 
0100    //!Note: This function is only available on operating systems with
0101    //!      native wchar_t APIs (e.g. Windows).
0102    named_recursive_mutex(open_only_t, const wchar_t *name);
0103 
0104    #endif //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0105 
0106    //!Destroys *this and indicates that the calling process is finished using
0107    //!the resource. The destructor function will deallocate
0108    //!any system resources allocated by the system for use by this process for
0109    //!this resource. The resource can still be opened again calling
0110    //!the open constructor overload. To erase the resource from the system
0111    //!use remove().
0112    ~named_recursive_mutex();
0113 
0114    //!Unlocks a previously locked
0115    //!named_recursive_mutex.
0116    void unlock();
0117 
0118    //!Locks named_recursive_mutex, sleeps when named_recursive_mutex is already 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    void lock();
0124 
0125    //!Tries to lock the named_recursive_mutex, returns false when named_recursive_mutex
0126    //!is already locked, returns true when success.
0127    //!Throws interprocess_exception if a severe error is found.
0128    //! 
0129    //!Note: A program shall not deadlock if the thread that has ownership calls 
0130    //!   this function. 
0131    bool try_lock();
0132 
0133    //!Tries to lock the named_recursive_mutex until time abs_time,
0134    //!Returns false when timeout expires, returns true when locks.
0135    //!Throws interprocess_exception if a severe error is found
0136    //! 
0137    //!Note: A program shall not deadlock if the thread that has ownership calls 
0138    //!   this function. 
0139    template<class TimePoint>
0140    bool timed_lock(const TimePoint &abs_time);
0141 
0142    //!Same as `timed_lock`, but this function is modeled after the
0143    //!standard library interface.
0144    template<class TimePoint> bool try_lock_until(const TimePoint &abs_time)
0145    {  return this->timed_lock(abs_time);  }
0146 
0147    //!Same as `timed_lock`, but this function is modeled after the
0148    //!standard library interface.
0149    template<class Duration>  bool try_lock_for(const Duration &dur)
0150    {  return this->timed_lock(ipcdetail::duration_to_ustime(dur)); }
0151 
0152    //!Erases a named recursive mutex
0153    //!from the system
0154    static bool remove(const char *name);
0155 
0156    #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0157    //!Erases a named recursive mutex
0158    //!from the system
0159    //! 
0160    //!Note: This function is only available on operating systems with
0161    //!      native wchar_t APIs (e.g. Windows).
0162    static bool remove(const wchar_t *name);
0163    #endif   //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0164 
0165    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0166    private:
0167    friend class ipcdetail::interprocess_tester;
0168    void dont_close_on_destruction();
0169 
0170    #if defined(BOOST_INTERPROCESS_NAMED_RECURSIVE_MUTEX_USE_WINAPI)
0171       typedef ipcdetail::winapi_named_recursive_mutex   impl_t;
0172    #else
0173       typedef ipcdetail::shm_named_recursive_mutex impl_t;
0174    #endif
0175    impl_t m_mut;
0176 
0177    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0178 };
0179 
0180 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0181 
0182 inline named_recursive_mutex::~named_recursive_mutex()
0183 {}
0184 
0185 inline void named_recursive_mutex::dont_close_on_destruction()
0186 {  ipcdetail::interprocess_tester::dont_close_on_destruction(m_mut);  }
0187 
0188 inline named_recursive_mutex::named_recursive_mutex(create_only_t, const char *name, const permissions &perm)
0189    :  m_mut  (create_only, name, perm)
0190 {}
0191 
0192 inline named_recursive_mutex::named_recursive_mutex(open_or_create_t, const char *name, const permissions &perm)
0193    :  m_mut  (open_or_create, name, perm)
0194 {}
0195 
0196 inline named_recursive_mutex::named_recursive_mutex(open_only_t, const char *name)
0197    :  m_mut   (open_only, name)
0198 {}
0199 
0200 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0201 
0202 inline named_recursive_mutex::named_recursive_mutex(create_only_t, const wchar_t *name, const permissions &perm)
0203    :  m_mut  (create_only, name, perm)
0204 {}
0205 
0206 inline named_recursive_mutex::named_recursive_mutex(open_or_create_t, const wchar_t *name, const permissions &perm)
0207    :  m_mut  (open_or_create, name, perm)
0208 {}
0209 
0210 inline named_recursive_mutex::named_recursive_mutex(open_only_t, const wchar_t *name)
0211    :  m_mut   (open_only, name)
0212 {}
0213 
0214 #endif   //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0215 
0216 inline void named_recursive_mutex::lock()
0217 {  m_mut.lock();  }
0218 
0219 inline void named_recursive_mutex::unlock()
0220 {  m_mut.unlock();  }
0221 
0222 inline bool named_recursive_mutex::try_lock()
0223 {  return m_mut.try_lock();  }
0224 
0225 template<class TimePoint>
0226 inline bool named_recursive_mutex::timed_lock(const TimePoint &abs_time)
0227 {  return m_mut.timed_lock(abs_time);  }
0228 
0229 inline bool named_recursive_mutex::remove(const char *name)
0230 {  return impl_t::remove(name); }
0231 
0232 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0233 
0234 inline bool named_recursive_mutex::remove(const wchar_t *name)
0235 {  return impl_t::remove(name); }
0236 
0237 #endif   //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0238 
0239 #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0240 
0241 }  //namespace interprocess {
0242 }  //namespace boost {
0243 
0244 #include <boost/interprocess/detail/config_end.hpp>
0245 
0246 #endif   //BOOST_INTERPROCESS_NAMED_RECURSIVE_MUTEX_HPP