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