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