hexagram/src/schedule.c

37 lines
845 B
C
Raw Normal View History

2023-12-24 00:11:00 -05:00
#include <stdlib.h>
#include <hexagram/schedule.h>
hexagram_schedule *hexagram_schedule_create(hexagram_table_entry *table,
size_t count) {
hexagram_schedule *schedule;
size_t i;
if ((schedule = malloc(sizeof(*schedule) + count * sizeof(hexagram_schedule_slot))) == 0) {
goto error_malloc_schedule;
}
2023-12-24 00:26:45 -05:00
schedule->timer = 0;
2023-12-24 00:11:00 -05:00
schedule->current = 0;
for (i=0; i<count; i++) {
hexagram_schedule_slot *slot = &((hexagram_schedule_slot *)(schedule + 1))[i];
slot->interval_us = 0;
slot->entry = &table[i];
}
return schedule;
error_malloc_schedule:
return NULL;
}
void hexagram_schedule_destroy(hexagram_schedule *schedule) {
if (schedule->timer) {
timer_delete(schedule->timer);
}
free(schedule);
}