idk, it's a bit nicer
This commit is contained in:
parent
01fd188d7e
commit
eeeb5659a9
1 changed files with 7 additions and 14 deletions
|
@ -31,11 +31,11 @@ static inline int _set_interval(hexagram_schedule *schedule,
|
||||||
return timer_settime(schedule->timer, 0, &schedule->ts, NULL);
|
return timer_settime(schedule->timer, 0, &schedule->ts, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int _set_slot_interval(hexagram_schedule *schedule, size_t i) {
|
static inline int _slot_set_interval(hexagram_schedule *schedule, size_t i) {
|
||||||
return _set_interval(schedule, _slot_interval_ns(schedule, i));
|
return _set_interval(schedule, _slot_interval_ns(schedule, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _schedule_notify(hexagram_schedule *schedule) {
|
static void _ev_notify(hexagram_schedule *schedule) {
|
||||||
time_t last = -1;
|
time_t last = -1;
|
||||||
|
|
||||||
while (schedule->current < schedule->count) {
|
while (schedule->current < schedule->count) {
|
||||||
|
@ -51,7 +51,7 @@ static void _schedule_notify(hexagram_schedule *schedule) {
|
||||||
schedule->current++;
|
schedule->current++;
|
||||||
|
|
||||||
if (last >= 0 && last != delay) {
|
if (last >= 0 && last != delay) {
|
||||||
_set_slot_interval(schedule, schedule->current);
|
_slot_set_interval(schedule, schedule->current);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ static void _schedule_notify(hexagram_schedule *schedule) {
|
||||||
|
|
||||||
schedule->current = 0;
|
schedule->current = 0;
|
||||||
|
|
||||||
_set_slot_interval(schedule, schedule->current);
|
_slot_set_interval(schedule, schedule->current);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _schedule_init(hexagram_schedule *schedule,
|
static int _schedule_init(hexagram_schedule *schedule,
|
||||||
|
@ -75,7 +75,7 @@ static int _schedule_init(hexagram_schedule *schedule,
|
||||||
schedule->count = count;
|
schedule->count = count;
|
||||||
|
|
||||||
schedule->ev.sigev_notify = SIGEV_THREAD;
|
schedule->ev.sigev_notify = SIGEV_THREAD;
|
||||||
schedule->ev.sigev_notify_function = _schedule_notify;
|
schedule->ev.sigev_notify_function = _ev_notify;
|
||||||
schedule->ev.sigev_value.sival_ptr = schedule;
|
schedule->ev.sigev_value.sival_ptr = schedule;
|
||||||
|
|
||||||
if (timer_create(CLOCK_REALTIME,
|
if (timer_create(CLOCK_REALTIME,
|
||||||
|
@ -132,18 +132,11 @@ int hexagram_schedule_run(hexagram_schedule *schedule) {
|
||||||
schedule->current = 0;
|
schedule->current = 0;
|
||||||
schedule->error = 0;
|
schedule->error = 0;
|
||||||
|
|
||||||
return _set_slot_interval(schedule, schedule->current);
|
return _slot_set_interval(schedule, schedule->current);
|
||||||
}
|
}
|
||||||
|
|
||||||
int hexagram_schedule_stop(hexagram_schedule *schedule) {
|
int hexagram_schedule_stop(hexagram_schedule *schedule) {
|
||||||
const struct itimerspec ts = {
|
return _set_interval(schedule, 0);
|
||||||
.it_value.tv_sec = 0,
|
|
||||||
.it_value.tv_nsec = 0,
|
|
||||||
.it_interval.tv_sec = 0,
|
|
||||||
.it_interval.tv_nsec = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
return timer_settime(schedule->timer, 0, &ts, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int hexagram_schedule_error(hexagram_schedule *schedule) {
|
int hexagram_schedule_error(hexagram_schedule *schedule) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue