Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-15 08:36:50

0001 //////////////////////////////////////////////////////////////////////////////
0002 //
0003 // (C) Copyright Ion Gaztanaga 2012-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_CONDITION_ANY_HPP
0012 #define BOOST_INTERPROCESS_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 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0023 
0024 #include <boost/interprocess/detail/config_begin.hpp>
0025 #include <boost/interprocess/detail/workaround.hpp>
0026 
0027 #include <boost/interprocess/sync/cv_status.hpp>
0028 #include <boost/interprocess/timed_utils.hpp>
0029 #include <boost/interprocess/sync/interprocess_mutex.hpp>
0030 #include <boost/interprocess/sync/interprocess_condition.hpp>
0031 #include <boost/interprocess/exceptions.hpp>
0032 #include <boost/interprocess/sync/detail/condition_any_algorithm.hpp>
0033 
0034 #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0035 
0036 //!\file
0037 //!Describes process-shared variables interprocess_condition_any class
0038 
0039 namespace boost {
0040 namespace interprocess {
0041 
0042 //!This class is a condition variable that can be placed in shared memory or
0043 //!memory mapped files.
0044 //!
0045 //!The interprocess_condition_any class is a generalization of interprocess_condition.
0046 //!Whereas interprocess_condition works only on Locks with mutex_type == interprocess_mutex
0047 //!interprocess_condition_any can operate on any user-defined lock that meets the BasicLockable
0048 //!requirements (lock()/unlock() member functions).
0049 //!
0050 //!Unlike std::condition_variable_any in C++11, it is NOT safe to invoke the destructor if all
0051 //!threads have been only notified. It is required that they have exited their respective wait
0052 //!functions.
0053 class interprocess_condition_any
0054 {
0055    #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0056    //Non-copyable
0057    interprocess_condition_any(const interprocess_condition_any &);
0058    interprocess_condition_any &operator=(const interprocess_condition_any &);
0059 
0060    class members
0061    {
0062       public:
0063       typedef interprocess_condition   condvar_type;
0064       typedef interprocess_mutex       mutex_type;
0065 
0066       condvar_type &get_condvar() {  return m_cond;  }
0067       mutex_type   &get_mutex()   {  return m_mut; }
0068 
0069       private:
0070       condvar_type   m_cond;
0071       mutex_type     m_mut;
0072    };
0073 
0074    ipcdetail::condition_any_wrapper<members>   m_cond;
0075 
0076    #endif   //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0077    public:
0078    //!Constructs a interprocess_condition_any. On error throws interprocess_exception.
0079    interprocess_condition_any(){}
0080 
0081    //!Destroys *this
0082    //!liberating system resources.
0083    ~interprocess_condition_any(){}
0084 
0085    //!If there is a thread waiting on *this, change that
0086    //!thread's state to ready. Otherwise there is no effect.
0087    void notify_one()
0088    {  m_cond.notify_one();  }
0089 
0090    //!Change the state of all threads waiting on *this to ready.
0091    //!If there are no waiting threads, notify_all() has no effect.
0092    void notify_all()
0093    {  m_cond.notify_all();  }
0094 
0095    //!Releases the lock on the interprocess_mutex object associated with lock, blocks
0096    //!the current thread of execution until readied by a call to
0097    //!this->notify_one() or this->notify_all(), and then reacquires the lock.
0098    template <typename L>
0099    void wait(L& lock)
0100    {  m_cond.wait(lock);  }
0101 
0102    //!The same as:
0103    //!while (!pred()) wait(lock)
0104    template <typename L, typename Pr>
0105    void wait(L& lock, Pr pred)
0106    {  m_cond.wait(lock, pred);  }
0107 
0108    //!Releases the lock on the interprocess_mutex object associated with lock, blocks
0109    //!the current thread of execution until readied by a call to
0110    //!this->notify_one() or this->notify_all(), or until time abs_time is reached,
0111    //!and then reacquires the lock.
0112    //!Returns: false if time abs_time is reached, otherwise true.
0113    template <typename L, class TimePoint>
0114    bool timed_wait(L& lock, const TimePoint &abs_time)
0115    {  return m_cond.timed_wait(lock, abs_time);  }
0116 
0117    //!The same as:   while (!pred()) {
0118    //!                  if (!timed_wait(lock, abs_time)) return pred();
0119    //!               } return true;
0120    template <typename L, class TimePoint, typename Pr>
0121    bool timed_wait(L& lock, const TimePoint &abs_time, Pr pred)
0122    {  return m_cond.timed_wait(lock, abs_time, pred);  }
0123 
0124    //!Same as `timed_wait`, but this function is modeled after the
0125    //!standard library interface.
0126    template <typename L, class TimePoint>
0127    cv_status wait_until(L& lock, const TimePoint &abs_time)
0128    {  return this->timed_wait(lock, abs_time) ? cv_status::no_timeout : cv_status::timeout; }
0129 
0130    //!Same as `timed_wait`, but this function is modeled after the
0131    //!standard library interface.
0132    template <typename L, class TimePoint, typename Pr>
0133    bool wait_until(L& lock, const TimePoint &abs_time, Pr pred)
0134    {  return this->timed_wait(lock, abs_time, pred); }
0135 
0136    //!Same as `timed_wait`, but this function is modeled after the
0137    //!standard library interface and uses relative timeouts.
0138    template <typename L, class Duration>
0139    cv_status wait_for(L& lock, const Duration &dur)
0140    {  return this->wait_until(lock, ipcdetail::duration_to_ustime(dur)); }
0141 
0142    //!Same as `timed_wait`, but this function is modeled after the
0143    //!standard library interface and uses relative timeouts
0144    template <typename L, class Duration, typename Pr>
0145    bool wait_for(L& lock, const Duration &dur, Pr pred)
0146    {  return this->wait_until(lock, ipcdetail::duration_to_ustime(dur), pred); }
0147 };
0148 
0149 }  //namespace interprocess
0150 }  // namespace boost
0151 
0152 #include <boost/interprocess/detail/config_end.hpp>
0153 
0154 #endif // BOOST_INTERPROCESS_CONDITION_ANY_HPP