1 #ifndef __ASM_SPINLOCK_LOCK1_H
2 #define __ASM_SPINLOCK_LOCK1_H
5 #include <asm/global_lock.h>
7 static inline int arch_spin_is_locked(arch_spinlock_t *lock)
13 WARN_ON(ret != 0 && ret != 1);
17 static inline void arch_spin_lock(arch_spinlock_t *lock)
19 unsigned int we_won = 0;
23 __global_lock1(flags);
24 if (lock->lock == 0) {
29 __global_unlock1(flags);
32 WARN_ON(lock->lock != 1);
35 /* Returns 0 if failed to acquire lock */
36 static inline int arch_spin_trylock(arch_spinlock_t *lock)
41 __global_lock1(flags);
47 __global_unlock1(flags);
51 static inline void arch_spin_unlock(arch_spinlock_t *lock)
62 * Write locks are easy - we just set bit 31. When unlocking, we can
63 * just write zero since the lock is exclusively held.
66 static inline void arch_write_lock(arch_rwlock_t *rw)
69 unsigned int we_won = 0;
72 __global_lock1(flags);
75 rw->lock = 0x80000000;
78 __global_unlock1(flags);
81 WARN_ON(rw->lock != 0x80000000);
84 static inline int arch_write_trylock(arch_rwlock_t *rw)
89 __global_lock1(flags);
93 rw->lock = 0x80000000;
95 __global_unlock1(flags);
100 static inline void arch_write_unlock(arch_rwlock_t *rw)
103 WARN_ON(rw->lock != 0x80000000);
107 /* write_can_lock - would write_trylock() succeed? */
108 static inline int arch_write_can_lock(arch_rwlock_t *rw)
118 * Read locks are a bit more hairy:
119 * - Exclusively load the lock value.
121 * - Store new lock value if positive, and we still own this location.
122 * If the value is negative, we've already failed.
123 * - If we failed to store the value, we want a negative result.
124 * - If we failed, try again.
125 * Unlocking is similarly hairy. We may have multiple read locks
126 * currently active. However, we know we won't have any write
129 static inline void arch_read_lock(arch_rwlock_t *rw)
132 unsigned int we_won = 0, ret;
135 __global_lock1(flags);
137 if (ret < 0x80000000) {
142 __global_unlock1(flags);
147 static inline void arch_read_unlock(arch_rwlock_t *rw)
152 __global_lock1(flags);
155 __global_unlock1(flags);
159 static inline int arch_read_trylock(arch_rwlock_t *rw)
164 __global_lock1(flags);
166 if (ret < 0x80000000) {
170 __global_unlock1(flags);
171 return (ret < 0x80000000);
174 /* read_can_lock - would read_trylock() succeed? */
175 static inline int arch_read_can_lock(arch_rwlock_t *rw)
181 return (ret < 0x80000000);
184 #endif /* __ASM_SPINLOCK_LOCK1_H */