From c70ec71d0cfb6524c270d54b83cb1a38903412da Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sun, 5 Jul 2020 21:16:32 -0400 Subject: [PATCH] freebsd_network: Move ticks/seconds conversions to sys/time.h and rename. They now match the names they have in FreeBSD. No functional change intended. --- src/libs/compat/freebsd_network/Condvar.cpp | 4 ++-- src/libs/compat/freebsd_network/callout.cpp | 2 +- src/libs/compat/freebsd_network/clock.c | 4 ++-- src/libs/compat/freebsd_network/compat/sys/kernel.h | 7 ++----- src/libs/compat/freebsd_network/compat/sys/time.h | 11 +++++++++-- src/libs/compat/freebsd_network/systm.cpp | 2 +- .../compat/freebsd_wlan/net80211/ieee80211_haiku.h | 5 ++--- 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/libs/compat/freebsd_network/Condvar.cpp b/src/libs/compat/freebsd_network/Condvar.cpp index e4a6b45d04..a7bbcd85a3 100644 --- a/src/libs/compat/freebsd_network/Condvar.cpp +++ b/src/libs/compat/freebsd_network/Condvar.cpp @@ -38,7 +38,7 @@ int conditionTimedWait(struct cv* variable, const int timeout) { status_t status = variable->condition.Wait(B_RELATIVE_TIMEOUT, - ticks_to_usecs(timeout)); + TICKS_2_USEC(timeout)); if (status != B_OK) status = EWOULDBLOCK; @@ -64,7 +64,7 @@ int publishedConditionTimedWait(const void* waitChannel, const int timeout) { ConditionVariableEntry variableEntry; - bigtime_t usecs = ticks_to_usecs(timeout); + bigtime_t usecs = TICKS_2_USEC(timeout); // FreeBSD has a condition-variable scheduling system with different // scheduling semantics than ours does. As a result, it seems there are diff --git a/src/libs/compat/freebsd_network/callout.cpp b/src/libs/compat/freebsd_network/callout.cpp index 3300989b07..53d613e35d 100644 --- a/src/libs/compat/freebsd_network/callout.cpp +++ b/src/libs/compat/freebsd_network/callout.cpp @@ -191,7 +191,7 @@ callout_reset(struct callout *c, int _ticks, void (*func)(void *), void *arg) if (c->due <= 0) list_add_item(&sTimers, c); - c->due = system_time() + ticks_to_usecs(_ticks); + c->due = system_time() + TICKS_2_USEC(_ticks); // notify timer about the change if necessary if (sTimeout > c->due) diff --git a/src/libs/compat/freebsd_network/clock.c b/src/libs/compat/freebsd_network/clock.c index 567a562110..29ae4107da 100644 --- a/src/libs/compat/freebsd_network/clock.c +++ b/src/libs/compat/freebsd_network/clock.c @@ -8,7 +8,7 @@ int32_t -get_ticks() +_get_ticks() { - return usecs_to_ticks(system_time()); + return USEC_2_TICKS(system_time()); } diff --git a/src/libs/compat/freebsd_network/compat/sys/kernel.h b/src/libs/compat/freebsd_network/compat/sys/kernel.h index 2524baaf42..cc10cce69c 100644 --- a/src/libs/compat/freebsd_network/compat/sys/kernel.h +++ b/src/libs/compat/freebsd_network/compat/sys/kernel.h @@ -25,11 +25,8 @@ * as it defines a long long constant. */ #define hz 1000LL -int32_t get_ticks(); -#define ticks (get_ticks()) - -#define ticks_to_usecs(t) (1000000*((bigtime_t)t) / hz) -#define usecs_to_ticks(t) (((bigtime_t)t*hz) / 1000000) +int32_t _get_ticks(); +#define ticks (_get_ticks()) /* sysinit */ diff --git a/src/libs/compat/freebsd_network/compat/sys/time.h b/src/libs/compat/freebsd_network/compat/sys/time.h index 4b061e3ad4..14265f44dd 100644 --- a/src/libs/compat/freebsd_network/compat/sys/time.h +++ b/src/libs/compat/freebsd_network/compat/sys/time.h @@ -1,5 +1,5 @@ /* - * Copyright 2009, Colin Günther, coling@gmx.de. + * Copyright 2020, Haiku, Inc. All rights reserved. * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef _FBSD_COMPAT_SYS_TIME_H_ @@ -12,9 +12,16 @@ #include -#define time_uptime (system_time() / 1000000) +#define TICKS_2_USEC(t) ((1000000*(bigtime_t)t) / hz) +#define USEC_2_TICKS(t) (((bigtime_t)t*hz) / 1000000) + +#define TICKS_2_MSEC(t) ((1000*(bigtime_t)t) / hz) +#define MSEC_2_TICKS(t) (((bigtime_t)t*hz) / 1000) + +#define time_uptime USEC_2_TICKS(system_time()) int ppsratecheck(struct timeval*, int*, int); + #endif /* _FBSD_COMPAT_SYS_TIME_H_ */ diff --git a/src/libs/compat/freebsd_network/systm.cpp b/src/libs/compat/freebsd_network/systm.cpp index a8d7ef61cc..458981f6b2 100644 --- a/src/libs/compat/freebsd_network/systm.cpp +++ b/src/libs/compat/freebsd_network/systm.cpp @@ -16,7 +16,7 @@ int _pause(const char* waitMessage, int timeout) { KASSERT(timeout != 0, ("pause: timeout required")); - return snooze(ticks_to_usecs(timeout)); + return snooze(TICKS_2_USEC(timeout)); } diff --git a/src/libs/compat/freebsd_wlan/net80211/ieee80211_haiku.h b/src/libs/compat/freebsd_wlan/net80211/ieee80211_haiku.h index c61df14023..1657a49503 100644 --- a/src/libs/compat/freebsd_wlan/net80211/ieee80211_haiku.h +++ b/src/libs/compat/freebsd_wlan/net80211/ieee80211_haiku.h @@ -265,9 +265,8 @@ void ieee80211_vap_destroy(struct ieee80211vap *); (((_ifp)->if_flags & IFF_UP) && \ ((_ifp)->if_drv_flags & IFF_DRV_RUNNING)) -/* XXX TODO: cap these at 1, as hz may not be 1000 */ -#define msecs_to_ticks(ms) (((ms)*hz)/1000) -#define ticks_to_msecs(t) (1000*(t) / hz) +#define msecs_to_ticks(ms) MSEC_2_TICKS(ms) +#define ticks_to_msecs(t) TICKS_2_MSEC(t) #define ticks_to_secs(t) ((t) / hz) #define ieee80211_time_after(a,b) ((long)(b) - (long)(a) < 0)