ovs-thread: Add xpthread_barrier_*() wrappers.
authorJoe Stringer <joestringer@nicira.com>
Tue, 4 Mar 2014 21:15:41 +0000 (13:15 -0800)
committerBen Pfaff <blp@nicira.com>
Tue, 4 Mar 2014 21:37:11 +0000 (13:37 -0800)
Signed-off-by: Joe Stringer <joestringer@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/ovs-thread.c
lib/ovs-thread.h

index 4dfccaf..b6b51c7 100644 (file)
@@ -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;
+}
 \f
 DEFINE_EXTERN_PER_THREAD_DATA(ovsthread_id, 0);
 
index 2e9a937..8868c51 100644 (file)
@@ -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 *);