Skip to content

Commit 1a50b7b

Browse files
committed
GH-1095 Update to use the new _state like platform_timer_posix
1 parent 8ad83f2 commit 1a50b7b

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

libraries/chain/platform_timer_asio_fallback.cpp

+16-9
Original file line numberDiff line numberDiff line change
@@ -57,36 +57,43 @@ platform_timer::~platform_timer() {
5757

5858
void platform_timer::start(fc::time_point tp) {
5959
if(tp == fc::time_point::maximum()) {
60-
expired = false;
60+
_state = state_t::running;
6161
return;
6262
}
6363
fc::microseconds x = tp.time_since_epoch() - fc::time_point::now().time_since_epoch();
6464
if(x.count() <= 0)
65-
expired = true;
65+
_state = state_t::timed_out;
6666
else {
67-
expired = false;
67+
_state = state_t::running;
6868
my->timer->expires_after(std::chrono::microseconds(x.count()));
6969
my->timer->async_wait([this](const boost::system::error_code& ec) {
7070
if(ec)
7171
return;
72-
expire_now();
72+
_expire_now();
7373
});
7474
}
7575
}
7676

77-
void platform_timer::expire_now() {
78-
bool expected = false;
79-
if (expired.compare_exchange_strong(expected, true)) {
77+
void platform_timer::_expire_now() {
78+
state_t expected = state_t::running;
79+
if (_state.compare_exchange_strong(expected, state_t::timed_out)) {
80+
call_expiration_callback();
81+
}
82+
}
83+
84+
void platform_timer::interrupt_timer() {
85+
state_t expected = state_t::running;
86+
if (_state.compare_exchange_strong(expected, state_t::interrupted)) {
8087
call_expiration_callback();
8188
}
8289
}
8390

8491
void platform_timer::stop() {
85-
if(expired)
92+
if(_state == state_t::stopped)
8693
return;
8794

8895
my->timer->cancel();
89-
expired = true;
96+
_state = state_t::stopped;
9097
}
9198

9299
}}

libraries/chain/platform_timer_kqueue.cpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ platform_timer::platform_timer() {
5858

5959
if(c == 1 && anEvent.filter == EVFILT_TIMER) {
6060
platform_timer* self = (platform_timer*)anEvent.udata;
61-
self->expire_now();
61+
self->_expire_now();
6262
}
6363
else if(c == 1 && anEvent.filter == EVFILT_USER)
6464
return;
@@ -105,21 +105,28 @@ void platform_timer::start(fc::time_point tp) {
105105
}
106106
}
107107

108-
void platform_timer::expire_now() {
109-
bool expected = false;
110-
if (expired.compare_exchange_strong(expected, true)) {
108+
void platform_timer::_expire_now() {
109+
state_t expected = state_t::running;
110+
if (_state.compare_exchange_strong(expected, state_t::timed_out)) {
111+
call_expiration_callback();
112+
}
113+
}
114+
115+
void platform_timer::interrupt_timer() {
116+
state_t expected = state_t::running;
117+
if (_state.compare_exchange_strong(expected, state_t::interrupted)) {
111118
call_expiration_callback();
112119
}
113120
}
114121

115122
void platform_timer::stop() {
116-
if(expired)
123+
if(_state == state_t::stopped)
117124
return;
118125

119126
struct kevent64_s stop_timer_event;
120127
EV_SET64(&stop_timer_event, my->timerid, EVFILT_TIMER, EV_DELETE, 0, 0, 0, 0, 0);
121128
kevent64(kqueue_fd, &stop_timer_event, 1, NULL, 0, KEVENT_FLAG_IMMEDIATE, NULL);
122-
expired = true;
129+
_state = state_t::stopped;
123130
}
124131

125132
}}

0 commit comments

Comments
 (0)