1 2 // Copyright Oliver Kowalke 2013. 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt or copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 // 7 // based on boost::interprocess::sync::interprocess_spinlock 8 9 #ifndef BOOST_FIBERS_RECURSIVE_MUTEX_H 10 #define BOOST_FIBERS_RECURSIVE_MUTEX_H 11 12 #include <cstddef> 13 14 #include <boost/config.hpp> 15 16 #include <boost/assert.hpp> 17 18 #include <boost/fiber/context.hpp> 19 #include <boost/fiber/detail/config.hpp> 20 #include <boost/fiber/detail/spinlock.hpp> 21 22 #ifdef BOOST_HAS_ABI_HEADERS 23 # include BOOST_ABI_PREFIX 24 #endif 25 26 #ifdef _MSC_VER 27 # pragma warning(push) 28 # pragma warning(disable:4251) 29 #endif 30 31 namespace boost { 32 namespace fibers { 33 34 class condition_variable; 35 36 class BOOST_FIBERS_DECL recursive_mutex { 37 private: 38 friend class condition_variable; 39 40 using wait_queue_type = context::wait_queue_t; 41 42 detail::spinlock wait_queue_splk_{}; 43 wait_queue_type wait_queue_{}; 44 context * owner_{ nullptr }; 45 std::size_t count_{ 0 }; 46 47 public: 48 recursive_mutex() = default; 49 ~recursive_mutex()50 ~recursive_mutex() { 51 BOOST_ASSERT( nullptr == owner_); 52 BOOST_ASSERT( 0 == count_); 53 BOOST_ASSERT( wait_queue_.empty() ); 54 } 55 56 recursive_mutex( recursive_mutex const&) = delete; 57 recursive_mutex & operator=( recursive_mutex const&) = delete; 58 59 void lock(); 60 61 bool try_lock() noexcept; 62 63 void unlock(); 64 }; 65 66 }} 67 68 #ifdef _MSC_VER 69 # pragma warning(pop) 70 #endif 71 72 #ifdef BOOST_HAS_ABI_HEADERS 73 # include BOOST_ABI_SUFFIX 74 #endif 75 76 #endif // BOOST_FIBERS_RECURSIVE_MUTEX_H 77