diff options
| author | Michael Biebl <biebl@debian.org> | 2019-03-26 23:26:14 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2019-03-26 23:26:14 +0100 |
| commit | 9bc3ff81969c896f6bf8e1c93f98f43f6ffffaf8 (patch) | |
| tree | 302fce2d1ab3a130ac0b684d168ab6312825fcd2 /shared/n-acd/src/util/timer.h | |
| parent | f97666c6bd29a3228443acd6401a407a19ec8d25 (diff) | |
| parent | 9a6dcbf895f9da01768e64b73cec88c16157d91e (diff) | |
Update upstream source from tag 'upstream/1.16.0'
Update to upstream version '1.16.0' with Debian dir a0f3ffb137940d423625faae8bedbaced4d34cda
Diffstat (limited to 'shared/n-acd/src/util/timer.h')
| -rw-r--r-- | shared/n-acd/src/util/timer.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/shared/n-acd/src/util/timer.h b/shared/n-acd/src/util/timer.h new file mode 100644 index 00000000..2acc99e3 --- /dev/null +++ b/shared/n-acd/src/util/timer.h @@ -0,0 +1,53 @@ +#pragma once + +#include <c-rbtree.h> +#include <inttypes.h> +#include <stdlib.h> +#include <time.h> +#include <unistd.h> + +typedef struct Timer Timer; +typedef struct Timeout Timeout; + +enum { + _TIMER_E_SUCCESS, + + TIMER_E_TRIGGERED, + + _TIMER_E_N, +}; + +struct Timer { + int fd; + clockid_t clock; + CRBTree tree; + uint64_t scheduled_timeout; +}; + +#define TIMER_NULL(_x) { \ + .fd = -1, \ + .tree = C_RBTREE_INIT, \ + } + +struct Timeout { + Timer *timer; + CRBNode node; + uint64_t timeout; +}; + +#define TIMEOUT_INIT(_x) { \ + .node = C_RBNODE_INIT((_x).node), \ + } + +int timer_init(Timer *timer); +void timer_deinit(Timer *timer); + +void timer_now(Timer *timer, uint64_t *nowp); + +int timer_pop_timeout(Timer *timer, uint64_t now, Timeout **timerp); +void timer_rearm(Timer *timer); +int timer_read(Timer *timer); + +void timeout_schedule(Timeout *timeout, Timer *timer, uint64_t time); +void timeout_unschedule(Timeout *timeout); + |