|
|
|
@ -10,22 +10,13 @@ timer::error::error(int err):e_err(err) { }
|
|
|
|
|
|
|
|
|
|
timer::interrupt_timer::interrupt_timer(struct timeval t,
|
|
|
|
|
sighandler_t_ sighandler=SIG_IGN) : new_handler(sighandler),
|
|
|
|
|
old_handler(NULL), armed(true) {
|
|
|
|
|
this->new_val = (struct itimerval){
|
|
|
|
|
{ 0, 0 },
|
|
|
|
|
t
|
|
|
|
|
};
|
|
|
|
|
this->old_val = (struct itimerval){
|
|
|
|
|
{ 0, 0 },
|
|
|
|
|
{ 0, 0 }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
old_handler(NULL), new_val((struct itimerval){{0,0},t}),
|
|
|
|
|
old_val(disable), armed(true) { }
|
|
|
|
|
|
|
|
|
|
int timer::interrupt_timer::arm_timer() {
|
|
|
|
|
// Disable the interval timer before resetting the handler and rearming
|
|
|
|
|
// the previous interval timer or else we will have a race-condition
|
|
|
|
|
// where the timer might fire and the appropriate handler might not be
|
|
|
|
|
// set.
|
|
|
|
|
// Disable the interval timer before setting the handler and arming the
|
|
|
|
|
// interval timer or else we will have a race-condition where the timer
|
|
|
|
|
// might fire and the appropriate handler might not be set.
|
|
|
|
|
if (setitimer(ITIMER_REAL, &disable, &this->old_val) != 0) {
|
|
|
|
|
log_error("Unable to disable the timer: %s",
|
|
|
|
|
strerror(errno));
|
|
|
|
@ -36,7 +27,8 @@ int timer::interrupt_timer::arm_timer() {
|
|
|
|
|
log_error("Unable to set the signal handler: %s",
|
|
|
|
|
strerror(errno));
|
|
|
|
|
if (setitimer(ITIMER_REAL, &this->old_val, NULL) != 0) {
|
|
|
|
|
log_error("Unable to reset the interrupt timer: %s", strerror(errno));
|
|
|
|
|
log_error("Unable to reset the interrupt timer: %s",
|
|
|
|
|
strerror(errno));
|
|
|
|
|
throw timer::error(errno);
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
@ -44,7 +36,8 @@ int timer::interrupt_timer::arm_timer() {
|
|
|
|
|
|
|
|
|
|
if (setitimer(ITIMER_REAL, &this->new_val, NULL) != 0) {
|
|
|
|
|
if(signal(SIGALRM, this->old_handler) == SIG_ERR) {
|
|
|
|
|
log_error("Unable to reset the signal handler: %s", strerror(errno));
|
|
|
|
|
log_error("Unable to reset the signal handler: %s",
|
|
|
|
|
strerror(errno));
|
|
|
|
|
throw timer::error(errno);
|
|
|
|
|
}
|
|
|
|
|
log_error("Unable to set the timer: %s", strerror(errno));
|
|
|
|
|