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" };
33 } else if ( nullptr == owner_
) {
37 BOOST_ASSERT( ! active_ctx
->wait_is_linked() );
38 active_ctx
->wait_link( wait_queue_
);
40 active_ctx
->suspend( lk
);
41 BOOST_ASSERT( ! active_ctx
->wait_is_linked() );
47 context
* active_ctx
= context::active();
48 detail::spinlock_lock lk
{ wait_queue_splk_
};
49 if ( BOOST_UNLIKELY( active_ctx
== owner_
) ) {
51 std::make_error_code( std::errc::resource_deadlock_would_occur
),
52 "boost fiber: a deadlock is detected" };
53 } else if ( nullptr == owner_
) {
57 // let other fiber release the lock
59 return active_ctx
== owner_
;
64 context
* active_ctx
= context::active();
65 detail::spinlock_lock lk
{ wait_queue_splk_
};
66 if ( BOOST_UNLIKELY( active_ctx
!= owner_
) ) {
68 std::make_error_code( std::errc::operation_not_permitted
),
69 "boost fiber: no privilege to perform the operation" };
72 if ( ! wait_queue_
.empty() ) {
73 context
* ctx
= & wait_queue_
.front();
74 wait_queue_
.pop_front();
75 active_ctx
->schedule( ctx
);
81 #ifdef BOOST_HAS_ABI_HEADERS
82 # include BOOST_ABI_SUFFIX