summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWilliam Tu <u9012063@gmail.com>2019-07-17 13:23:33 -0700
committerIlya Maximets <i.maximets@samsung.com>2019-07-19 15:14:18 +0300
commit884ca8aceb0cbb5dc8ca3d124a59157ef2b941cf (patch)
treef6f2c858d08af711de5f48e8ca89df871c3925c1 /lib
parentce2c1065c269fe45609cab43df3f23f42079078f (diff)
downloadopenvswitch-884ca8aceb0cbb5dc8ca3d124a59157ef2b941cf.tar.gz
ovs-thread: Add pthread spin lock support.
The patch adds the basic spin lock functions: ovs_spin_{lock, try_lock, unlock, init, destroy}. Signed-off-by: William Tu <u9012063@gmail.com> Acked-by: Ilya Maximets <i.maximets@samsung.com> Acked-by: Ben Pfaff <blp@ovn.org> Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/ovs-thread.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c
index 159d87e5b..b686e4548 100644
--- a/lib/ovs-thread.c
+++ b/lib/ovs-thread.c
@@ -75,6 +75,9 @@ static bool multithreaded;
LOCK_FUNCTION(mutex, lock);
LOCK_FUNCTION(rwlock, rdlock);
LOCK_FUNCTION(rwlock, wrlock);
+#ifdef HAVE_PTHREAD_SPIN_LOCK
+LOCK_FUNCTION(spin, lock);
+#endif
#define TRY_LOCK_FUNCTION(TYPE, FUN) \
int \
@@ -103,6 +106,9 @@ LOCK_FUNCTION(rwlock, wrlock);
TRY_LOCK_FUNCTION(mutex, trylock);
TRY_LOCK_FUNCTION(rwlock, tryrdlock);
TRY_LOCK_FUNCTION(rwlock, trywrlock);
+#ifdef HAVE_PTHREAD_SPIN_LOCK
+TRY_LOCK_FUNCTION(spin, trylock);
+#endif
#define UNLOCK_FUNCTION(TYPE, FUN, WHERE) \
void \
@@ -125,6 +131,10 @@ UNLOCK_FUNCTION(mutex, unlock, "<unlocked>");
UNLOCK_FUNCTION(mutex, destroy, NULL);
UNLOCK_FUNCTION(rwlock, unlock, "<unlocked>");
UNLOCK_FUNCTION(rwlock, destroy, NULL);
+#ifdef HAVE_PTHREAD_SPIN_LOCK
+UNLOCK_FUNCTION(spin, unlock, "<unlocked>");
+UNLOCK_FUNCTION(spin, destroy, NULL);
+#endif
#define XPTHREAD_FUNC1(FUNCTION, PARAM1) \
void \
@@ -268,6 +278,27 @@ ovs_mutex_cond_wait(pthread_cond_t *cond, const struct ovs_mutex *mutex_)
}
}
+#ifdef HAVE_PTHREAD_SPIN_LOCK
+static void
+ovs_spin_init__(const struct ovs_spin *l_, int pshared)
+{
+ struct ovs_spin *l = CONST_CAST(struct ovs_spin *, l_);
+ int error;
+
+ l->where = "<unlocked>";
+ error = pthread_spin_init(&l->lock, pshared);
+ if (OVS_UNLIKELY(error)) {
+ ovs_abort(error, "pthread_spin_init failed");
+ }
+}
+
+void
+ovs_spin_init(const struct ovs_spin *spin)
+{
+ ovs_spin_init__(spin, PTHREAD_PROCESS_PRIVATE);
+}
+#endif
+
/* Initializes the 'barrier'. 'size' is the number of threads
* expected to hit the barrier. */
void