-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
don't start kernel level platform timer when applying blocks #1130
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,20 +88,23 @@ platform_timer::~platform_timer() { | |
} | ||
|
||
void platform_timer::start(fc::time_point tp) { | ||
assert(_state == state_t::stopped); | ||
if(tp == fc::time_point::maximum()) { | ||
expired = false; | ||
_state = state_t::running; | ||
timer_running_forever = true; | ||
return; | ||
} | ||
fc::microseconds x = tp.time_since_epoch() - fc::time_point::now().time_since_epoch(); | ||
timer_running_forever = false; | ||
if(x.count() <= 0) | ||
expired = true; | ||
_state = state_t::timed_out; | ||
else { | ||
struct kevent64_s aTimerEvent; | ||
EV_SET64(&aTimerEvent, my->timerid, EVFILT_TIMER, EV_ADD|EV_ENABLE|EV_ONESHOT, NOTE_USECONDS|NOTE_CRITICAL, x.count(), (uint64_t)this, 0, 0); | ||
|
||
expired = false; | ||
_state = state_t::running; | ||
if(kevent64(kqueue_fd, &aTimerEvent, 1, NULL, 0, KEVENT_FLAG_IMMEDIATE, NULL) != 0) | ||
expired = true; | ||
_state = state_t::timed_out; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this wasn't updated completely in #1107. We should really refactor the code a bit to move the common state logic out of the platform specific impls. |
||
} | ||
} | ||
|
||
|
@@ -120,7 +123,11 @@ void platform_timer::interrupt_timer() { | |
} | ||
|
||
void platform_timer::stop() { | ||
if(_state == state_t::stopped) | ||
const state_t prior_state = _state; | ||
if(prior_state == state_t::stopped) | ||
return; | ||
_state = state_t::stopped; | ||
if(prior_state == state_t::timed_out || timer_running_forever) | ||
return; | ||
|
||
struct kevent64_s stop_timer_event; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,9 +58,11 @@ void platform_timer::start(fc::time_point tp) { | |
assert(_state == state_t::stopped); | ||
if(tp == fc::time_point::maximum()) { | ||
_state = state_t::running; | ||
timer_running_forever = true; | ||
return; | ||
} | ||
fc::microseconds x = tp.time_since_epoch() - fc::time_point::now().time_since_epoch(); | ||
timer_running_forever = false; | ||
if(x.count() <= 0) | ||
_state = state_t::timed_out; | ||
else { | ||
|
@@ -88,11 +90,14 @@ void platform_timer::interrupt_timer() { | |
} | ||
|
||
void platform_timer::stop() { | ||
if(_state == state_t::stopped) | ||
const state_t prior_state = _state; | ||
if(prior_state == state_t::stopped) | ||
return; | ||
_state = state_t::stopped; | ||
if(prior_state == state_t::timed_out || timer_running_forever) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another minor tweak here is to not stop the timer if it has already expired. Obviously that's a rather rare scenario, but might as well be thorough while tweaking all this. |
||
return; | ||
struct itimerspec disable = {{0, 0}, {0, 0}}; | ||
timer_settime(my->timerid, 0, &disable, NULL); | ||
_state = state_t::stopped; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to change, just a remark. Personally I prefer initializing members once if possible, as in:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that does look good here