6#ifndef BOOST_FIBERS_ASIO_ROUND_ROBIN_H
7#define BOOST_FIBERS_ASIO_ROUND_ROBIN_H
14#include <boost/asio.hpp>
15#include <boost/assert.hpp>
16#include <boost/asio/steady_timer.hpp>
17#include <boost/config.hpp>
19#include <boost/fiber/condition_variable.hpp>
20#include <boost/fiber/context.hpp>
21#include <boost/fiber/mutex.hpp>
22#include <boost/fiber/operations.hpp>
23#include <boost/fiber/scheduler.hpp>
27#ifdef BOOST_HAS_ABI_HEADERS
28# include BOOST_ABI_PREFIX
37 typedef scheduler::ready_queue_t rqueue_t;
40 boost::asio::io_service & io_svc_;
41 boost::asio::steady_timer suspend_timer_;
47 struct service :
public boost::asio::io_service::service {
48 static boost::asio::io_service::id
id;
50 std::unique_ptr< boost::asio::io_service::work >
work_;
52 service( boost::asio::io_service & io_svc) :
55 io_svc.post([&io_svc](){
58 while ( ! io_svc.stopped() ) {
59 if ( boost::fibers::has_ready_fibers() ) {
61 while ( io_svc.poll() );
67 if ( ! io_svc.run_one() ) {
91 suspend_timer_( io_svc_) {
95 boost::asio::add_service( io_svc_,
new service( io_svc_));
100 BOOST_ASSERT(
nullptr != ctx);
101 ctx->ready_link( rqueue_);
106 if ( ! rqueue_.empty() ) {
109 ctx = & rqueue_.front();
111 BOOST_ASSERT(
nullptr != ctx);
112 BOOST_ASSERT( context::active() != ctx);
118 return ! rqueue_.empty();
122 void suspend_until( std::chrono::steady_clock::time_point
const& abs_time)
noexcept {
127 if ( suspend_timer_.expires_at() != abs_time) {
145 suspend_timer_.expires_at( abs_time);
150 suspend_timer_.async_wait([](boost::system::error_code
const&){});
172 suspend_timer_.expires_at( std::chrono::steady_clock::now() );
181#ifdef BOOST_HAS_ABI_HEADERS
182# include BOOST_ABI_SUFFIX
context * pick_next() noexcept
bool has_ready_fibers() const noexcept
void suspend_until(std::chrono::steady_clock::time_point const &abs_time) noexcept
round_robin(boost::asio::io_service &io_svc)
void awakened(context *ctx) noexcept
service(boost::asio::io_service &io_svc)
void shutdown_service() override final
static boost::asio::io_service::id id
service & operator=(service const &)=delete
std::unique_ptr< boost::asio::io_service::work > work_
service(service const &)=delete