From 3e509ec5ed94351e0b6fc1cfc64351f5be7d8bc2 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 13 Sep 2013 11:32:45 -0700 Subject: [PATCH] timeval: Add Clang thread-safety annotations, fix unimportant violation. Signed-off-by: Ben Pfaff Acked-by: Ethan Jackson --- lib/timeval.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/timeval.c b/lib/timeval.c index c24788ab3..64d65eade 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -44,10 +44,9 @@ struct clock { /* Features for use by unit tests. Protected by 'rwlock'. */ struct ovs_rwlock rwlock; - struct timespec warp; /* Offset added for unit tests. */ - bool stopped; /* Disables real-time updates if true. */ - - struct timespec cache; /* Last time read from kernel. */ + struct timespec warp OVS_GUARDED; /* Offset added for unit tests. */ + bool stopped OVS_GUARDED; /* Disable real-time updates if true. */ + struct timespec cache OVS_GUARDED; /* Last time read from kernel. */ }; /* Our clocks. */ @@ -320,14 +319,24 @@ timespec_add(struct timespec *sum, *sum = tmp; } +static bool +is_warped(const struct clock *c) +{ + bool warped; + + ovs_rwlock_rdlock(&c->rwlock); + warped = monotonic_clock.warp.tv_sec || monotonic_clock.warp.tv_nsec; + ovs_rwlock_unlock(&c->rwlock); + + return warped; +} + static void log_poll_interval(long long int last_wakeup) { long long int interval = time_msec() - last_wakeup; - if (interval >= 1000 - && !monotonic_clock.warp.tv_sec - && !monotonic_clock.warp.tv_nsec) { + if (interval >= 1000 && !is_warped(&monotonic_clock)) { const struct rusage *last_rusage = get_recent_rusage(); struct rusage rusage; -- 2.47.0