Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::chain::platform_timer Struct Reference

#include <platform_timer.hpp>

Classes

struct  impl
 

Public Member Functions

 platform_timer ()
 
 ~platform_timer ()
 
void start (fc::time_point tp)
 
void stop ()
 
void set_expiration_callback (void(*func)(void *), void *user)
 

Public Attributes

std::atomic_bool expired = true
 

Detailed Description

Definition at line 14 of file platform_timer.hpp.

Constructor & Destructor Documentation

◆ platform_timer()

sysio::chain::platform_timer::platform_timer ( )

Definition at line 24 of file platform_timer_asio_fallback.cpp.

24 {
25 static_assert(sizeof(impl) <= fwd_size);
26
27 std::lock_guard guard(timer_ref_mutex);
28
29 if(refcount++ == 0) {
30 std::promise<void> p;
31 checktime_thread = std::thread([&p]() {
32 fc::set_os_thread_name("checktime");
33 checktime_ios = std::make_unique<boost::asio::io_service>();
34 boost::asio::io_service::work work(*checktime_ios);
35 p.set_value();
36
37 checktime_ios->run();
38 });
39 p.get_future().get();
40 }
41
42 my->timer = std::make_unique<boost::asio::high_resolution_timer>(*checktime_ios);
43
44 //compute_and_print_timer_accuracy(*this);
45}
const mie::Vuint & p
Definition bn.cpp:27
void set_os_thread_name(const string &name)
Here is the call graph for this function:

◆ ~platform_timer()

sysio::chain::platform_timer::~platform_timer ( )

Definition at line 47 of file platform_timer_asio_fallback.cpp.

47 {
48 stop();
49 if(std::lock_guard guard(timer_ref_mutex); --refcount == 0) {
50 checktime_ios->stop();
51 checktime_thread.join();
52 checktime_ios.reset();
53 }
54}
Here is the call graph for this function:

Member Function Documentation

◆ set_expiration_callback()

void sysio::chain::platform_timer::set_expiration_callback ( void(* func )(void *),
void * user )
inline

Definition at line 24 of file platform_timer.hpp.

24 {
25 bool expect_false = false;
26 while(!atomic_compare_exchange_strong(&_callback_variables_busy, &expect_false, true))
27 expect_false = false;
28 auto reset_busy = fc::make_scoped_exit([this]() {
29 _callback_variables_busy.store(false, std::memory_order_release);
30 });
31 SYS_ASSERT(!(func && _expiration_callback), misc_exception, "Setting a platform_timer callback when one already exists");
32
33 _expiration_callback = func;
34 _expiration_callback_data = user;
35 }
#define SYS_ASSERT(expr, exc_type, FORMAT,...)
Definition exceptions.hpp:7
scoped_exit< Callback > make_scoped_exit(Callback &&c)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ start()

void sysio::chain::platform_timer::start ( fc::time_point tp)

Definition at line 56 of file platform_timer_asio_fallback.cpp.

56 {
57 if(tp == fc::time_point::maximum()) {
58 expired = 0;
59 return;
60 }
62 if(x.count() <= 0)
63 expired = 1;
64 else {
65#if 0
66 std::promise<void> p;
67 checktime_ios->post([&p,this]() {
68 expired = 0;
69 p.set_value();
70 });
71 p.get_future().get();
72#endif
73 expired = 0;
74 my->timer->expires_after(std::chrono::microseconds(x.count()));
75 my->timer->async_wait([this](const boost::system::error_code& ec) {
76 if(ec)
77 return;
78 expired = 1;
79 call_expiration_callback();
80 });
81 }
82}
constexpr int64_t count() const
Definition time.hpp:26
static time_point now()
Definition time.cpp:14
constexpr const microseconds & time_since_epoch() const
Definition time.hpp:52
static constexpr time_point maximum()
Definition time.hpp:46
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop()

void sysio::chain::platform_timer::stop ( )

Definition at line 84 of file platform_timer_asio_fallback.cpp.

84 {
85 if(expired)
86 return;
87
88 my->timer->cancel();
89 expired = 1;
90}
Here is the caller graph for this function:

Member Data Documentation

◆ expired

std::atomic_bool sysio::chain::platform_timer::expired = true

Definition at line 37 of file platform_timer.hpp.


The documentation for this struct was generated from the following files: