diff options
author | William Tu <u9012063@gmail.com> | 2019-07-17 13:23:33 -0700 |
---|---|---|
committer | Ilya Maximets <i.maximets@samsung.com> | 2019-07-19 15:14:18 +0300 |
commit | 884ca8aceb0cbb5dc8ca3d124a59157ef2b941cf (patch) | |
tree | f6f2c858d08af711de5f48e8ca89df871c3925c1 /include/openvswitch | |
parent | ce2c1065c269fe45609cab43df3f23f42079078f (diff) | |
download | openvswitch-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 'include/openvswitch')
-rw-r--r-- | include/openvswitch/thread.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/include/openvswitch/thread.h b/include/openvswitch/thread.h index 2987db37c..acc822904 100644 --- a/include/openvswitch/thread.h +++ b/include/openvswitch/thread.h @@ -33,6 +33,13 @@ struct OVS_LOCKABLE ovs_mutex { const char *where; /* NULL if and only if uninitialized. */ }; +#ifdef HAVE_PTHREAD_SPIN_LOCK +struct OVS_LOCKABLE ovs_spin { + pthread_spinlock_t lock; + const char *where; /* NULL if and only if uninitialized. */ +}; +#endif + /* "struct ovs_mutex" initializer. */ #ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP #define OVS_MUTEX_INITIALIZER { PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP, \ @@ -70,6 +77,21 @@ int ovs_mutex_trylock_at(const struct ovs_mutex *mutex, const char *where) void ovs_mutex_cond_wait(pthread_cond_t *, const struct ovs_mutex *mutex) OVS_REQUIRES(mutex); + +#ifdef HAVE_PTHREAD_SPIN_LOCK +void ovs_spin_init(const struct ovs_spin *); +void ovs_spin_destroy(const struct ovs_spin *); +void ovs_spin_unlock(const struct ovs_spin *spin) OVS_RELEASES(spin); +void ovs_spin_lock_at(const struct ovs_spin *spin, const char *where) + OVS_ACQUIRES(spin); +#define ovs_spin_lock(spin) \ + ovs_spin_lock_at(spin, OVS_SOURCE_LOCATOR) + +int ovs_spin_trylock_at(const struct ovs_spin *spin, const char *where) + OVS_TRY_LOCK(0, spin); +#define ovs_spin_trylock(spin) \ + ovs_spin_trylock_at(spin, OVS_SOURCE_LOCATOR) +#endif /* Convenient once-only execution. * |