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/mutex.hpp"
11 #include <system_error>
13 #include "boost/fiber/exceptions.hpp"
14 #include "boost/fiber/scheduler.hpp"
16 #ifdef BOOST_HAS_ABI_HEADERS
17 # include BOOST_ABI_PREFIX
26 context
* active_ctx
= context::active();
27 // store this fiber in order to be notified later
28 detail::spinlock_lock lk
{ wait_queue_splk_
};
29 if ( BOOST_UNLIKELY( active_ctx
== owner_
) ) {
31 std::make_error_code( std::errc::resource_deadlock_would_occur
),
32 "boost fiber: a deadlock is detected" };
34 if ( nullptr == owner_
) {
38 BOOST_ASSERT( ! active_ctx
->wait_is_linked() );
39 active_ctx
->wait_link( wait_queue_
);
41 active_ctx
->suspend( lk
);
42 BOOST_ASSERT( ! active_ctx
->wait_is_linked() );
48 context
* active_ctx
= context::active();
49 detail::spinlock_lock lk
{ wait_queue_splk_
};
50 if ( BOOST_UNLIKELY( active_ctx
== owner_
) ) {
52 std::make_error_code( std::errc::resource_deadlock_would_occur
),
53 "boost fiber: a deadlock is detected" };
55 if ( nullptr == owner_
) {
59 // let other fiber release the lock
61 return active_ctx
== owner_
;
66 context
* active_ctx
= context::active();
67 detail::spinlock_lock lk
{ wait_queue_splk_
};
68 if ( BOOST_UNLIKELY( active_ctx
!= owner_
) ) {
70 std::make_error_code( std::errc::operation_not_permitted
),
71 "boost fiber: no privilege to perform the operation" };
74 if ( ! wait_queue_
.empty() ) {
75 context
* ctx
= & wait_queue_
.front();
76 wait_queue_
.pop_front();
77 active_ctx
->schedule( ctx
);
83 #ifdef BOOST_HAS_ABI_HEADERS
84 # include BOOST_ABI_SUFFIX