]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fiber/src/algo/shared_work.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/algo/shared_work.hpp"
9 #include <boost/assert.hpp>
11 #include "boost/fiber/type.hpp"
13 #ifdef BOOST_HAS_ABI_HEADERS
14 # include BOOST_ABI_PREFIX
23 shared_work::awakened( context
* ctx
) noexcept
{
24 if ( ctx
->is_context( type::pinned_context
) ) { /*<
25 recognize when we're passed this thread's main fiber (or an
26 implicit library helper fiber): never put those on the shared
29 lqueue_
.push_back( * ctx
);
32 std::unique_lock
< std::mutex
> lk
{ rqueue_mtx_
}; /*<
33 worker fiber, enqueue on shared queue
35 rqueue_
.push_back( ctx
);
42 shared_work::pick_next() noexcept
{
43 context
* ctx
= nullptr;
44 std::unique_lock
< std::mutex
> lk
{ rqueue_mtx_
};
45 if ( ! rqueue_
.empty() ) { /*<
46 pop an item from the ready queue
48 ctx
= rqueue_
.front();
51 BOOST_ASSERT( nullptr != ctx
);
52 context::active()->attach( ctx
); /*<
53 attach context to current scheduler via the active fiber
58 if ( ! lqueue_
.empty() ) { /*<
59 nothing in the ready queue, return main or dispatcher fiber
61 ctx
= & lqueue_
.front();
70 shared_work::suspend_until( std::chrono::steady_clock::time_point
const& time_point
) noexcept
{
72 if ( (std::chrono::steady_clock::time_point::max
)() == time_point
) {
73 std::unique_lock
< std::mutex
> lk
{ mtx_
};
74 cnd_
.wait( lk
, [this](){ return flag_
; });
77 std::unique_lock
< std::mutex
> lk
{ mtx_
};
78 cnd_
.wait_until( lk
, time_point
, [this](){ return flag_
; });
85 shared_work::notify() noexcept
{
87 std::unique_lock
< std::mutex
> lk
{ mtx_
};
94 shared_work::rqueue_type
shared_work::rqueue_
{};
95 std::mutex
shared_work::rqueue_mtx_
{};
99 #ifdef BOOST_HAS_ABI_HEADERS
100 # include BOOST_ABI_SUFFIX