mirror of
https://github.com/boostorg/fiber.git
synced 2026-02-02 20:52:21 +00:00
43 lines
1.2 KiB
C++
43 lines
1.2 KiB
C++
|
|
// Copyright Eugene Yakubovich 2014.
|
|
// Distributed under the Boost Software License, Version 1.0.
|
|
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
// http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
#include <boost/asio.hpp>
|
|
#include <boost/asio/system_timer.hpp>
|
|
#include <boost/bind.hpp>
|
|
#include <boost/chrono/system_clocks.hpp>
|
|
#include <boost/config.hpp>
|
|
#include <boost/ref.hpp>
|
|
|
|
#include <boost/fiber/detail/config.hpp>
|
|
#include <boost/fiber/detail/scheduler.hpp>
|
|
|
|
#ifdef BOOST_HAS_ABI_HEADERS
|
|
# include BOOST_ABI_PREFIX
|
|
#endif
|
|
|
|
namespace boost {
|
|
namespace fibers {
|
|
namespace asio {
|
|
|
|
inline void timer_handler( boost::asio::system_timer & timer) {
|
|
boost::fibers::detail::scheduler::instance()->yield();
|
|
timer.expires_at(
|
|
boost::fibers::detail::scheduler::instance()->next_wakeup() );
|
|
timer.async_wait( boost::bind( timer_handler, boost::ref( timer) ) );
|
|
}
|
|
|
|
inline void run_service( boost::asio::io_service & io_service) {
|
|
boost::asio::system_timer timer( io_service, boost::chrono::seconds(0) );
|
|
timer.async_wait( boost::bind( timer_handler, boost::ref( timer) ) );
|
|
io_service.run();
|
|
}
|
|
|
|
}}}
|
|
|
|
#ifdef BOOST_HAS_ABI_HEADERS
|
|
# include BOOST_ABI_SUFFIX
|
|
#endif
|