From 0231b68a8b0ef60d905d4fc7acdf7bc3e20e6cc1 Mon Sep 17 00:00:00 2001 From: Samy Al Bahra Date: Fri, 11 Nov 2011 21:54:38 +0000 Subject: [PATCH] ck_spinlock: Add ck_spinlock_*_locked. This class of functions detects whether or not the lock is currently acquired. --- include/ck_spinlock.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/ck_spinlock.h b/include/ck_spinlock.h index 3955068..d1cc03c 100644 --- a/include/ck_spinlock.h +++ b/include/ck_spinlock.h @@ -177,6 +177,13 @@ ck_spinlock_fas_trylock(struct ck_spinlock_fas *lock) return (!value); } +CK_CC_INLINE static bool +ck_spinlock_fas_locked(struct ck_spinlock_fas *lock) +{ + + return ck_pr_load_uint(&lock->value); +} + CK_CC_INLINE static void ck_spinlock_fas_lock(struct ck_spinlock_fas *lock) { @@ -239,6 +246,13 @@ ck_spinlock_cas_trylock(struct ck_spinlock_cas *lock) return (!value); } +CK_CC_INLINE static bool +ck_spinlock_cas_locked(struct ck_spinlock_cas *lock) +{ + + return ck_pr_load_uint(&lock->value); +} + CK_CC_INLINE static void ck_spinlock_cas_lock(struct ck_spinlock_cas *lock) { @@ -297,6 +311,13 @@ ck_spinlock_dec_trylock(struct ck_spinlock_dec *lock) return (value == 1); } +CK_CC_INLINE static bool +ck_spinlock_dec_locked(struct ck_spinlock_dec *lock) +{ + + return ck_pr_load_uint(&lock->value) != 1; +} + CK_CC_INLINE static void ck_spinlock_dec_lock(struct ck_spinlock_dec *lock) { @@ -470,6 +491,13 @@ ck_spinlock_mcs_trylock(struct ck_spinlock_mcs **queue, struct ck_spinlock_mcs * return ck_pr_cas_ptr(queue, NULL, node); } +CK_CC_INLINE static bool +ck_spinlock_mcs_locked(struct ck_spinlock_mcs **queue) +{ + + return ck_pr_load_ptr(queue) != NULL; +} + CK_CC_INLINE static void ck_spinlock_mcs_lock(struct ck_spinlock_mcs **queue, struct ck_spinlock_mcs *node) {