diff options
author | Richard Braun <rbraun@sceen.net> | 2013-04-03 20:58:54 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2013-04-03 20:58:54 +0200 |
commit | 9ca509a21cdb2ee412b62ba264704ce0d7fda4c4 (patch) | |
tree | c686e8792ce70ada2694af958696c11008389bba | |
parent | 5f0401fd56a2dc980def9c381a8248a5b61c45a9 (diff) |
kern/spinlock: change the interface of trylock functions
Make trylock functions behave as error-returning functions.
-rw-r--r-- | kern/spinlock.h | 18 | ||||
-rw-r--r-- | kern/spinlock_i.h | 6 |
2 files changed, 12 insertions, 12 deletions
diff --git a/kern/spinlock.h b/kern/spinlock.h index cbd95458..8d20db4f 100644 --- a/kern/spinlock.h +++ b/kern/spinlock.h @@ -45,20 +45,20 @@ spinlock_assert_locked(struct spinlock *lock) } /* - * Return true if acquired, false if busy. + * Return 0 on success, 1 if busy. */ static inline int spinlock_trylock(struct spinlock *lock) { - int acquired; + int busy; thread_preempt_disable(); - acquired = spinlock_tryacquire(lock); + busy = spinlock_tryacquire(lock); - if (!acquired) + if (busy) thread_preempt_enable(); - return acquired; + return busy; } static inline void @@ -83,18 +83,18 @@ spinlock_unlock(struct spinlock *lock) static inline int spinlock_trylock_intr_save(struct spinlock *lock, unsigned long *flags) { - int acquired; + int busy; thread_preempt_disable(); *flags = cpu_intr_save(); - acquired = spinlock_tryacquire(lock); + busy = spinlock_tryacquire(lock); - if (!acquired) { + if (busy) { cpu_intr_restore(*flags); thread_preempt_enable(); } - return acquired; + return busy; } static inline void diff --git a/kern/spinlock_i.h b/kern/spinlock_i.h index 58af6bf1..e0d88ba9 100644 --- a/kern/spinlock_i.h +++ b/kern/spinlock_i.h @@ -33,18 +33,18 @@ struct spinlock { }; /* - * Return true if acquired, false if busy. + * Return 0 on success, 1 if busy. */ static inline int spinlock_tryacquire(struct spinlock *lock) { - return !atomic_cas(&lock->locked, 0, 1); + return atomic_cas(&lock->locked, 0, 1); } static inline void spinlock_acquire(struct spinlock *lock) { - while (!spinlock_tryacquire(lock)) + while (spinlock_tryacquire(lock)) cpu_pause(); } |