os/ossrv/ossrv_pub/boost_apis/boost/thread/condition.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/thread/condition.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,201 @@
     1.4 +// Copyright (C) 2001-2003
     1.5 +// William E. Kempf
     1.6 +//
     1.7 +//  Distributed under the Boost Software License, Version 1.0. (See accompanying 
     1.8 +//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     1.9 +
    1.10 +#ifndef BOOST_CONDITION_WEK070601_HPP
    1.11 +#define BOOST_CONDITION_WEK070601_HPP
    1.12 +
    1.13 +#include <boost/thread/detail/config.hpp>
    1.14 +
    1.15 +#include <boost/thread/exceptions.hpp>
    1.16 +#include <boost/utility.hpp>
    1.17 +#include <boost/thread/detail/lock.hpp>
    1.18 +
    1.19 +#if defined(BOOST_HAS_PTHREADS)
    1.20 +#   include <pthread.h>
    1.21 +#elif defined(BOOST_HAS_MPTASKS)
    1.22 +#   include "scoped_critical_region.hpp"
    1.23 +#endif
    1.24 +
    1.25 +namespace boost {
    1.26 +
    1.27 +struct xtime;
    1.28 +// disable warnings about non dll import
    1.29 +// see: http://www.boost.org/more/separate_compilation.html#dlls
    1.30 +#ifdef BOOST_MSVC
    1.31 +#   pragma warning(push)
    1.32 +#   pragma warning(disable: 4251 4231 4660 4275)
    1.33 +#endif
    1.34 +
    1.35 +namespace detail {
    1.36 +
    1.37 +class BOOST_THREAD_DECL condition_impl : private noncopyable
    1.38 +{
    1.39 +    friend class condition;
    1.40 +
    1.41 +public:
    1.42 +    condition_impl();
    1.43 +    ~condition_impl();
    1.44 +
    1.45 +    void notify_one();
    1.46 +    void notify_all();
    1.47 +
    1.48 +#if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
    1.49 +    void enter_wait();
    1.50 +    void do_wait();
    1.51 +    bool do_timed_wait(const xtime& xt);
    1.52 +#elif defined(BOOST_HAS_PTHREADS)
    1.53 +    void do_wait(pthread_mutex_t* pmutex);
    1.54 +    bool do_timed_wait(const xtime& xt, pthread_mutex_t* pmutex);
    1.55 +#endif
    1.56 +
    1.57 +#if defined(BOOST_HAS_WINTHREADS)
    1.58 +    void* m_gate;
    1.59 +    void* m_queue;
    1.60 +    void* m_mutex;
    1.61 +    unsigned m_gone;  // # threads that timed out and never made it to m_queue
    1.62 +    unsigned long m_blocked; // # threads blocked on the condition
    1.63 +    unsigned m_waiting; // # threads no longer waiting for the condition but
    1.64 +                        // still waiting to be removed from m_queue
    1.65 +#elif defined(BOOST_HAS_PTHREADS)
    1.66 +    pthread_cond_t m_condition;
    1.67 +#elif defined(BOOST_HAS_MPTASKS)
    1.68 +    MPSemaphoreID m_gate;
    1.69 +    MPSemaphoreID m_queue;
    1.70 +    threads::mac::detail::scoped_critical_region m_mutex;
    1.71 +    threads::mac::detail::scoped_critical_region m_mutex_mutex;
    1.72 +    unsigned m_gone; // # threads that timed out and never made it to m_queue
    1.73 +    unsigned long m_blocked; // # threads blocked on the condition
    1.74 +    unsigned m_waiting; // # threads no longer waiting for the condition but
    1.75 +                        // still waiting to be removed from m_queue
    1.76 +#endif
    1.77 +};
    1.78 +
    1.79 +} // namespace detail
    1.80 +
    1.81 +class condition : private noncopyable
    1.82 +{
    1.83 +public:
    1.84 +    condition() { }
    1.85 +    ~condition() { }
    1.86 +
    1.87 +    void notify_one() { m_impl.notify_one(); }
    1.88 +    void notify_all() { m_impl.notify_all(); }
    1.89 +
    1.90 +    template <typename L>
    1.91 +    void wait(L& lock)
    1.92 +    {
    1.93 +        if (!lock)
    1.94 +            throw lock_error();
    1.95 +
    1.96 +        do_wait(lock.m_mutex);
    1.97 +    }
    1.98 +
    1.99 +    template <typename L, typename Pr>
   1.100 +    void wait(L& lock, Pr pred)
   1.101 +    {
   1.102 +        if (!lock)
   1.103 +            throw lock_error();
   1.104 +
   1.105 +        while (!pred())
   1.106 +            do_wait(lock.m_mutex);
   1.107 +    }
   1.108 +
   1.109 +    template <typename L>
   1.110 +    bool timed_wait(L& lock, const xtime& xt)
   1.111 +    {
   1.112 +        if (!lock)
   1.113 +            throw lock_error();
   1.114 +
   1.115 +        return do_timed_wait(lock.m_mutex, xt);
   1.116 +    }
   1.117 +
   1.118 +    template <typename L, typename Pr>
   1.119 +    bool timed_wait(L& lock, const xtime& xt, Pr pred)
   1.120 +    {
   1.121 +        if (!lock)
   1.122 +            throw lock_error();
   1.123 +
   1.124 +        while (!pred())
   1.125 +        {
   1.126 +            if (!do_timed_wait(lock.m_mutex, xt))
   1.127 +                return false;
   1.128 +        }
   1.129 +
   1.130 +        return true;
   1.131 +    }
   1.132 +
   1.133 +private:
   1.134 +    detail::condition_impl m_impl;
   1.135 +
   1.136 +    template <typename M>
   1.137 +    void do_wait(M& mutex)
   1.138 +    {
   1.139 +#if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
   1.140 +        m_impl.enter_wait();
   1.141 +#endif
   1.142 +
   1.143 +        typedef detail::thread::lock_ops<M>
   1.144 +#if defined(__HP_aCC) && __HP_aCC <= 33900 && !defined(BOOST_STRICT_CONFIG)
   1.145 +# define lock_ops lock_ops_  // HP confuses lock_ops witht the template
   1.146 +#endif
   1.147 +            lock_ops;
   1.148 +
   1.149 +        typename lock_ops::lock_state state;
   1.150 +        lock_ops::unlock(mutex, state);
   1.151 +
   1.152 +#if defined(BOOST_HAS_PTHREADS)
   1.153 +        m_impl.do_wait(state.pmutex);
   1.154 +#elif (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
   1.155 +        m_impl.do_wait();
   1.156 +#endif
   1.157 +
   1.158 +        lock_ops::lock(mutex, state);
   1.159 +#undef lock_ops
   1.160 +    }
   1.161 +
   1.162 +    template <typename M>
   1.163 +    bool do_timed_wait(M& mutex, const xtime& xt)
   1.164 +    {
   1.165 +#if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
   1.166 +        m_impl.enter_wait();
   1.167 +#endif
   1.168 +
   1.169 +        typedef detail::thread::lock_ops<M>
   1.170 +#if defined(__HP_aCC) && __HP_aCC <= 33900 && !defined(BOOST_STRICT_CONFIG)
   1.171 +# define lock_ops lock_ops_  // HP confuses lock_ops witht the template
   1.172 +#endif
   1.173 +            lock_ops;
   1.174 +
   1.175 +        typename lock_ops::lock_state state;
   1.176 +        lock_ops::unlock(mutex, state);
   1.177 +
   1.178 +        bool ret = false;
   1.179 +
   1.180 +#if defined(BOOST_HAS_PTHREADS)
   1.181 +        ret = m_impl.do_timed_wait(xt, state.pmutex);
   1.182 +#elif (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
   1.183 +        ret = m_impl.do_timed_wait(xt);
   1.184 +#endif
   1.185 +
   1.186 +        lock_ops::lock(mutex, state);
   1.187 +#undef lock_ops
   1.188 +
   1.189 +        return ret;
   1.190 +    }
   1.191 +};
   1.192 +#ifdef BOOST_MSVC
   1.193 +#   pragma warning(pop)
   1.194 +#endif
   1.195 +} // namespace boost
   1.196 +
   1.197 +// Change Log:
   1.198 +//    8 Feb 01  WEKEMPF Initial version.
   1.199 +//   22 May 01  WEKEMPF Modified to use xtime for time outs.
   1.200 +//   23 May 01  WEKEMPF Removed "duration" timed_waits, as they are too
   1.201 +//                      difficult to use with spurious wakeups.
   1.202 +//    3 Jan 03  WEKEMPF Modified for DLL implementation.
   1.203 +
   1.204 +#endif // BOOST_CONDITION_WEK070601_HPP