Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 1 | #ifndef __LINUX_SPINLOCK_UP_H |
| 2 | #define __LINUX_SPINLOCK_UP_H |
| 3 | |
| 4 | #ifndef __LINUX_SPINLOCK_H |
| 5 | # error "please don't include this file directly" |
| 6 | #endif |
| 7 | |
| 8 | /* |
| 9 | * include/linux/spinlock_up.h - UP-debug version of spinlocks. |
| 10 | * |
| 11 | * portions Copyright 2005, Red Hat, Inc., Ingo Molnar |
| 12 | * Released under the General Public License (GPL). |
| 13 | * |
| 14 | * In the debug case, 1 means unlocked, 0 means locked. (the values |
| 15 | * are inverted, to catch initialization bugs) |
| 16 | * |
| 17 | * No atomicity anywhere, we are on UP. |
| 18 | */ |
| 19 | |
| 20 | #ifdef CONFIG_DEBUG_SPINLOCK |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 21 | #define arch_spin_is_locked(x) ((x)->slock == 0) |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 22 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 23 | static inline void arch_spin_lock(arch_spinlock_t *lock) |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 24 | { |
| 25 | lock->slock = 0; |
| 26 | } |
| 27 | |
| 28 | static inline void |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 29 | arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags) |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 30 | { |
| 31 | local_irq_save(flags); |
| 32 | lock->slock = 0; |
| 33 | } |
| 34 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 35 | static inline int arch_spin_trylock(arch_spinlock_t *lock) |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 36 | { |
| 37 | char oldval = lock->slock; |
| 38 | |
| 39 | lock->slock = 0; |
| 40 | |
| 41 | return oldval > 0; |
| 42 | } |
| 43 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 44 | static inline void arch_spin_unlock(arch_spinlock_t *lock) |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 45 | { |
| 46 | lock->slock = 1; |
| 47 | } |
| 48 | |
| 49 | /* |
| 50 | * Read-write spinlocks. No debug version. |
| 51 | */ |
Thomas Gleixner | e593194 | 2009-12-03 20:08:46 +0100 | [diff] [blame] | 52 | #define arch_read_lock(lock) do { (void)(lock); } while (0) |
| 53 | #define arch_write_lock(lock) do { (void)(lock); } while (0) |
| 54 | #define arch_read_trylock(lock) ({ (void)(lock); 1; }) |
| 55 | #define arch_write_trylock(lock) ({ (void)(lock); 1; }) |
| 56 | #define arch_read_unlock(lock) do { (void)(lock); } while (0) |
| 57 | #define arch_write_unlock(lock) do { (void)(lock); } while (0) |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 58 | |
| 59 | #else /* DEBUG_SPINLOCK */ |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 60 | #define arch_spin_is_locked(lock) ((void)(lock), 0) |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 61 | /* for sched.c and kernel_lock.c: */ |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 62 | # define arch_spin_lock(lock) do { (void)(lock); } while (0) |
| 63 | # define arch_spin_lock_flags(lock, flags) do { (void)(lock); } while (0) |
| 64 | # define arch_spin_unlock(lock) do { (void)(lock); } while (0) |
| 65 | # define arch_spin_trylock(lock) ({ (void)(lock); 1; }) |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 66 | #endif /* DEBUG_SPINLOCK */ |
| 67 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 68 | #define arch_spin_is_contended(lock) (((void)(lock), 0)) |
Nick Piggin | 95c354f | 2008-01-30 13:31:20 +0100 | [diff] [blame] | 69 | |
Thomas Gleixner | e593194 | 2009-12-03 20:08:46 +0100 | [diff] [blame] | 70 | #define arch_read_can_lock(lock) (((void)(lock), 1)) |
| 71 | #define arch_write_can_lock(lock) (((void)(lock), 1)) |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 72 | |
Thomas Gleixner | 0199c4e | 2009-12-02 20:01:25 +0100 | [diff] [blame] | 73 | #define arch_spin_unlock_wait(lock) \ |
| 74 | do { cpu_relax(); } while (arch_spin_is_locked(lock)) |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 75 | |
| 76 | #endif /* __LINUX_SPINLOCK_UP_H */ |