Commit d453fc96 authored by william's avatar william

forgot to define timeouts_open() and timeouts_close(); add timeouts_hz()

parent 13c02447
......@@ -26,6 +26,7 @@
#include <limits.h> /* CHAR_BIT */
#include <stddef.h> /* NULL */
#include <stdlib.h> /* malloc(3) free(3) */
#include <stdio.h> /* FILE fprintf(3) */
#include <inttypes.h> /* UINT64_C uint64_t */
......@@ -34,6 +35,8 @@
#include <string.h> /* memset(3) */
#include <errno.h> /* errno */
#include <sys/queue.h> /* TAILQ(3) */
#include "timeout.h"
......@@ -225,6 +228,55 @@ static struct timeouts *timeouts_init(struct timeouts *T, timeout_t hz) {
} /* timeouts_init() */
TIMEOUT_PUBLIC struct timeouts *timeouts_open(timeout_t hz, int *error) {
struct timeouts *T;
if ((T = malloc(sizeof *T)))
return timeouts_init(T, hz);
*error = errno;
return NULL;
} /* timeouts_open() */
static void timeouts_reset(struct timeouts *T) {
struct timeouts_list reset;
struct timeout *to;
TAILQ_INIT(&reset);
for (unsigned i = 0; i < countof(T->wheel); i++) {
for (unsigned j = 0; j < countof(T->wheel[i]); j++) {
TAILQ_CONCAT(&reset, &T->wheel[i][j]);
}
}
TAILQ_CONCAT(&reset, &T->expired);
TAILQ_FOREACH(to, &reset, tqe) {
to->timeouts = NULL;
to->pending = NULL;
}
} /* timeouts_reset() */
TIMEOUT_PUBLIC void timeouts_close(struct timeouts *T) {
/*
* NOTE: Delete installed timeouts so timeout_pending() and
* timeout_expired() worked as expected.
*/
timeouts_reset(T);
free(T);
} /* timeouts_close() */
TIMEOUT_PUBLIC timeout_t timeouts_hz(struct timeouts *T) {
return T->hertz;
} /* timeouts_hz() */
TIMEOUT_PUBLIC void timeouts_del(struct timeouts *T, struct timeout *to) {
if (to->pending) {
if (to->pending != &T->expired && TAILQ_EMPTY(to->pending)) {
......
......@@ -146,12 +146,15 @@ TIMEOUT_PUBLIC void timeout_del(struct timeout *);
struct timeouts;
TIMEOUT_PUBLIC struct timeouts *timeouts_open(timeout_t);
TIMEOUT_PUBLIC struct timeouts *timeouts_open(timeout_t, int *);
/* open a new timing wheel, setting optional HZ (for float conversions) */
TIMEOUT_PUBLIC void timeouts_close(struct timeouts *);
/* destroy timing wheel */
TIMEOUT_PUBLIC timeout_t timeouts_hz(struct timeouts *);
/* return HZ setting (for float conversions) */
TIMEOUT_PUBLIC void timeouts_update(struct timeouts *, timeout_t);
/* update timing wheel with current absolute time */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment