summaryrefslogtreecommitdiff
path: root/timeout.h
diff options
context:
space:
mode:
Diffstat (limited to 'timeout.h')
-rw-r--r--timeout.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/timeout.h b/timeout.h
index ee0180d..5c82753 100644
--- a/timeout.h
+++ b/timeout.h
@@ -189,6 +189,34 @@ TIMEOUT_PUBLIC bool timeouts_expired(struct timeouts *);
TIMEOUT_PUBLIC bool timeouts_check(struct timeouts *, FILE *);
/* return true if invariants hold. describes failures to optional file handle. */
+#define TIMEOUTS_PENDING 0x10
+#define TIMEOUTS_EXPIRED 0x20
+#define TIMEOUTS_ALL (TIMEOUTS_PENDING|TIMEOUTS_EXPIRED)
+
+#define TIMEOUTS_CURSOR_INITIALIZER(flags) { (flags) }
+
+#define TIMEOUTS_CURSOR_INIT(cur, _flags) do { \
+ (cur)->flags = (_flags); \
+ (cur)->pc = 0; \
+} while (0)
+
+struct timeouts_cursor {
+ int flags;
+ unsigned pc, i, j;
+ struct timeout *to;
+}; /* struct timeouts_cursor */
+
+TIMEOUT_PUBLIC struct timeout *timeouts_next(struct timeouts *, struct timeouts_cursor *);
+/* return next timeout in pending wheel or expired queue. caller can delete
+ * the returned timeout, but should not otherwise manipulate the timing
+ * wheel. in particular, caller SHOULD NOT delete any other timeout as that
+ * could invalidate cursor state and trigger a use-after-free.
+ */
+
+#define TIMEOUTS_FOREACH(var, T, flags) \
+ struct timeouts_cursor _foreach_cursor = TIMEOUTS_CURSOR_INITIALIZER((flags)); \
+ while (((var) = timeouts_next((T), &_foreach_cursor)))
+
/*
* B O N U S W H E E L I N T E R F A C E S