]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/fiber/src/condition_variable.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / fiber / src / condition_variable.cpp
CommitLineData
7c673cae
FG
1
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)
6
7#include "boost/fiber/condition_variable.hpp"
8
9#include "boost/fiber/context.hpp"
10
11#ifdef BOOST_HAS_ABI_HEADERS
12# include BOOST_ABI_PREFIX
13#endif
14
15namespace boost {
16namespace fibers {
17
18void
19condition_variable_any::notify_one() noexcept {
b32b8144 20 context * active_ctx = context::active();
7c673cae 21 // get one context' from wait-queue
b32b8144
FG
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) ) {
b32b8144
FG
28 // notify context
29 active_ctx->schedule( ctx);
30 break;
31 } else if ( static_cast< std::intptr_t >( 0) == expected) {
32 // no timed-wait op.
33 // notify context
34 active_ctx->schedule( ctx);
35 break;
b32b8144 36 }
7c673cae 37 }
7c673cae
FG
38}
39
40void
41condition_variable_any::notify_all() noexcept {
b32b8144 42 context * active_ctx = context::active();
7c673cae 43 // get all context' from wait-queue
b32b8144 44 detail::spinlock_lock lk{ wait_queue_splk_ };
7c673cae
FG
45 // notify all context'
46 while ( ! wait_queue_.empty() ) {
47 context * ctx = & wait_queue_.front();
48 wait_queue_.pop_front();
b32b8144
FG
49 std::intptr_t expected = reinterpret_cast< std::intptr_t >( this);
50 if ( ctx->twstatus.compare_exchange_strong( expected, static_cast< std::intptr_t >( -1), std::memory_order_acq_rel) ) {
b32b8144
FG
51 // notify context
52 active_ctx->schedule( ctx);
53 } else if ( static_cast< std::intptr_t >( 0) == expected) {
54 // no timed-wait op.
55 // notify context
56 active_ctx->schedule( ctx);
b32b8144 57 }
7c673cae
FG
58 }
59}
60
61}}
62
63#ifdef BOOST_HAS_ABI_HEADERS
64# include BOOST_ABI_SUFFIX
65#endif