Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-03 08:17:16

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_CONDITION_ANY_HPP
0012 #define BOOST_INTERPROCESS_NAMED_CONDITION_ANY_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 
0025 #include <boost/interprocess/sync/cv_status.hpp>
0026 #include <boost/interprocess/creation_tags.hpp>
0027 #include <boost/interprocess/exceptions.hpp>
0028 #include <boost/interprocess/timed_utils.hpp>
0029 #include <boost/interprocess/detail/interprocess_tester.hpp>
0030 #include <boost/interprocess/permissions.hpp>
0031 #include <boost/interprocess/sync/detail/locks.hpp>
0032 #if !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION) && defined (BOOST_INTERPROCESS_WINDOWS)
0033    #include <boost/interprocess/sync/windows/named_condition_any.hpp>
0034    #define BOOST_INTERPROCESS_NAMED_CONDITION_ANY_USE_WINAPI
0035 #else
0036    #include <boost/interprocess/sync/shm/named_condition_any.hpp>
0037 #endif
0038 
0039 //!\file
0040 //!Describes a named condition class for inter-process synchronization
0041 
0042 namespace boost {
0043 namespace interprocess {
0044 
0045 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0046 namespace ipcdetail{ class interprocess_tester; }
0047 #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0048 
0049 //! A global condition variable that can be created by name.
0050 //! This condition variable is designed to work with named_mutex and
0051 //! can't be placed in shared memory or memory mapped files.
0052 class named_condition_any
0053 {
0054    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0055    //Non-copyable
0056    named_condition_any();
0057    named_condition_any(const named_condition_any &);
0058    named_condition_any &operator=(const named_condition_any &);
0059    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0060 
0061    public:
0062    //!Creates a global condition with a name.
0063    //!If the condition can't be created throws interprocess_exception
0064    named_condition_any(create_only_t, const char *name, const permissions &perm = permissions())
0065       :  m_cond(create_only_t(), name, perm)
0066    {}
0067 
0068    //!Opens or creates a global condition with a name.
0069    //!If the condition is created, this call is equivalent to
0070    //!named_condition_any(create_only_t, ... )
0071    //!If the condition is already created, this call is equivalent
0072    //!named_condition_any(open_only_t, ... )
0073    //!Does not throw
0074    named_condition_any(open_or_create_t, const char *name, const permissions &perm = permissions())
0075       :  m_cond(open_or_create_t(), name, perm)
0076    {}
0077 
0078    //!Opens a global condition with a name if that condition is previously
0079    //!created. If it is not previously created this function throws
0080    //!interprocess_exception.
0081    named_condition_any(open_only_t, const char *name)
0082       :  m_cond(open_only_t(), name)
0083    {}
0084 
0085    #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0086 
0087    //!Creates a global condition with a name.
0088    //!If the condition can't be created throws interprocess_exception
0089    //! 
0090    //!Note: This function is only available on operating systems with
0091    //!      native wchar_t APIs (e.g. Windows).
0092    named_condition_any(create_only_t, const wchar_t *name, const permissions &perm = permissions())
0093       :  m_cond(create_only_t(), name, perm)
0094    {}
0095 
0096    //!Opens or creates a global condition with a name.
0097    //!If the condition is created, this call is equivalent to
0098    //!named_condition_any(create_only_t, ... )
0099    //!If the condition is already created, this call is equivalent
0100    //!named_condition_any(open_only_t, ... )
0101    //!Does not throw
0102    //! 
0103    //!Note: This function is only available on operating systems with
0104    //!      native wchar_t APIs (e.g. Windows).
0105    named_condition_any(open_or_create_t, const wchar_t *name, const permissions &perm = permissions())
0106       :  m_cond(open_or_create_t(), name, perm)
0107    {}
0108 
0109    //!Opens a global condition with a name if that condition is previously
0110    //!created. If it is not previously created this function throws
0111    //!interprocess_exception.
0112    //! 
0113    //!Note: This function is only available on operating systems with
0114    //!      native wchar_t APIs (e.g. Windows).
0115    named_condition_any(open_only_t, const wchar_t *name)
0116       :  m_cond(open_only_t(), name)
0117    {}
0118 
0119    #endif   //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0120 
0121    //!Destroys *this and indicates that the calling process is finished using
0122    //!the resource. The destructor function will deallocate
0123    //!any system resources allocated by the system for use by this process for
0124    //!this resource. The resource can still be opened again calling
0125    //!the open constructor overload. To erase the resource from the system
0126    //!use remove().
0127    ~named_condition_any()
0128    {}
0129 
0130    //!If there is a thread waiting on *this, change that
0131    //!thread's state to ready. Otherwise there is no effect.*/
0132    void notify_one()
0133    {  m_cond.notify_one();  }
0134 
0135    //!Change the state of all threads waiting on *this to ready.
0136    //!If there are no waiting threads, notify_all() has no effect.
0137    void notify_all()
0138    {  m_cond.notify_all();  }
0139 
0140    //!Releases the lock on the named_mutex object associated with lock, blocks
0141    //!the current thread of execution until readied by a call to
0142    //!this->notify_one() or this->notify_all(), and then reacquires the lock.
0143    template <typename L>
0144    void wait(L& lock)
0145    {  return m_cond.wait(lock); }
0146 
0147    //!The same as:
0148    //!while (!pred()) wait(lock)
0149    template <typename L, typename Pr>
0150    void wait(L& lock, Pr pred)
0151    {  return m_cond.wait(lock, pred); }
0152 
0153    //!Releases the lock on the named_mutex object associated with lock, blocks
0154    //!the current thread of execution until readied by a call to
0155    //!this->notify_one() or this->notify_all(), or until time abs_time is reached,
0156    //!and then reacquires the lock.
0157    //!Returns: false if time abs_time is reached, otherwise true.
0158    template <typename L, typename TimePoint>
0159    bool timed_wait(L& lock, const TimePoint &abs_time)
0160    {  return m_cond.timed_wait(lock, abs_time); }
0161 
0162    //!The same as:   while (!pred()) {
0163    //!                  if (!timed_wait(lock, abs_time)) return pred();
0164    //!               } return true;
0165    template <typename L, typename TimePoint, typename Pr>
0166    bool timed_wait(L& lock, const TimePoint &abs_time, Pr pred)
0167    {  return m_cond.timed_wait(lock, abs_time, pred); }
0168 
0169    //!Same as `timed_wait`, but this function is modeled after the
0170    //!standard library interface.
0171    template <typename L, class TimePoint>
0172    cv_status wait_until(L& lock, const TimePoint &abs_time)
0173    {  return this->timed_wait(lock, abs_time) ? cv_status::no_timeout : cv_status::timeout; }
0174 
0175    //!Same as `timed_wait`, but this function is modeled after the
0176    //!standard library interface.
0177    template <typename L, class TimePoint, typename Pr>
0178    bool wait_until(L& lock, const TimePoint &abs_time, Pr pred)
0179    {  return this->timed_wait(lock, abs_time, pred); }
0180 
0181    //!Same as `timed_wait`, but this function is modeled after the
0182    //!standard library interface and uses relative timeouts.
0183    template <typename L, class Duration>
0184    cv_status wait_for(L& lock, const Duration &dur)
0185    {  return this->wait_until(lock, ipcdetail::duration_to_ustime(dur)); }
0186 
0187    //!Same as `timed_wait`, but this function is modeled after the
0188    //!standard library interface and uses relative timeouts
0189    template <typename L, class Duration, typename Pr>
0190    bool wait_for(L& lock, const Duration &dur, Pr pred)
0191    {  return this->wait_until(lock, ipcdetail::duration_to_ustime(dur), pred); }
0192 
0193    //!Erases a named condition from the system.
0194    //!Returns false on error. Never throws.
0195    static bool remove(const char *name)
0196    {  return condition_any_type::remove(name);  }
0197 
0198    #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0199 
0200    //!Erases a named condition from the system.
0201    //!Returns false on error. Never throws.
0202    //! 
0203    //!Note: This function is only available on operating systems with
0204    //!      native wchar_t APIs (e.g. Windows).
0205    static bool remove(const wchar_t *name)
0206    {  return condition_any_type::remove(name);  }
0207 
0208    #endif //defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0209 
0210    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0211    private:
0212    #if defined(BOOST_INTERPROCESS_NAMED_CONDITION_ANY_USE_WINAPI)
0213    typedef ipcdetail::winapi_named_condition_any   condition_any_type;
0214    #else
0215    typedef ipcdetail::shm_named_condition_any       condition_any_type;
0216    #endif
0217    condition_any_type m_cond;
0218 
0219    friend class ipcdetail::interprocess_tester;
0220    void dont_close_on_destruction()
0221    {  ipcdetail::interprocess_tester::dont_close_on_destruction(m_cond); }
0222    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0223 };
0224 
0225 }  //namespace interprocess
0226 }  //namespace boost
0227 
0228 #include <boost/interprocess/detail/config_end.hpp>
0229 
0230 #endif // BOOST_INTERPROCESS_NAMED_CONDITION_ANY_HPP