]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fiber/src/condition_variable.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/condition_variable.hpp"
9 #include "boost/fiber/context.hpp"
11 #ifdef BOOST_HAS_ABI_HEADERS
12 # include BOOST_ABI_PREFIX
19 condition_variable_any::notify_one() noexcept
{
20 context
* active_ctx
= context::active();
21 // get one context' from wait-queue
22 detail::spinlock_lock lk
{ wait_queue_splk_
};
23 while ( ! wait_queue_
.empty() ) {
24 context
* ctx
= & wait_queue_
.front();
25 wait_queue_
.pop_front();
26 std::intptr_t expected
= reinterpret_cast< std::intptr_t >( this);
27 if ( ctx
->twstatus
.compare_exchange_strong( expected
, static_cast< std::intptr_t >( -1), std::memory_order_acq_rel
) ) {
28 // notify before timeout
29 intrusive_ptr_release( ctx
);
31 active_ctx
->schedule( ctx
);
33 } else if ( static_cast< std::intptr_t >( 0) == expected
) {
36 active_ctx
->schedule( ctx
);
40 // expected == -1: notify after timeout, same timed-wait op.
41 // expected == <any>: notify after timeout, another timed-wait op. was already started
42 intrusive_ptr_release( ctx
);
49 condition_variable_any::notify_all() noexcept
{
50 context
* active_ctx
= context::active();
51 // get all context' from wait-queue
52 detail::spinlock_lock lk
{ wait_queue_splk_
};
53 // notify all context'
54 while ( ! wait_queue_
.empty() ) {
55 context
* ctx
= & wait_queue_
.front();
56 wait_queue_
.pop_front();
57 std::intptr_t expected
= reinterpret_cast< std::intptr_t >( this);
58 if ( ctx
->twstatus
.compare_exchange_strong( expected
, static_cast< std::intptr_t >( -1), std::memory_order_acq_rel
) ) {
59 // notify before timeout
60 intrusive_ptr_release( ctx
);
62 active_ctx
->schedule( ctx
);
63 } else if ( static_cast< std::intptr_t >( 0) == expected
) {
66 active_ctx
->schedule( ctx
);
69 // expected == -1: notify after timeout, same timed-wait op.
70 // expected == <any>: notify after timeout, another timed-wait op. was already started
71 intrusive_ptr_release( ctx
);
79 #ifdef BOOST_HAS_ABI_HEADERS
80 # include BOOST_ABI_SUFFIX