\f
#define SYSTEM_STATS_INTERVAL (5 * 1000) /* In milliseconds. */
-static pthread_mutex_t mutex = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER;
+static struct ovs_mutex mutex = OVS_ADAPTIVE_MUTEX_INITIALIZER;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
-static struct latch latch;
+static struct latch latch OVS_GUARDED_BY(mutex);
static bool enabled;
-static bool started;
-static struct smap *system_stats;
+static bool started OVS_GUARDED_BY(mutex);
+static struct smap *system_stats OVS_GUARDED_BY(mutex);
static void *system_stats_thread_func(void *);
static void discard_stats(void);
system_stats_enable(bool enable)
{
if (enabled != enable) {
- xpthread_mutex_lock(&mutex);
+ ovs_mutex_lock(&mutex);
if (enable) {
if (!started) {
xpthread_create(NULL, NULL, system_stats_thread_func, NULL);
xpthread_cond_signal(&cond);
}
enabled = enable;
- xpthread_mutex_unlock(&mutex);
+ ovs_mutex_unlock(&mutex);
}
}
{
struct smap *stats = NULL;
- xpthread_mutex_lock(&mutex);
+ ovs_mutex_lock(&mutex);
if (system_stats) {
latch_poll(&latch);
discard_stats();
}
}
- xpthread_mutex_unlock(&mutex);
+ ovs_mutex_unlock(&mutex);
return stats;
}
}
static void
-discard_stats(void)
+discard_stats(void) OVS_REQUIRES(mutex)
{
if (system_stats) {
smap_destroy(system_stats);
long long int next_refresh;
struct smap *stats;
- xpthread_mutex_lock(&mutex);
+ ovs_mutex_lock(&mutex);
while (!enabled) {
- xpthread_cond_wait(&cond, &mutex);
+ ovs_mutex_cond_wait(&cond, &mutex);
}
- xpthread_mutex_unlock(&mutex);
+ ovs_mutex_unlock(&mutex);
stats = xmalloc(sizeof *stats);
smap_init(stats);
get_process_stats(stats);
get_filesys_stats(stats);
- xpthread_mutex_lock(&mutex);
+ ovs_mutex_lock(&mutex);
discard_stats();
system_stats = stats;
latch_set(&latch);
- xpthread_mutex_unlock(&mutex);
+ ovs_mutex_unlock(&mutex);
next_refresh = time_msec() + SYSTEM_STATS_INTERVAL;
do {