7#include <boost/asio.hpp>
12namespace sysio {
namespace chain {
15static std::mutex timer_ref_mutex;
16static unsigned refcount;
17static std::thread checktime_thread;
18static std::unique_ptr<boost::asio::io_service> checktime_ios;
20struct platform_timer::impl {
21 std::unique_ptr<boost::asio::high_resolution_timer>
timer;
25 static_assert(
sizeof(
impl) <= fwd_size);
27 std::lock_guard guard(timer_ref_mutex);
31 checktime_thread = std::thread([&
p]() {
33 checktime_ios = std::make_unique<boost::asio::io_service>();
34 boost::asio::io_service::work work(*checktime_ios);
42 my->timer = std::make_unique<boost::asio::high_resolution_timer>(*checktime_ios);
49 if(std::lock_guard guard(timer_ref_mutex); --refcount == 0) {
50 checktime_ios->stop();
51 checktime_thread.join();
52 checktime_ios.reset();
67 checktime_ios->post([&
p,
this]() {
74 my->timer->expires_after(std::chrono::microseconds(x.
count()));
75 my->timer->async_wait([
this](
const boost::system::error_code& ec) {
79 call_expiration_callback();
constexpr int64_t count() const
constexpr const microseconds & time_since_epoch() const
static constexpr time_point maximum()
void set_os_thread_name(const string &name)