Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-05 08:35:56

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_DETAIL_WINDOWS_CONDITION_HPP
0012 #define BOOST_INTERPROCESS_DETAIL_WINDOWS_CONDITION_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/sync/interprocess_mutex.hpp>
0027 #include <boost/interprocess/sync/scoped_lock.hpp>
0028 #include <boost/interprocess/exceptions.hpp>
0029 #include <boost/interprocess/sync/windows/semaphore.hpp>
0030 #include <boost/interprocess/sync/windows/mutex.hpp>
0031 #include <boost/interprocess/timed_utils.hpp>
0032 #include <boost/interprocess/sync/detail/condition_algorithm_8a.hpp>
0033 
0034 
0035 namespace boost {
0036 namespace interprocess {
0037 namespace ipcdetail {
0038 
0039 class winapi_condition
0040 {
0041    winapi_condition(const winapi_condition &);
0042    winapi_condition &operator=(const winapi_condition &);
0043 
0044    public:
0045    winapi_condition()
0046       : m_condition_data()
0047    {}
0048 
0049    ~winapi_condition()
0050    {
0051       //Notify all waiting threads
0052       //to allow POSIX semantics on condition destruction
0053       this->notify_all();
0054    }
0055 
0056    void notify_one()
0057    {  m_condition_data.notify_one();   }
0058 
0059    void notify_all()
0060    {  m_condition_data.notify_all();   }
0061 
0062    template <typename L>
0063    void wait(L& lock)
0064    {  m_condition_data.wait(lock);   }
0065 
0066    template <typename L, typename Pr>
0067    void wait(L& lock, Pr pred)
0068    {  m_condition_data.wait(lock, pred);   }
0069 
0070 
0071    template <typename L, typename TimePoint>
0072    bool timed_wait(L& lock, const TimePoint &abs_time)
0073    {  return m_condition_data.timed_wait(lock, abs_time);   }
0074 
0075    template <typename L, typename TimePoint, typename Pr>
0076    bool timed_wait(L& lock, const TimePoint &abs_time, Pr pred)
0077    {  return m_condition_data.timed_wait(lock, abs_time, pred);   }
0078 
0079    template <typename L, class TimePoint>
0080    cv_status wait_until(L& lock, const TimePoint &abs_time)
0081    {  return this->timed_wait(lock, abs_time) ? cv_status::no_timeout : cv_status::timeout; }
0082 
0083    template <typename L, class TimePoint, typename Pr>
0084    bool wait_until(L& lock, const TimePoint &abs_time, Pr pred)
0085    {  return this->timed_wait(lock, abs_time, pred); }
0086 
0087    template <typename L, class Duration>
0088    cv_status wait_for(L& lock, const Duration &dur)
0089    {  return this->wait_until(lock, duration_to_ustime(dur)); }
0090 
0091    template <typename L, class Duration, typename Pr>
0092    bool wait_for(L& lock, const Duration &dur, Pr pred)
0093    {  return this->wait_until(lock, duration_to_ustime(dur), pred); }
0094 
0095    private:
0096 
0097    struct condition_data
0098    {
0099       typedef unsigned int      integer_type;
0100       typedef winapi_semaphore  semaphore_type;
0101       typedef winapi_mutex      mutex_type;
0102 
0103       condition_data()
0104          : m_nwaiters_blocked(0)
0105          , m_nwaiters_gone(0)
0106          , m_nwaiters_to_unblock(0)
0107          , m_sem_block_queue(0)
0108          , m_sem_block_lock(1)
0109          , m_mtx_unblock_lock()
0110       {}
0111 
0112       integer_type    &get_nwaiters_blocked()
0113       {  return m_nwaiters_blocked;  }
0114 
0115       integer_type    &get_nwaiters_gone()
0116       {  return m_nwaiters_gone;  }
0117 
0118       integer_type    &get_nwaiters_to_unblock()
0119       {  return m_nwaiters_to_unblock;  }
0120 
0121       semaphore_type  &get_sem_block_queue()
0122       {  return m_sem_block_queue;  }
0123 
0124       semaphore_type  &get_sem_block_lock()
0125       {  return m_sem_block_lock;  }
0126 
0127       mutex_type      &get_mtx_unblock_lock()
0128       {  return m_mtx_unblock_lock;  }
0129 
0130       integer_type            m_nwaiters_blocked;
0131       integer_type            m_nwaiters_gone;
0132       integer_type            m_nwaiters_to_unblock;
0133       semaphore_type          m_sem_block_queue;
0134       semaphore_type          m_sem_block_lock;
0135       mutex_type              m_mtx_unblock_lock;
0136    };
0137 
0138    ipcdetail::condition_8a_wrapper<condition_data> m_condition_data;
0139 };
0140 
0141 }  //namespace ipcdetail
0142 }  //namespace interprocess
0143 }  //namespace boost
0144 
0145 #include <boost/interprocess/detail/config_end.hpp>
0146 
0147 #endif   //BOOST_INTERPROCESS_DETAIL_WINDOWS_CONDITION_HPP