TT#50652 split timeval_cmp_ptr into function

Change-Id: I803e25bc3dc631d9eb05223d61708e9bfc5ca9de
changes/10/27610/9
Richard Fuchs 6 years ago
parent 38c96468f1
commit cfe6f87c8d

@ -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));

@ -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;
}

@ -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;

Loading…
Cancel
Save