[ovs-dev] [PATCH 1/2] ovs-thread: Add support for pthread adaptive mutex

Jarno Rajahalme jrajahalme at nicira.com
Wed Feb 12 22:01:41 UTC 2014


Signed-off-by: Jarno Rajahalme <jrajahalme at nicira.com>
---
 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 a20b2fd..f0b1e9e 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 f031894..5c1e839 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)
-- 
1.7.10.4




More information about the dev mailing list