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#include <boost/fiber/waker.hpp>
22
23#ifdef BOOST_HAS_ABI_HEADERS
24# include BOOST_ABI_PREFIX
25#endif
26
27#ifdef _MSC_VER
28# pragma warning(push)
29# pragma warning(disable:4251)
30#endif
31
32namespace boost {
33namespace fibers {
34
35class condition_variable;
36
37class BOOST_FIBERS_DECL recursive_mutex {
38private:
39 friend class condition_variable;
40
41 detail::spinlock wait_queue_splk_{};
42 wait_queue wait_queue_{};
43 context * owner_{ nullptr };
44 std::size_t count_{ 0 };
45
46public:
47 recursive_mutex() = default;
48
49 ~recursive_mutex() {
50 BOOST_ASSERT( nullptr == owner_);
51 BOOST_ASSERT( 0 == count_);
52 BOOST_ASSERT( wait_queue_.empty() );
53 }
54
55 recursive_mutex( recursive_mutex const&) = delete;
56 recursive_mutex & operator=( recursive_mutex const&) = delete;
57
58 void lock();
59
60 bool try_lock() noexcept;
61
62 void unlock();
63};
64
65}}
66
67#ifdef _MSC_VER
68# pragma warning(pop)
69#endif
70
71#ifdef BOOST_HAS_ABI_HEADERS
72# include BOOST_ABI_SUFFIX
73#endif
74
75#endif // BOOST_FIBERS_RECURSIVE_MUTEX_H
76

source code of boost/libs/fiber/include/boost/fiber/recursive_mutex.hpp