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