Browse Source

TT#50652 use a better timeval_cmp function

Change-Id: I727d1e7c28c2fe887fa0889060ae5f93883f52bd
changes/17/27717/4
Richard Fuchs 7 years ago
parent
commit
29a83846d7
1 changed files with 11 additions and 7 deletions
  1. +11
    -7
      lib/auxlib.h

+ 11
- 7
lib/auxlib.h View File

@ -235,14 +235,18 @@ INLINE void timeval_add(struct timeval *result, const struct timeval *a, const s
INLINE void timeval_add_usec(struct timeval *tv, long usec) { INLINE void timeval_add_usec(struct timeval *tv, long usec) {
timeval_from_us(tv, timeval_us(tv) + usec); timeval_from_us(tv, timeval_us(tv) + usec);
} }
INLINE int timeval_cmp(const struct timeval *a, const struct timeval *b) {
long long diff;
diff = timeval_diff(a, b);
if (diff < 0)
INLINE int long_cmp(long long a, long long b) {
if (a == b)
return 0;
if (a < b)
return -1; return -1;
if (diff > 0)
return 1;
return 0;
return 1;
}
INLINE int timeval_cmp(const struct timeval *a, const struct timeval *b) {
int r = long_cmp(a->tv_sec, b->tv_sec);
if (r != 0)
return r;
return long_cmp(a->tv_usec, b->tv_usec);
} }
// as a GCompareFunc // as a GCompareFunc
int timeval_cmp_ptr(const void *a, const void *b); int timeval_cmp_ptr(const void *a, const void *b);


Loading…
Cancel
Save