sl@0: // Copyright (C) 2001-2003 sl@0: // William E. Kempf sl@0: // sl@0: // Distributed under the Boost Software License, Version 1.0. (See accompanying sl@0: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) sl@0: sl@0: #ifndef BOOST_RECURSIVE_MUTEX_WEK070601_HPP sl@0: #define BOOST_RECURSIVE_MUTEX_WEK070601_HPP sl@0: sl@0: #include sl@0: sl@0: #include sl@0: #include sl@0: sl@0: #if defined(BOOST_HAS_PTHREADS) sl@0: # include sl@0: #endif sl@0: sl@0: #if defined(BOOST_HAS_MPTASKS) sl@0: # include "scoped_critical_region.hpp" sl@0: #endif sl@0: sl@0: namespace boost { sl@0: sl@0: struct xtime; sl@0: // disable warnings about non dll import sl@0: // see: http://www.boost.org/more/separate_compilation.html#dlls sl@0: #ifdef BOOST_MSVC sl@0: # pragma warning(push) sl@0: # pragma warning(disable: 4251 4231 4660 4275) sl@0: #endif sl@0: class BOOST_THREAD_DECL recursive_mutex sl@0: : private noncopyable sl@0: { sl@0: public: sl@0: friend class detail::thread::lock_ops; sl@0: sl@0: typedef detail::thread::scoped_lock scoped_lock; sl@0: sl@0: recursive_mutex(); sl@0: ~recursive_mutex(); sl@0: sl@0: private: sl@0: #if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS)) sl@0: typedef std::size_t cv_state; sl@0: #elif defined(BOOST_HAS_PTHREADS) sl@0: struct cv_state sl@0: { sl@0: long count; sl@0: pthread_mutex_t* pmutex; sl@0: }; sl@0: #endif sl@0: void do_lock(); sl@0: void do_unlock(); sl@0: void do_lock(cv_state& state); sl@0: void do_unlock(cv_state& state); sl@0: sl@0: #if defined(BOOST_HAS_WINTHREADS) sl@0: void* m_mutex; sl@0: bool m_critical_section; sl@0: unsigned long m_count; sl@0: #elif defined(BOOST_HAS_PTHREADS) sl@0: pthread_mutex_t m_mutex; sl@0: unsigned m_count; sl@0: # if !defined(BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE) sl@0: pthread_cond_t m_unlocked; sl@0: pthread_t m_thread_id; sl@0: bool m_valid_id; sl@0: # endif sl@0: #elif defined(BOOST_HAS_MPTASKS) sl@0: threads::mac::detail::scoped_critical_region m_mutex; sl@0: threads::mac::detail::scoped_critical_region m_mutex_mutex; sl@0: std::size_t m_count; sl@0: #endif sl@0: }; sl@0: sl@0: class BOOST_THREAD_DECL recursive_try_mutex sl@0: : private noncopyable sl@0: { sl@0: public: sl@0: friend class detail::thread::lock_ops; sl@0: sl@0: typedef detail::thread::scoped_lock scoped_lock; sl@0: typedef detail::thread::scoped_try_lock< sl@0: recursive_try_mutex> scoped_try_lock; sl@0: sl@0: recursive_try_mutex(); sl@0: ~recursive_try_mutex(); sl@0: sl@0: private: sl@0: #if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS)) sl@0: typedef std::size_t cv_state; sl@0: #elif defined(BOOST_HAS_PTHREADS) sl@0: struct cv_state sl@0: { sl@0: long count; sl@0: pthread_mutex_t* pmutex; sl@0: }; sl@0: #endif sl@0: void do_lock(); sl@0: bool do_trylock(); sl@0: void do_unlock(); sl@0: void do_lock(cv_state& state); sl@0: void do_unlock(cv_state& state); sl@0: sl@0: #if defined(BOOST_HAS_WINTHREADS) sl@0: void* m_mutex; sl@0: bool m_critical_section; sl@0: unsigned long m_count; sl@0: #elif defined(BOOST_HAS_PTHREADS) sl@0: pthread_mutex_t m_mutex; sl@0: unsigned m_count; sl@0: # if !defined(BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE) sl@0: pthread_cond_t m_unlocked; sl@0: pthread_t m_thread_id; sl@0: bool m_valid_id; sl@0: # endif sl@0: #elif defined(BOOST_HAS_MPTASKS) sl@0: threads::mac::detail::scoped_critical_region m_mutex; sl@0: threads::mac::detail::scoped_critical_region m_mutex_mutex; sl@0: std::size_t m_count; sl@0: #endif sl@0: }; sl@0: sl@0: class BOOST_THREAD_DECL recursive_timed_mutex sl@0: : private noncopyable sl@0: { sl@0: public: sl@0: friend class detail::thread::lock_ops; sl@0: sl@0: typedef detail::thread::scoped_lock scoped_lock; sl@0: typedef detail::thread::scoped_try_lock< sl@0: recursive_timed_mutex> scoped_try_lock; sl@0: typedef detail::thread::scoped_timed_lock< sl@0: recursive_timed_mutex> scoped_timed_lock; sl@0: sl@0: recursive_timed_mutex(); sl@0: ~recursive_timed_mutex(); sl@0: sl@0: private: sl@0: #if (defined(BOOST_HAS_WINTHREADS) || defined(BOOST_HAS_MPTASKS)) sl@0: typedef std::size_t cv_state; sl@0: #elif defined(BOOST_HAS_PTHREADS) sl@0: struct cv_state sl@0: { sl@0: long count; sl@0: pthread_mutex_t* pmutex; sl@0: }; sl@0: #endif sl@0: void do_lock(); sl@0: bool do_trylock(); sl@0: bool do_timedlock(const xtime& xt); sl@0: void do_unlock(); sl@0: void do_lock(cv_state& state); sl@0: void do_unlock(cv_state& state); sl@0: sl@0: #if defined(BOOST_HAS_WINTHREADS) sl@0: void* m_mutex; sl@0: unsigned long m_count; sl@0: #elif defined(BOOST_HAS_PTHREADS) sl@0: pthread_mutex_t m_mutex; sl@0: pthread_cond_t m_unlocked; sl@0: pthread_t m_thread_id; sl@0: bool m_valid_id; sl@0: unsigned m_count; sl@0: #elif defined(BOOST_HAS_MPTASKS) sl@0: threads::mac::detail::scoped_critical_region m_mutex; sl@0: threads::mac::detail::scoped_critical_region m_mutex_mutex; sl@0: std::size_t m_count; sl@0: #endif sl@0: }; sl@0: #ifdef BOOST_MSVC sl@0: # pragma warning(pop) sl@0: #endif sl@0: } // namespace boost sl@0: sl@0: #endif // BOOST_RECURSIVE_MUTEX_WEK070601_HPP sl@0: sl@0: // Change Log: sl@0: // 8 Feb 01 WEKEMPF Initial version. sl@0: // 1 Jun 01 WEKEMPF Modified to use xtime for time outs. Factored out sl@0: // to three classes, mutex, try_mutex and timed_mutex. sl@0: // 11 Jun 01 WEKEMPF Modified to use PTHREAD_MUTEX_RECURSIVE if available. sl@0: // 3 Jan 03 WEKEMPF Modified for DLL implementation.