]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fiber/src/recursive_mutex.cpp
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)
7 #include "boost/fiber/recursive_mutex.hpp"
12 #include "boost/fiber/exceptions.hpp"
13 #include "boost/fiber/scheduler.hpp"
15 #ifdef BOOST_HAS_ABI_HEADERS
16 # include BOOST_ABI_PREFIX
23 recursive_mutex::lock() {
25 context
* active_ctx
= context::active();
26 // store this fiber in order to be notified later
27 detail::spinlock_lock lk
{ wait_queue_splk_
};
28 if ( active_ctx
== owner_
) {
31 } else if ( nullptr == owner_
) {
36 BOOST_ASSERT( ! active_ctx
->wait_is_linked() );
37 active_ctx
->wait_link( wait_queue_
);
39 active_ctx
->suspend( lk
);
40 BOOST_ASSERT( ! active_ctx
->wait_is_linked() );
45 recursive_mutex::try_lock() noexcept
{
46 context
* active_ctx
= context::active();
47 detail::spinlock_lock lk
{ wait_queue_splk_
};
48 if ( nullptr == owner_
) {
51 } else if ( active_ctx
== owner_
) {
55 // let other fiber release the lock
56 context::active()->yield();
57 return active_ctx
== owner_
;
61 recursive_mutex::unlock() {
62 context
* active_ctx
= context::active();
63 detail::spinlock_lock
lk( wait_queue_splk_
);
64 if ( BOOST_UNLIKELY( active_ctx
!= owner_
) ) {
66 std::make_error_code( std::errc::operation_not_permitted
),
67 "boost fiber: no privilege to perform the operation");
71 if ( ! wait_queue_
.empty() ) {
72 context
* ctx
= & wait_queue_
.front();
73 wait_queue_
.pop_front();
74 active_ctx
->schedule( ctx
);
81 #ifdef BOOST_HAS_ABI_HEADERS
82 # include BOOST_ABI_SUFFIX