]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/fiber/algo/shared_work.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / fiber / algo / shared_work.hpp
CommitLineData
7c673cae
FG
1
2// Copyright Nat Goodspeed + Oliver Kowalke 2015.
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#ifndef BOOST_FIBERS_ALGO_SHARED_WORK_H
8#define BOOST_FIBERS_ALGO_SHARED_WORK_H
9
10#include <condition_variable>
11#include <chrono>
12#include <deque>
13#include <mutex>
14
15#include <boost/config.hpp>
16
17#include <boost/fiber/algo/algorithm.hpp>
18#include <boost/fiber/context.hpp>
19#include <boost/fiber/detail/config.hpp>
20#include <boost/fiber/scheduler.hpp>
21
22#ifdef BOOST_HAS_ABI_HEADERS
23# include BOOST_ABI_PREFIX
24#endif
25
26#ifdef _MSC_VER
27# pragma warning(push)
28# pragma warning(disable:4251)
29#endif
30
31namespace boost {
32namespace fibers {
33namespace algo {
34
35class BOOST_FIBERS_DECL shared_work : public algorithm {
36private:
b32b8144
FG
37 typedef std::deque< context * > rqueue_type;
38 typedef scheduler::ready_queue_type lqueue_type;
7c673cae 39
b32b8144 40 static rqueue_type rqueue_;
7c673cae
FG
41 static std::mutex rqueue_mtx_;
42
b32b8144 43 lqueue_type lqueue_{};
7c673cae
FG
44 std::mutex mtx_{};
45 std::condition_variable cnd_{};
46 bool flag_{ false };
b32b8144 47 bool suspend_{ false };
7c673cae
FG
48
49public:
50 shared_work() = default;
51
52 shared_work( bool suspend) :
53 suspend_{ suspend } {
54 }
55
56 shared_work( shared_work const&) = delete;
57 shared_work( shared_work &&) = delete;
58
59 shared_work & operator=( shared_work const&) = delete;
60 shared_work & operator=( shared_work &&) = delete;
61
62 void awakened( context * ctx) noexcept;
63
64 context * pick_next() noexcept;
65
66 bool has_ready_fibers() const noexcept {
b32b8144 67 std::unique_lock< std::mutex > lock{ rqueue_mtx_ };
7c673cae
FG
68 return ! rqueue_.empty() || ! lqueue_.empty();
69 }
70
71 void suspend_until( std::chrono::steady_clock::time_point const& time_point) noexcept;
72
73 void notify() noexcept;
74};
75
76}}}
77
78#ifdef _MSC_VER
79# pragma warning(pop)
80#endif
81
82#ifdef BOOST_HAS_ABI_HEADERS
83# include BOOST_ABI_SUFFIX
84#endif
85
86#endif // BOOST_FIBERS_ALGO_SHARED_WORK_H