aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra
diff options
context:
space:
mode:
Diffstat (limited to 'src/vppinfra')
-rw-r--r--src/vppinfra/lock.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/vppinfra/lock.h b/src/vppinfra/lock.h
index 3cfe11cba17..470890b6ec7 100644
--- a/src/vppinfra/lock.h
+++ b/src/vppinfra/lock.h
@@ -91,6 +91,15 @@ clib_spinlock_lock (clib_spinlock_t * p)
CLIB_LOCK_DBG (p);
}
+static_always_inline int
+clib_spinlock_trylock (clib_spinlock_t * p)
+{
+ if (PREDICT_FALSE (CLIB_SPINLOCK_IS_LOCKED (p)))
+ return 0;
+ clib_spinlock_lock (p);
+ return 1;
+}
+
static_always_inline void
clib_spinlock_lock_if_init (clib_spinlock_t * p)
{
@@ -98,6 +107,14 @@ clib_spinlock_lock_if_init (clib_spinlock_t * p)
clib_spinlock_lock (p);
}
+static_always_inline int
+clib_spinlock_trylock_if_init (clib_spinlock_t * p)
+{
+ if (PREDICT_FALSE (*p != 0))
+ return clib_spinlock_trylock (p);
+ return 1;
+}
+
static_always_inline void
clib_spinlock_unlock (clib_spinlock_t * p)
{