From 5dd0a387a305d940314fd34555a11561c0578dfc Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 13 Feb 2025 09:20:20 -0400 Subject: [PATCH] MT#55283 modernise timeval_from_us Change-Id: I745365e9c0c3c055e6972d18ab4593b9589f55f5 --- daemon/graphite.c | 2 +- daemon/main.c | 2 +- daemon/redis.c | 4 +--- lib/auxlib.h | 13 +++++-------- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/daemon/graphite.c b/daemon/graphite.c index f5293bca7..1d34e082e 100644 --- a/daemon/graphite.c +++ b/daemon/graphite.c @@ -136,7 +136,7 @@ GString *print_graphite_data(void) { struct timeval avg_duration; uint64_t managed_sess = atomic64_get_na(&rtpe_stats_graphite_diff.managed_sess); if (managed_sess) - timeval_from_us(&avg_duration, atomic64_get_na(&rtpe_stats_graphite_diff.call_duration) / managed_sess); + avg_duration = timeval_from_us(atomic64_get_na(&rtpe_stats_graphite_diff.call_duration) / managed_sess); else avg_duration = (struct timeval) {0,0}; GPF("average_call_dur %llu.%06llu",(unsigned long long)avg_duration.tv_sec,(unsigned long long)avg_duration.tv_usec); diff --git a/daemon/main.c b/daemon/main.c index 43c1440f2..cea84f4dc 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -1601,7 +1601,7 @@ static void create_everything(void) { gettimeofday(&rtpe_latest_graphite_interval_start, NULL); - timeval_from_us(&tmp_tv, (long long) rtpe_config.graphite_interval*1000000); + tmp_tv = timeval_from_us((long long) rtpe_config.graphite_interval*1000000); set_graphite_interval_tv(&tmp_tv); if (!media_player_preload_files(rtpe_config.preload_media_files)) diff --git a/daemon/redis.c b/daemon/redis.c index 2ab264680..1744af5d5 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -1121,9 +1121,7 @@ static atomic64 strtoa64(const char *c, char **endp, int base) { } static struct timeval strtotimeval(const char *c, char **endp, int base) { long long ll = strtoll(c, endp, base); - struct timeval ret; - timeval_from_us(&ret, ll); - return ret; + return timeval_from_us(ll); } define_get_int_type(time_t, time_t, strtoull); diff --git a/lib/auxlib.h b/lib/auxlib.h index ef09817e5..a86b575ae 100644 --- a/lib/auxlib.h +++ b/lib/auxlib.h @@ -350,23 +350,20 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(rwlock_w_lock_t, rwlock_ptr_unlock_r) INLINE long long timeval_us(const struct timeval *t) { return (long long) ((long long) t->tv_sec * 1000000LL) + t->tv_usec; } -INLINE void timeval_from_us(struct timeval *t, long long ms) { - t->tv_sec = ms/1000000LL; - t->tv_usec = ms%1000000LL; +INLINE struct timeval timeval_from_us(long long ms) { + return (struct timeval) { .tv_sec = ms/1000000LL, .tv_usec = ms%1000000LL }; } INLINE long long timeval_diff(const struct timeval *a, const struct timeval *b) { return timeval_us(a) - timeval_us(b); } INLINE void timeval_subtract(struct timeval *result, const struct timeval *a, const struct timeval *b) { - timeval_from_us(result, timeval_diff(a, b)); + *result = timeval_from_us(timeval_diff(a, b)); } INLINE struct timeval timeval_add(const struct timeval *a, const struct timeval *b) { - struct timeval result; - timeval_from_us(&result, timeval_us(a) + timeval_us(b)); - return result; + return timeval_from_us(timeval_us(a) + timeval_us(b)); } INLINE void timeval_add_usec(struct timeval *tv, long usec) { - timeval_from_us(tv, timeval_us(tv) + usec); + *tv = timeval_from_us(timeval_us(tv) + usec); } INLINE int long_cmp(long long a, long long b) { if (a == b)