summaryrefslogtreecommitdiff
path: root/src/ext/timeouts/bench/bench-wheel.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-05-09 14:06:10 -0400
committerNick Mathewson <nickm@torproject.org>2016-05-09 14:06:10 -0400
commit69380033d644d39a7369e0cd2b2cb7fd5cd7c695 (patch)
tree4c06dd268817276028ece95eeb6d1db91a7cb9a6 /src/ext/timeouts/bench/bench-wheel.c
parent641cdc345c7a0e8123cee9a7b3864b63ba389afa (diff)
parentaf132fc299f837f8749278099e6257cea3795e8e (diff)
downloadtor-69380033d644d39a7369e0cd2b2cb7fd5cd7c695.tar.gz
tor-69380033d644d39a7369e0cd2b2cb7fd5cd7c695.zip
Merge branch 'timeouts_v2_squashed'
Diffstat (limited to 'src/ext/timeouts/bench/bench-wheel.c')
-rw-r--r--src/ext/timeouts/bench/bench-wheel.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/ext/timeouts/bench/bench-wheel.c b/src/ext/timeouts/bench/bench-wheel.c
new file mode 100644
index 0000000000..0cba1af83e
--- /dev/null
+++ b/src/ext/timeouts/bench/bench-wheel.c
@@ -0,0 +1,81 @@
+#include <stdlib.h>
+
+#define TIMEOUT_PUBLIC static
+
+#include "timeout.h"
+#include "timeout.c"
+#include "bench.h"
+
+
+static void *init(struct timeout *timeout, size_t count, int verbose) {
+ struct timeouts *T;
+ size_t i;
+ int error;
+
+ T = timeouts_open(TIMEOUT_mHZ, &error);
+
+ for (i = 0; i < count; i++) {
+ timeout_init(&timeout[i], 0);
+ }
+
+#if TIMEOUT_DEBUG - 0
+ timeout_debug = verbose;
+#endif
+
+ return T;
+} /* init() */
+
+
+static void add(void *T, struct timeout *to, timeout_t expires) {
+ timeouts_add(T, to, expires);
+} /* add() */
+
+
+static void del(void *T, struct timeout *to) {
+ timeouts_del(T, to);
+} /* del() */
+
+
+static struct timeout *get(void *T) {
+ return timeouts_get(T);
+} /* get() */
+
+
+static void update(void *T, timeout_t ts) {
+ timeouts_update(T, ts);
+} /* update() */
+
+
+static void (check)(void *T) {
+ if (!timeouts_check(T, stderr))
+ _Exit(1);
+} /* check() */
+
+
+static int empty(void *T) {
+ return !(timeouts_pending(T) || timeouts_expired(T));
+} /* empty() */
+
+
+static struct timeout *next(void *T, struct timeouts_it *it) {
+ return timeouts_next(T, it);
+} /* next() */
+
+
+static void destroy(void *T) {
+ timeouts_close(T);
+} /* destroy() */
+
+
+const struct benchops benchops = {
+ .init = &init,
+ .add = &add,
+ .del = &del,
+ .get = &get,
+ .update = &update,
+ .check = &check,
+ .empty = &empty,
+ .next = &next,
+ .destroy = &destroy
+};
+