From ea6f3f9a49ad9d671fa226dd33a14b7f287c6602 Mon Sep 17 00:00:00 2001 From: Jarno Rajahalme Date: Tue, 4 Feb 2014 15:47:39 -0800 Subject: [PATCH] ovs-thread: Add support for pthread adaptive mutex Signed-off-by: Jarno Rajahalme Signed-off-by: Ben Pfaff --- lib/ovs-thread.c | 11 +++++++++++ lib/ovs-thread.h | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c index a20b2fd93..f0b1e9e81 100644 --- a/lib/ovs-thread.c +++ b/lib/ovs-thread.c @@ -168,6 +168,17 @@ ovs_mutex_init_recursive(const struct ovs_mutex *mutex) ovs_mutex_init__(mutex, PTHREAD_MUTEX_RECURSIVE); } +/* Initializes 'mutex' as a recursive mutex. */ +void +ovs_mutex_init_adaptive(const struct ovs_mutex *mutex) +{ +#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP + ovs_mutex_init__(mutex, PTHREAD_MUTEX_ADAPTIVE_NP); +#else + ovs_mutex_init(mutex); +#endif +} + void ovs_rwlock_init(const struct ovs_rwlock *l_) { diff --git a/lib/ovs-thread.h b/lib/ovs-thread.h index f0318948b..5c1e83903 100644 --- a/lib/ovs-thread.h +++ b/lib/ovs-thread.h @@ -37,6 +37,13 @@ struct OVS_LOCKABLE ovs_mutex { #define OVS_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, NULL } #endif +#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP +#define OVS_ADAPTIVE_MUTEX_INITIALIZER \ + { PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP, NULL } +#else +#define OVS_ADAPTIVE_MUTEX_INITIALIZER OVS_MUTEX_INITIALIZER +#endif + /* ovs_mutex functions analogous to pthread_mutex_*() functions. * * Most of these functions abort the process with an error message on any @@ -44,6 +51,7 @@ struct OVS_LOCKABLE ovs_mutex { * return value to the caller and aborts on any other error. */ void ovs_mutex_init(const struct ovs_mutex *); void ovs_mutex_init_recursive(const struct ovs_mutex *); +void ovs_mutex_init_adaptive(const struct ovs_mutex *); void ovs_mutex_destroy(const struct ovs_mutex *); void ovs_mutex_unlock(const struct ovs_mutex *mutex) OVS_RELEASES(mutex); void ovs_mutex_lock_at(const struct ovs_mutex *mutex, const char *where) -- 2.43.0