1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/thread/recursive_mutex.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,184 @@
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_RECURSIVE_MUTEX_WEK070601_HPP
1.11 +#define BOOST_RECURSIVE_MUTEX_WEK070601_HPP
1.12 +
1.13 +#include <boost/thread/detail/config.hpp>
1.14 +
1.15 +#include <boost/utility.hpp>
1.16 +#include <boost/thread/detail/lock.hpp>
1.17 +
1.18 +#if defined(BOOST_HAS_PTHREADS)
1.19 +# include <pthread.h>
1.20 +#endif
1.21 +
1.22 +#if defined(BOOST_HAS_MPTASKS)
1.23 +# include "scoped_critical_region.hpp"
1.24 +#endif
1.25 +
1.26 +namespace boost {
1.27 +
1.28 +struct xtime;
1.29 +// disable warnings about non dll import
1.30 +// see: http://www.boost.org/more/separate_compilation.html#dlls
1.31 +#ifdef BOOST_MSVC
1.32 +# pragma warning(push)
1.33 +# pragma warning(disable: 4251 4231 4660 4275)
1.34 +#endif
1.35 +class BOOST_THREAD_DECL recursive_mutex
1.36 + : private noncopyable
1.37 +{
1.38 +public:
1.39 + friend class detail::thread::lock_ops<recursive_mutex>;
1.40 +
1.41 + typedef detail::thread::scoped_lock<recursive_mutex> scoped_lock;
1.42 +
1.43 + recursive_mutex();
1.44 + ~recursive_mutex();
1.45 +
1.46 +private:
1.47 +#if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
1.48 + typedef std::size_t cv_state;
1.49 +#elif defined(BOOST_HAS_PTHREADS)
1.50 + struct cv_state
1.51 + {
1.52 + long count;
1.53 + pthread_mutex_t* pmutex;
1.54 + };
1.55 +#endif
1.56 + void do_lock();
1.57 + void do_unlock();
1.58 + void do_lock(cv_state& state);
1.59 + void do_unlock(cv_state& state);
1.60 +
1.61 +#if defined(BOOST_HAS_WINTHREADS)
1.62 + void* m_mutex;
1.63 + bool m_critical_section;
1.64 + unsigned long m_count;
1.65 +#elif defined(BOOST_HAS_PTHREADS)
1.66 + pthread_mutex_t m_mutex;
1.67 + unsigned m_count;
1.68 +# if !defined(BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE)
1.69 + pthread_cond_t m_unlocked;
1.70 + pthread_t m_thread_id;
1.71 + bool m_valid_id;
1.72 +# endif
1.73 +#elif defined(BOOST_HAS_MPTASKS)
1.74 + threads::mac::detail::scoped_critical_region m_mutex;
1.75 + threads::mac::detail::scoped_critical_region m_mutex_mutex;
1.76 + std::size_t m_count;
1.77 +#endif
1.78 +};
1.79 +
1.80 +class BOOST_THREAD_DECL recursive_try_mutex
1.81 + : private noncopyable
1.82 +{
1.83 +public:
1.84 + friend class detail::thread::lock_ops<recursive_try_mutex>;
1.85 +
1.86 + typedef detail::thread::scoped_lock<recursive_try_mutex> scoped_lock;
1.87 + typedef detail::thread::scoped_try_lock<
1.88 + recursive_try_mutex> scoped_try_lock;
1.89 +
1.90 + recursive_try_mutex();
1.91 + ~recursive_try_mutex();
1.92 +
1.93 +private:
1.94 +#if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
1.95 + typedef std::size_t cv_state;
1.96 +#elif defined(BOOST_HAS_PTHREADS)
1.97 + struct cv_state
1.98 + {
1.99 + long count;
1.100 + pthread_mutex_t* pmutex;
1.101 + };
1.102 +#endif
1.103 + void do_lock();
1.104 + bool do_trylock();
1.105 + void do_unlock();
1.106 + void do_lock(cv_state& state);
1.107 + void do_unlock(cv_state& state);
1.108 +
1.109 +#if defined(BOOST_HAS_WINTHREADS)
1.110 + void* m_mutex;
1.111 + bool m_critical_section;
1.112 + unsigned long m_count;
1.113 +#elif defined(BOOST_HAS_PTHREADS)
1.114 + pthread_mutex_t m_mutex;
1.115 + unsigned m_count;
1.116 +# if !defined(BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE)
1.117 + pthread_cond_t m_unlocked;
1.118 + pthread_t m_thread_id;
1.119 + bool m_valid_id;
1.120 +# endif
1.121 +#elif defined(BOOST_HAS_MPTASKS)
1.122 + threads::mac::detail::scoped_critical_region m_mutex;
1.123 + threads::mac::detail::scoped_critical_region m_mutex_mutex;
1.124 + std::size_t m_count;
1.125 +#endif
1.126 +};
1.127 +
1.128 +class BOOST_THREAD_DECL recursive_timed_mutex
1.129 + : private noncopyable
1.130 +{
1.131 +public:
1.132 + friend class detail::thread::lock_ops<recursive_timed_mutex>;
1.133 +
1.134 + typedef detail::thread::scoped_lock<recursive_timed_mutex> scoped_lock;
1.135 + typedef detail::thread::scoped_try_lock<
1.136 + recursive_timed_mutex> scoped_try_lock;
1.137 + typedef detail::thread::scoped_timed_lock<
1.138 + recursive_timed_mutex> scoped_timed_lock;
1.139 +
1.140 + recursive_timed_mutex();
1.141 + ~recursive_timed_mutex();
1.142 +
1.143 +private:
1.144 +#if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS))
1.145 + typedef std::size_t cv_state;
1.146 +#elif defined(BOOST_HAS_PTHREADS)
1.147 + struct cv_state
1.148 + {
1.149 + long count;
1.150 + pthread_mutex_t* pmutex;
1.151 + };
1.152 +#endif
1.153 + void do_lock();
1.154 + bool do_trylock();
1.155 + bool do_timedlock(const xtime& xt);
1.156 + void do_unlock();
1.157 + void do_lock(cv_state& state);
1.158 + void do_unlock(cv_state& state);
1.159 +
1.160 +#if defined(BOOST_HAS_WINTHREADS)
1.161 + void* m_mutex;
1.162 + unsigned long m_count;
1.163 +#elif defined(BOOST_HAS_PTHREADS)
1.164 + pthread_mutex_t m_mutex;
1.165 + pthread_cond_t m_unlocked;
1.166 + pthread_t m_thread_id;
1.167 + bool m_valid_id;
1.168 + unsigned m_count;
1.169 +#elif defined(BOOST_HAS_MPTASKS)
1.170 + threads::mac::detail::scoped_critical_region m_mutex;
1.171 + threads::mac::detail::scoped_critical_region m_mutex_mutex;
1.172 + std::size_t m_count;
1.173 +#endif
1.174 +};
1.175 +#ifdef BOOST_MSVC
1.176 +# pragma warning(pop)
1.177 +#endif
1.178 +} // namespace boost
1.179 +
1.180 +#endif // BOOST_RECURSIVE_MUTEX_WEK070601_HPP
1.181 +
1.182 +// Change Log:
1.183 +// 8 Feb 01 WEKEMPF Initial version.
1.184 +// 1 Jun 01 WEKEMPF Modified to use xtime for time outs. Factored out
1.185 +// to three classes, mutex, try_mutex and timed_mutex.
1.186 +// 11 Jun 01 WEKEMPF Modified to use PTHREAD_MUTEX_RECURSIVE if available.
1.187 +// 3 Jan 03 WEKEMPF Modified for DLL implementation.