Merge branch 'maint-0.4.8'
[tor.git] / src / ext / timeouts / bench / bench-wheel.c
blob0cba1af83ed1fa09c508f8f27fe2f31b3f512a01
1 #include <stdlib.h>
3 #define TIMEOUT_PUBLIC static
5 #include "timeout.h"
6 #include "timeout.c"
7 #include "bench.h"
10 static void *init(struct timeout *timeout, size_t count, int verbose) {
11 struct timeouts *T;
12 size_t i;
13 int error;
15 T = timeouts_open(TIMEOUT_mHZ, &error);
17 for (i = 0; i < count; i++) {
18 timeout_init(&timeout[i], 0);
21 #if TIMEOUT_DEBUG - 0
22 timeout_debug = verbose;
23 #endif
25 return T;
26 } /* init() */
29 static void add(void *T, struct timeout *to, timeout_t expires) {
30 timeouts_add(T, to, expires);
31 } /* add() */
34 static void del(void *T, struct timeout *to) {
35 timeouts_del(T, to);
36 } /* del() */
39 static struct timeout *get(void *T) {
40 return timeouts_get(T);
41 } /* get() */
44 static void update(void *T, timeout_t ts) {
45 timeouts_update(T, ts);
46 } /* update() */
49 static void (check)(void *T) {
50 if (!timeouts_check(T, stderr))
51 _Exit(1);
52 } /* check() */
55 static int empty(void *T) {
56 return !(timeouts_pending(T) || timeouts_expired(T));
57 } /* empty() */
60 static struct timeout *next(void *T, struct timeouts_it *it) {
61 return timeouts_next(T, it);
62 } /* next() */
65 static void destroy(void *T) {
66 timeouts_close(T);
67 } /* destroy() */
70 const struct benchops benchops = {
71 .init = &init,
72 .add = &add,
73 .del = &del,
74 .get = &get,
75 .update = &update,
76 .check = &check,
77 .empty = &empty,
78 .next = &next,
79 .destroy = &destroy