Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-23 08:50:09

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