Commit
97be153858b4cd175cbe7862b8e1624bf22ab98a (clang: Add
annotations for thread safety check.) defined 'struct ovs_mutex'
variable in 'atomic_flag' in 'ovs-atomic-pthreads.h'. This
casued "mutex: has incomplete type" error in compilation when
'ovs-atomic-pthreads.h' is included.
This commit goes back to use 'pthread_mutex_t' for that variable
and adds test for the 'atomic_flag' related functions.
Reported-by: Gurucharan Shetty <gshetty@nicira.com>
Signed-off-by: Alex Wang <alexw@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
atomic_flag *flag = CONST_CAST(atomic_flag *, flag_);
bool old_value;
- ovs_mutex_lock(&flag->mutex);
+ xpthread_mutex_lock(&flag->mutex);
old_value = flag->b;
flag->b = true;
- ovs_mutex_unlock(&flag->mutex);
+ xpthread_mutex_unlock(&flag->mutex);
return old_value;
}
{
atomic_flag *flag = CONST_CAST(atomic_flag *, flag_);
- ovs_mutex_lock(&flag->mutex);
+ xpthread_mutex_lock(&flag->mutex);
flag->b = false;
- ovs_mutex_unlock(&flag->mutex);
+ xpthread_mutex_unlock(&flag->mutex);
}
void
typedef struct {
bool b;
- struct ovs_mutex mutex;
+ pthread_mutex_t mutex;
} atomic_flag;
#define ATOMIC_FLAG_INIT { false, PTHREAD_MUTEX_INITIALIZER }
} \
}
+XPTHREAD_FUNC1(pthread_mutex_lock, pthread_mutex_t *);
+XPTHREAD_FUNC1(pthread_mutex_unlock, pthread_mutex_t *);
XPTHREAD_FUNC1(pthread_mutexattr_init, pthread_mutexattr_t *);
XPTHREAD_FUNC1(pthread_mutexattr_destroy, pthread_mutexattr_t *);
XPTHREAD_FUNC2(pthread_mutexattr_settype, pthread_mutexattr_t *, int);
void ovs_mutex_cond_wait(pthread_cond_t *, const struct ovs_mutex *);
+/* Wrappers for pthread_mutex_*() that abort the process on any error.
+ * This is still needed when ovs-atomic-pthreads.h is used. */
+void xpthread_mutex_lock(pthread_mutex_t *mutex);
+void xpthread_mutex_unlock(pthread_mutex_t *mutex);
+
/* Wrappers for pthread_mutexattr_*() that abort the process on any error. */
void xpthread_mutexattr_init(pthread_mutexattr_t *);
void xpthread_mutexattr_destroy(pthread_mutexattr_t *);
ovs_assert(value == 8); \
}
+static void
+test_atomic_flag(void)
+{
+ atomic_flag flag = ATOMIC_FLAG_INIT;
+ ovs_assert(atomic_flag_test_and_set(&flag) == false);
+ ovs_assert(flag.b == true);
+ atomic_flag_clear(&flag);
+ ovs_assert(flag.b == false);
+}
+
int
main(void)
{
TEST_ATOMIC_TYPE(atomic_uint64_t, uint64_t);
TEST_ATOMIC_TYPE(atomic_int64_t, int64_t);
+ test_atomic_flag();
+
return 0;
}