]>
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 auto 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
) ) {
29 active_ctx
->schedule( ctx
);
32 if ( static_cast< std::intptr_t >( 0) == expected
) {
35 active_ctx
->schedule( ctx
);
42 condition_variable_any::notify_all() noexcept
{
43 context
* active_ctx
= context::active();
44 // get all context' from wait-queue
45 detail::spinlock_lock lk
{ wait_queue_splk_
};
46 // notify all context'
47 while ( ! wait_queue_
.empty() ) {
48 context
* ctx
= & wait_queue_
.front();
49 wait_queue_
.pop_front();
50 auto expected
= reinterpret_cast< std::intptr_t >( this);
51 if ( ctx
->twstatus
.compare_exchange_strong( expected
, static_cast< std::intptr_t >( -1), std::memory_order_acq_rel
) ) {
53 active_ctx
->schedule( ctx
);
54 } else if ( static_cast< std::intptr_t >( 0) == expected
) {
57 active_ctx
->schedule( ctx
);
64 #ifdef BOOST_HAS_ABI_HEADERS
65 # include BOOST_ABI_SUFFIX