14namespace sysio {
namespace chain {
17static std::mutex timer_ref_mutex;
18static unsigned next_timerid;
19static unsigned refcount;
21static std::thread kevent_thread;
23struct platform_timer::impl {
30 static_assert(
sizeof(
impl) <= fwd_size);
32 std::lock_guard guard(timer_ref_mutex);
37 FC_ASSERT(kqueue_fd != -1,
"failed to create kqueue");
40 struct kevent64_s quit_event;
41 EV_SET64(&quit_event,
impl::quit_event_id, EVFILT_USER, EV_ADD|EV_ENABLE, NOTE_FFNOP, 0, 0, 0, 0);
42 FC_ASSERT(kevent64(kqueue_fd, &quit_event, 1, NULL, 0, KEVENT_FLAG_IMMEDIATE, NULL) == 0,
"failed to create quit event");
44 kevent_thread = std::thread([]() {
47 struct kevent64_s anEvent;
48 int c = kevent64(kqueue_fd, NULL, 0, &anEvent, 1, 0, NULL);
50 if(c == 1 && anEvent.filter == EVFILT_TIMER) {
53 self->call_expiration_callback();
55 else if(c == 1 && anEvent.filter == EVFILT_USER)
57 else if(c == -1 && errno == EINTR)
65 my->timerid = next_timerid++;
72 if(std::lock_guard guard(timer_ref_mutex); --refcount == 0) {
73 struct kevent64_s signal_quit_event;
74 EV_SET64(&signal_quit_event,
impl::quit_event_id, EVFILT_USER, 0, NOTE_TRIGGER, 0, 0, 0, 0);
76 if(kevent64(kqueue_fd, &signal_quit_event, 1, NULL, 0, KEVENT_FLAG_IMMEDIATE, NULL) != -1)
91 struct kevent64_s aTimerEvent;
92 EV_SET64(&aTimerEvent, my->timerid, EVFILT_TIMER, EV_ADD|EV_ENABLE|EV_ONESHOT, NOTE_USECONDS|NOTE_CRITICAL, x.
count(), (
uint64_t)
this, 0, 0);
95 if(kevent64(kqueue_fd, &aTimerEvent, 1, NULL, 0, KEVENT_FLAG_IMMEDIATE, NULL) != 0)
104 struct kevent64_s stop_timer_event;
105 EV_SET64(&stop_timer_event, my->timerid, EVFILT_TIMER, EV_DELETE, 0, 0, 0, 0, 0);
106 kevent64(kqueue_fd, &stop_timer_event, 1, NULL, 0, KEVENT_FLAG_IMMEDIATE, NULL);
constexpr int64_t count() const
constexpr const microseconds & time_since_epoch() const
static constexpr time_point maximum()
Defines exception's used by fc.
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
void close(T *e, websocketpp::connection_hdl hdl)
void set_os_thread_name(const string &name)
void compute_and_print_timer_accuracy(platform_timer &t)
@ self
the connection is to itself
unsigned __int64 uint64_t