We have too many timeout(9) initialization functions and macros.
Let's slim it down and combine some interfaces.
- Remove timeout_set_kclock(), TIMEOUT_INITIALIZER_KCLOCK().
- Expand timeout_set_flags(), TIMEOUT_INITIALIZER_FLAGS() to accept
an additional "kclock" parameter.
- Reimplement timeout_set(), timeout_set_proc() with timeout_set_flags().
- Reimplement TIMEOUT_INITIALIZER() with TIMEOUT_INITIALIZER_FLAGS().
- Update the sole timeout_set_flags() user to pass a kclock parameter.
- Update the sole timeout_set_kclock() user to call timeout_set_flags().
- Update the sole TIMEOUT_INITIALIZER_FLAGS() user to provide a kclock
parameter.
The timeout(9) code is now a bit out of sync with the manpage. This
will be corrected in a subsequent commit.
ok kn@
-/* $OpenBSD: kern_fork.c,v 1.243 2022/11/02 07:20:07 guenther Exp $ */
+/* $OpenBSD: kern_fork.c,v 1.244 2022/11/11 18:09:58 cheloha Exp $ */
/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */
/*
rw_init(&pr->ps_lock, "pslock");
mtx_init(&pr->ps_mtx, IPL_HIGH);
- timeout_set_kclock(&pr->ps_realit_to, realitexpire, pr,
+ timeout_set_flags(&pr->ps_realit_to, realitexpire, pr,
KCLOCK_UPTIME, 0);
timeout_set(&pr->ps_rucheck_to, rucheck, pr);
}
-/* $OpenBSD: kern_timeout.c,v 1.87 2022/11/09 17:12:50 cheloha Exp $ */
+/* $OpenBSD: kern_timeout.c,v 1.88 2022/11/11 18:09:58 cheloha Exp $ */
/*
* Copyright (c) 2001 Thomas Nordin <nordin@openbsd.org>
* Copyright (c) 2000-2001 Artur Grabowski <art@openbsd.org>
kthread_create_deferred(softclock_create_thread, NULL);
}
-static inline void
-_timeout_set(struct timeout *to, void (*fn)(void *), void *arg, int kclock,
- int flags)
-{
- to->to_func = fn;
- to->to_arg = arg;
- to->to_kclock = kclock;
- to->to_flags = flags | TIMEOUT_INITIALIZED;
-}
-
void
timeout_set(struct timeout *new, void (*fn)(void *), void *arg)
{
- _timeout_set(new, fn, arg, KCLOCK_NONE, 0);
+ timeout_set_flags(new, fn, arg, KCLOCK_NONE, 0);
}
void
-timeout_set_flags(struct timeout *to, void (*fn)(void *), void *arg, int flags)
+timeout_set_flags(struct timeout *to, void (*fn)(void *), void *arg, int kclock,
+ int flags)
{
- _timeout_set(to, fn, arg, KCLOCK_NONE, flags);
+ to->to_func = fn;
+ to->to_arg = arg;
+ to->to_kclock = kclock;
+ to->to_flags = flags | TIMEOUT_INITIALIZED;
}
void
timeout_set_proc(struct timeout *new, void (*fn)(void *), void *arg)
{
- _timeout_set(new, fn, arg, KCLOCK_NONE, TIMEOUT_PROC);
-}
-
-void
-timeout_set_kclock(struct timeout *to, void (*fn)(void *), void *arg,
- int kclock, int flags)
-{
- _timeout_set(to, fn, arg, kclock, flags);
+ timeout_set_flags(new, fn, arg, KCLOCK_NONE, TIMEOUT_PROC);
}
int
procflag = (to->to_flags & TIMEOUT_PROC);
timeout_sync_order(procflag);
- timeout_set_flags(&barrier, timeout_barrier_timeout, &c, procflag);
+ timeout_set_flags(&barrier, timeout_barrier_timeout, &c, KCLOCK_NONE,
+ procflag);
barrier.to_process = curproc->p_p;
cond_init(&c);
-/* $OpenBSD: ip_ipsp.c,v 1.274 2022/11/05 22:33:11 jan Exp $ */
+/* $OpenBSD: ip_ipsp.c,v 1.275 2022/11/11 18:09:58 cheloha Exp $ */
/*
* The authors of this code are John Ioannidis (ji@tla.org),
* Angelos D. Keromytis (kermit@csd.uch.gr),
LIST_HEAD(, ipsec_ids) ipsp_ids_gc_list =
LIST_HEAD_INITIALIZER(ipsp_ids_gc_list); /* [F] */
struct timeout ipsp_ids_gc_timeout =
- TIMEOUT_INITIALIZER_FLAGS(ipsp_ids_gc, NULL, TIMEOUT_PROC);
+ TIMEOUT_INITIALIZER_FLAGS(ipsp_ids_gc, NULL, KCLOCK_NONE, TIMEOUT_PROC);
static inline int ipsp_ids_cmp(const struct ipsec_ids *,
const struct ipsec_ids *);
-/* $OpenBSD: timeout.h,v 1.45 2022/11/09 17:12:50 cheloha Exp $ */
+/* $OpenBSD: timeout.h,v 1.46 2022/11/11 18:09:58 cheloha Exp $ */
/*
* Copyright (c) 2000-2001 Artur Grabowski <art@openbsd.org>
* All rights reserved.
#define KCLOCK_UPTIME 0 /* uptime clock; time since boot */
#define KCLOCK_MAX 1
-#define __TIMEOUT_INITIALIZER(_fn, _arg, _kclock, _flags) { \
+#define TIMEOUT_INITIALIZER_FLAGS(_fn, _arg, _kclock, _flags) { \
.to_list = { NULL, NULL }, \
.to_abstime = { .tv_sec = 0, .tv_nsec = 0 }, \
.to_func = (_fn), \
.to_kclock = (_kclock) \
}
-#define TIMEOUT_INITIALIZER_KCLOCK(_fn, _arg, _kclock, _flags) \
- __TIMEOUT_INITIALIZER((_fn), (_arg), (_kclock), (_flags))
-
-#define TIMEOUT_INITIALIZER_FLAGS(_fn, _arg, _flags) \
- __TIMEOUT_INITIALIZER((_fn), (_arg), KCLOCK_NONE, (_flags))
-
#define TIMEOUT_INITIALIZER(_f, _a) \
- __TIMEOUT_INITIALIZER((_f), (_a), KCLOCK_NONE, 0)
+ TIMEOUT_INITIALIZER_FLAGS((_f), (_a), KCLOCK_NONE, 0)
void timeout_set(struct timeout *, void (*)(void *), void *);
-void timeout_set_flags(struct timeout *, void (*)(void *), void *, int);
-void timeout_set_kclock(struct timeout *, void (*)(void *), void *, int, int);
+void timeout_set_flags(struct timeout *, void (*)(void *), void *, int, int);
void timeout_set_proc(struct timeout *, void (*)(void *), void *);
int timeout_add(struct timeout *, int);