From f0e4e85d192f41b4b47f6381c078a1c5a5493bb4 Mon Sep 17 00:00:00 2001 From: Joe Stringer Date: Tue, 4 Mar 2014 13:15:41 -0800 Subject: [PATCH] ovs-thread: Add xpthread_barrier_*() wrappers. Signed-off-by: Joe Stringer Signed-off-by: Ben Pfaff --- lib/ovs-thread.c | 26 ++++++++++++++++++++++++++ lib/ovs-thread.h | 6 ++++++ 2 files changed, 32 insertions(+) diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c index 4dfccaf3e..b6b51c76a 100644 --- a/lib/ovs-thread.c +++ b/lib/ovs-thread.c @@ -117,6 +117,15 @@ UNLOCK_FUNCTION(rwlock, destroy); ovs_abort(error, "%s failed", #FUNCTION); \ } \ } +#define XPTHREAD_FUNC3(FUNCTION, PARAM1, PARAM2, PARAM3)\ + void \ + x##FUNCTION(PARAM1 arg1, PARAM2 arg2, PARAM3 arg3) \ + { \ + int error = FUNCTION(arg1, arg2, arg3); \ + if (OVS_UNLIKELY(error)) { \ + ovs_abort(error, "%s failed", #FUNCTION); \ + } \ + } XPTHREAD_FUNC1(pthread_mutex_lock, pthread_mutex_t *); XPTHREAD_FUNC1(pthread_mutex_unlock, pthread_mutex_t *); @@ -136,6 +145,10 @@ XPTHREAD_FUNC1(pthread_cond_destroy, pthread_cond_t *); XPTHREAD_FUNC1(pthread_cond_signal, pthread_cond_t *); XPTHREAD_FUNC1(pthread_cond_broadcast, pthread_cond_t *); +XPTHREAD_FUNC3(pthread_barrier_init, pthread_barrier_t *, + pthread_barrierattr_t *, unsigned int); +XPTHREAD_FUNC1(pthread_barrier_destroy, pthread_barrier_t *); + XPTHREAD_FUNC2(pthread_join, pthread_t, void **); typedef void destructor_func(void *); @@ -215,6 +228,19 @@ ovs_mutex_cond_wait(pthread_cond_t *cond, const struct ovs_mutex *mutex_) ovs_abort(error, "pthread_cond_wait failed"); } } + +int +xpthread_barrier_wait(pthread_barrier_t *barrier) +{ + int error; + + error = pthread_barrier_wait(barrier); + if (error && OVS_UNLIKELY(error != PTHREAD_BARRIER_SERIAL_THREAD)) { + ovs_abort(error, "pthread_barrier_wait failed"); + } + + return error; +} DEFINE_EXTERN_PER_THREAD_DATA(ovsthread_id, 0); diff --git a/lib/ovs-thread.h b/lib/ovs-thread.h index 2e9a937f5..8868c5115 100644 --- a/lib/ovs-thread.h +++ b/lib/ovs-thread.h @@ -146,6 +146,12 @@ void xpthread_cond_destroy(pthread_cond_t *); void xpthread_cond_signal(pthread_cond_t *); void xpthread_cond_broadcast(pthread_cond_t *); +/* Wrappers for pthread_barrier_*() that abort the process on any error. */ +void xpthread_barrier_init(pthread_barrier_t *, pthread_barrierattr_t *, + unsigned int count); +int xpthread_barrier_wait(pthread_barrier_t *); +void xpthread_barrier_destroy(pthread_barrier_t *); + void xpthread_key_create(pthread_key_t *, void (*destructor)(void *)); void xpthread_key_delete(pthread_key_t); void xpthread_setspecific(pthread_key_t, const void *); -- 2.43.0