• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //          Copyright Oliver Kowalke 2013.
2 // Distributed under the Boost Software License, Version 1.0.
3 //    (See accompanying file LICENSE_1_0.txt or copy at
4 //          http://www.boost.org/LICENSE_1_0.txt)
5 
6 #ifndef BOOST_FIBERS_ALGO_ROUND_ROBIN_H
7 #define BOOST_FIBERS_ALGO_ROUND_ROBIN_H
8 
9 #include <condition_variable>
10 #include <chrono>
11 #include <mutex>
12 
13 #include <boost/config.hpp>
14 
15 #include <boost/fiber/algo/algorithm.hpp>
16 #include <boost/fiber/context.hpp>
17 #include <boost/fiber/detail/config.hpp>
18 #include <boost/fiber/scheduler.hpp>
19 
20 #ifdef BOOST_HAS_ABI_HEADERS
21 #  include BOOST_ABI_PREFIX
22 #endif
23 
24 #ifdef _MSC_VER
25 # pragma warning(push)
26 # pragma warning(disable:4251)
27 #endif
28 
29 namespace boost {
30 namespace fibers {
31 namespace algo {
32 
33 class BOOST_FIBERS_DECL round_robin : public algorithm {
34 private:
35     typedef scheduler::ready_queue_type rqueue_type;
36 
37     rqueue_type                 rqueue_{};
38     std::mutex                  mtx_{};
39     std::condition_variable     cnd_{};
40     bool                        flag_{ false };
41 
42 public:
43     round_robin() = default;
44 
45     round_robin( round_robin const&) = delete;
46     round_robin & operator=( round_robin const&) = delete;
47 
48     void awakened( context *) noexcept override;
49 
50     context * pick_next() noexcept override;
51 
52     bool has_ready_fibers() const noexcept override;
53 
54     void suspend_until( std::chrono::steady_clock::time_point const&) noexcept override;
55 
56     void notify() noexcept override;
57 };
58 
59 }}}
60 
61 #ifdef _MSC_VER
62 # pragma warning(pop)
63 #endif
64 
65 #ifdef BOOST_HAS_ABI_HEADERS
66 #  include BOOST_ABI_SUFFIX
67 #endif
68 
69 #endif // BOOST_FIBERS_ALGO_ROUND_ROBIN_H
70