From cfe6f87c8dd9e07c612cf048f81624eae9dd148c Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 27 Feb 2019 10:34:00 -0500 Subject: [PATCH] TT#50652 split timeval_cmp_ptr into function Change-Id: I803e25bc3dc631d9eb05223d61708e9bfc5ca9de --- daemon/ice.c | 20 +------------------- lib/auxlib.c | 24 ++++++++++++++++++++++++ lib/auxlib.h | 3 +++ 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/daemon/ice.c b/daemon/ice.c index d6740d2c8..8fc0d04f7 100644 --- a/daemon/ice.c +++ b/daemon/ice.c @@ -572,25 +572,7 @@ nope: static int __ice_agent_timer_cmp(const void *a, const void *b) { const struct ice_agent *A = a, *B = b; - int ret; - /* zero timevals go last */ - if (A->next_check.tv_sec == 0 && B->next_check.tv_sec != 0) - return 1; - if (B->next_check.tv_sec == 0 && A->next_check.tv_sec == 0) - return -1; - if (A->next_check.tv_sec == 0 && B->next_check.tv_sec == 0) - goto ptr; - /* earlier timevals go first */ - ret = timeval_cmp(&A->next_check, &B->next_check); - if (ret) - return ret; - /* equal timeval, so use pointer as tie breaker */ -ptr: - if (A < B) - return -1; - if (A > B) - return 1; - return 0; + return timeval_cmp_ptr(&A->next_check, &B->next_check); } void ice_init(void) { random_string((void *) &tie_breaker, sizeof(tie_breaker)); diff --git a/lib/auxlib.c b/lib/auxlib.c index c2f729798..52046cfe0 100644 --- a/lib/auxlib.c +++ b/lib/auxlib.c @@ -237,3 +237,27 @@ int uint32_eq(const void *a, const void *b) { const u_int32_t *A = a, *B = b; return (*A == *B) ? TRUE : FALSE; } + +int timeval_cmp_ptr(const void *a, const void *b) { + const struct timeval *A = a, *B = b; + int ret; + + /* zero timevals go last */ + if (A->tv_sec == 0 && B->tv_sec != 0) + return 1; + if (B->tv_sec == 0 && A->tv_sec == 0) + return -1; + if (A->tv_sec == 0 && B->tv_sec == 0) + goto ptr; + /* earlier timevals go first */ + ret = timeval_cmp(A, B); + if (ret) + return ret; + /* equal timeval, so use pointer as tie breaker */ +ptr: + if (A < B) + return -1; + if (A > B) + return 1; + return 0; +} diff --git a/lib/auxlib.h b/lib/auxlib.h index 3f2282040..6c9ad5b03 100644 --- a/lib/auxlib.h +++ b/lib/auxlib.h @@ -244,6 +244,9 @@ INLINE int timeval_cmp(const struct timeval *a, const struct timeval *b) { return 1; return 0; } +// as a GCompareFunc +int timeval_cmp_ptr(const void *a, const void *b); + INLINE void timeval_lowest(struct timeval *l, const struct timeval *n) { if (!n->tv_sec) return;