round_robin.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #ifndef BOOST_FIBERS_ALGO_ROUND_ROBIN_H
  6. #define BOOST_FIBERS_ALGO_ROUND_ROBIN_H
  7. #include <condition_variable>
  8. #include <chrono>
  9. #include <mutex>
  10. #include <boost/config.hpp>
  11. #include <boost/fiber/algo/algorithm.hpp>
  12. #include <boost/fiber/context.hpp>
  13. #include <boost/fiber/detail/config.hpp>
  14. #include <boost/fiber/scheduler.hpp>
  15. #ifdef BOOST_HAS_ABI_HEADERS
  16. # include BOOST_ABI_PREFIX
  17. #endif
  18. #ifdef _MSC_VER
  19. # pragma warning(push)
  20. # pragma warning(disable:4251)
  21. #endif
  22. namespace boost {
  23. namespace fibers {
  24. namespace algo {
  25. class BOOST_FIBERS_DECL round_robin : public algorithm {
  26. private:
  27. typedef scheduler::ready_queue_type rqueue_type;
  28. rqueue_type rqueue_{};
  29. std::mutex mtx_{};
  30. std::condition_variable cnd_{};
  31. bool flag_{ false };
  32. public:
  33. round_robin() = default;
  34. round_robin( round_robin const&) = delete;
  35. round_robin & operator=( round_robin const&) = delete;
  36. void awakened( context *) noexcept override;
  37. context * pick_next() noexcept override;
  38. bool has_ready_fibers() const noexcept override;
  39. void suspend_until( std::chrono::steady_clock::time_point const&) noexcept override;
  40. void notify() noexcept override;
  41. };
  42. }}}
  43. #ifdef _MSC_VER
  44. # pragma warning(pop)
  45. #endif
  46. #ifdef BOOST_HAS_ABI_HEADERS
  47. # include BOOST_ABI_SUFFIX
  48. #endif
  49. #endif // BOOST_FIBERS_ALGO_ROUND_ROBIN_H