-/* $OpenBSD: kern_timeout.c,v 1.98 2024/08/05 23:51:11 dlg Exp $ */
+/* $OpenBSD: kern_timeout.c,v 1.99 2024/08/11 00:49:34 dlg Exp $ */
/*
* Copyright (c) 2001 Thomas Nordin <nordin@openbsd.org>
* Copyright (c) 2000-2001 Artur Grabowski <art@openbsd.org>
return ret;
}
+static inline int
+timeout_add_ticks(struct timeout *to, uint64_t to_ticks, int notzero)
+{
+ if (to_ticks > INT_MAX)
+ to_ticks = INT_MAX;
+ else if (to_ticks == 0 && notzero)
+ to_ticks = 1;
+
+ return timeout_add(to, (int)to_ticks);
+}
+
int
timeout_add_tv(struct timeout *to, const struct timeval *tv)
{
uint64_t to_ticks;
to_ticks = (uint64_t)hz * tv->tv_sec + tv->tv_usec / tick;
- if (to_ticks > INT_MAX)
- to_ticks = INT_MAX;
- if (to_ticks == 0 && tv->tv_usec > 0)
- to_ticks = 1;
- return timeout_add(to, (int)to_ticks);
+ return timeout_add_ticks(to, to_ticks, tv->tv_usec > 0);
}
int
uint64_t to_ticks;
to_ticks = (uint64_t)hz * secs;
- if (to_ticks > INT_MAX)
- to_ticks = INT_MAX;
- if (to_ticks == 0)
- to_ticks = 1;
- return timeout_add(to, (int)to_ticks);
+ return timeout_add_ticks(to, to_ticks, 1);
}
int
-timeout_add_msec(struct timeout *to, int msecs)
+timeout_add_msec(struct timeout *to, uint64_t msecs)
{
uint64_t to_ticks;
- to_ticks = (uint64_t)msecs * 1000 / tick;
- if (to_ticks > INT_MAX)
- to_ticks = INT_MAX;
- if (to_ticks == 0 && msecs > 0)
- to_ticks = 1;
+ to_ticks = msecs * 1000 / tick;
- return timeout_add(to, (int)to_ticks);
+ return timeout_add_ticks(to, to_ticks, msecs > 0);
}
int
-timeout_add_usec(struct timeout *to, int usecs)
+timeout_add_usec(struct timeout *to, uint64_t usecs)
{
- int to_ticks = usecs / tick;
+ uint64_t to_ticks;
- if (to_ticks == 0 && usecs > 0)
- to_ticks = 1;
+ to_ticks = usecs / tick;
- return timeout_add(to, to_ticks);
+ return timeout_add_ticks(to, to_ticks, usecs > 0);
}
int
uint64_t to_ticks;
to_ticks = nsecs / (tick * 1000);
- if (to_ticks > INT_MAX)
- to_ticks = INT_MAX;
- if (to_ticks == 0 && nsecs > 0)
- to_ticks = 1;
- return timeout_add(to, (int)to_ticks);
+ return timeout_add_ticks(to, to_ticks, nsecs > 0);
}
int
-/* $OpenBSD: timeout.h,v 1.49 2024/08/05 23:51:11 dlg Exp $ */
+/* $OpenBSD: timeout.h,v 1.50 2024/08/11 00:49:34 dlg Exp $ */
/*
* Copyright (c) 2000-2001 Artur Grabowski <art@openbsd.org>
* All rights reserved.
int timeout_add(struct timeout *, int);
int timeout_add_tv(struct timeout *, const struct timeval *);
int timeout_add_sec(struct timeout *, int);
-int timeout_add_msec(struct timeout *, int);
-int timeout_add_usec(struct timeout *, int);
+int timeout_add_msec(struct timeout *, uint64_t);
+int timeout_add_usec(struct timeout *, uint64_t);
int timeout_add_nsec(struct timeout *, uint64_t);
int timeout_abs_ts(struct timeout *, const struct timespec *);