1/*
2 * Copyright 2022, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _OBSD_COMPAT_SYS_TIMEOUT_H_
6#define _OBSD_COMPAT_SYS_TIMEOUT_H_
7
8
9#include <sys/callout.h>
10
11
12struct timeout {
13	struct callout c;
14};
15
16
17static inline void
18timeout_set(struct timeout *to, void (*fn)(void *), void *arg)
19{
20	callout_init_mtx(&to->c, &Giant, 0);
21	callout_reset(&to->c, -1, fn, arg);
22}
23
24
25static inline int
26timeout_pending(struct timeout *to)
27{
28	return callout_pending(&to->c);
29}
30
31
32static inline int
33timeout_add_usec(struct timeout *to, int usec)
34{
35	return (callout_schedule(&to->c, USEC_2_TICKS(usec)) ? 0 : 1);
36}
37
38
39static inline int
40timeout_add_msec(struct timeout *to, int msec)
41{
42	return timeout_add_usec(to, msec * 1000);
43}
44
45
46static inline int
47timeout_add_sec(struct timeout *to, int sec)
48{
49	return timeout_add_msec(to, sec * 1000);
50}
51
52
53static inline int
54timeout_del(struct timeout *to)
55{
56	return ((callout_stop(&to->c) == 1) ? 1 : 0);
57}
58
59
60#endif	/* _OBSD_COMPAT_SYS_TIMEOUT_H_ */
61