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