Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-15 08:48:45

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