Add helpers to detect locked user spinlocks
authorBarret Rhoden <brho@cs.berkeley.edu>
Tue, 18 Aug 2015 19:25:21 +0000 (15:25 -0400)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 28 Sep 2015 19:14:00 +0000 (15:14 -0400)
Similar to the kernel's functions.  I use these on the user side of
CEQs.

user/parlib/include/spinlock.h
user/parlib/spinlock.c

index 822370e..50a3472 100644 (file)
@@ -37,6 +37,7 @@ void spinlock_init(spinlock_t *lock);
 int spinlock_trylock(spinlock_t *lock);
 void spinlock_lock(spinlock_t *lock);
 void spinlock_unlock(spinlock_t *lock);
+bool spinlock_locked(spinlock_t *lock);
 
 /* RISCV doesn't support CAS, so til it does, we use the NO_CAS, even if they
  * didn't ask for it in their config. */
@@ -74,6 +75,7 @@ typedef struct spin_pdr_lock spinpdrlock_t;
 void spin_pdr_init(struct spin_pdr_lock *pdr_lock);
 void spin_pdr_lock(struct spin_pdr_lock *pdr_lock);
 void spin_pdr_unlock(struct spin_pdr_lock *pdr_lock);
+bool spin_pdr_locked(struct spin_pdr_lock *pdr_lock);
 
 __END_DECLS
 
index 2ae1bb5..1338d5a 100644 (file)
@@ -50,6 +50,11 @@ void spinlock_unlock(spinlock_t *lock)
        __sync_lock_release(&lock->lock, 0);
 }
 
+bool spinlock_locked(spinlock_t *lock)
+{
+       return lock->lock != 0;
+}
+
 /* Two different versions, with and without CAS.  Default is with CAS. */
 #ifndef CONFIG_SPINPDR_NO_CAS /* CAS version */
 
@@ -82,6 +87,11 @@ void __spin_pdr_unlock(struct spin_pdr_lock *pdr_lock)
        pdr_lock->lock = SPINPDR_UNLOCKED;
 }
 
+bool spin_pdr_locked(struct spin_pdr_lock *pdr_lock)
+{
+       return pdr_lock->lock != SPINPDR_UNLOCKED;
+}
+
 #else /* NON-CAS version */
 
 /* Using regular spinlocks, with SPINPDR_VCOREID_UNKNOWN (-1) meaning 'no
@@ -115,6 +125,11 @@ void __spin_pdr_unlock(struct spin_pdr_lock *pdr_lock)
        spinlock_unlock(&pdr_lock->spinlock);
 }
 
+bool spin_pdr_locked(struct spin_pdr_lock *pdr_lock)
+{
+       return spinlock_locked(&pdr_lock->spinlock);
+}
+
 #endif /* CONFIG_SPINPDR_NO_CAS */
 
 void spin_pdr_lock(struct spin_pdr_lock *pdr_lock)