spinlock.h (fb3a6bbc912b12347614e5742c7c61416cdb0ca0) | spinlock.h (e5931943d02bf751b1ec849c0d2ade23d76a8d41) |
---|---|
1#ifndef __ASM_SPINLOCK_H 2#define __ASM_SPINLOCK_H 3 4#include <asm/system.h> 5#include <asm/processor.h> 6#include <asm/spinlock_types.h> 7 8static inline int arch_spin_is_locked(arch_spinlock_t *x) --- 55 unchanged lines hidden (view full) --- 64 * Readers use the lock to serialise their access to the counter (which 65 * records how many readers currently hold the lock). 66 * Writers hold the spinlock, preventing any readers or other writers from 67 * grabbing the rwlock. 68 */ 69 70/* Note that we have to ensure interrupts are disabled in case we're 71 * interrupted by some other code that wants to grab the same read lock */ | 1#ifndef __ASM_SPINLOCK_H 2#define __ASM_SPINLOCK_H 3 4#include <asm/system.h> 5#include <asm/processor.h> 6#include <asm/spinlock_types.h> 7 8static inline int arch_spin_is_locked(arch_spinlock_t *x) --- 55 unchanged lines hidden (view full) --- 64 * Readers use the lock to serialise their access to the counter (which 65 * records how many readers currently hold the lock). 66 * Writers hold the spinlock, preventing any readers or other writers from 67 * grabbing the rwlock. 68 */ 69 70/* Note that we have to ensure interrupts are disabled in case we're 71 * interrupted by some other code that wants to grab the same read lock */ |
72static __inline__ void __raw_read_lock(arch_rwlock_t *rw) | 72static __inline__ void arch_read_lock(arch_rwlock_t *rw) |
73{ 74 unsigned long flags; 75 local_irq_save(flags); 76 arch_spin_lock_flags(&rw->lock, flags); 77 rw->counter++; 78 arch_spin_unlock(&rw->lock); 79 local_irq_restore(flags); 80} 81 82/* Note that we have to ensure interrupts are disabled in case we're 83 * interrupted by some other code that wants to grab the same read lock */ | 73{ 74 unsigned long flags; 75 local_irq_save(flags); 76 arch_spin_lock_flags(&rw->lock, flags); 77 rw->counter++; 78 arch_spin_unlock(&rw->lock); 79 local_irq_restore(flags); 80} 81 82/* Note that we have to ensure interrupts are disabled in case we're 83 * interrupted by some other code that wants to grab the same read lock */ |
84static __inline__ void __raw_read_unlock(arch_rwlock_t *rw) | 84static __inline__ void arch_read_unlock(arch_rwlock_t *rw) |
85{ 86 unsigned long flags; 87 local_irq_save(flags); 88 arch_spin_lock_flags(&rw->lock, flags); 89 rw->counter--; 90 arch_spin_unlock(&rw->lock); 91 local_irq_restore(flags); 92} 93 94/* Note that we have to ensure interrupts are disabled in case we're 95 * interrupted by some other code that wants to grab the same read lock */ | 85{ 86 unsigned long flags; 87 local_irq_save(flags); 88 arch_spin_lock_flags(&rw->lock, flags); 89 rw->counter--; 90 arch_spin_unlock(&rw->lock); 91 local_irq_restore(flags); 92} 93 94/* Note that we have to ensure interrupts are disabled in case we're 95 * interrupted by some other code that wants to grab the same read lock */ |
96static __inline__ int __raw_read_trylock(arch_rwlock_t *rw) | 96static __inline__ int arch_read_trylock(arch_rwlock_t *rw) |
97{ 98 unsigned long flags; 99 retry: 100 local_irq_save(flags); 101 if (arch_spin_trylock(&rw->lock)) { 102 rw->counter++; 103 arch_spin_unlock(&rw->lock); 104 local_irq_restore(flags); --- 9 unchanged lines hidden (view full) --- 114 while (arch_spin_is_locked(&rw->lock) && rw->counter >= 0) 115 cpu_relax(); 116 117 goto retry; 118} 119 120/* Note that we have to ensure interrupts are disabled in case we're 121 * interrupted by some other code that wants to read_trylock() this lock */ | 97{ 98 unsigned long flags; 99 retry: 100 local_irq_save(flags); 101 if (arch_spin_trylock(&rw->lock)) { 102 rw->counter++; 103 arch_spin_unlock(&rw->lock); 104 local_irq_restore(flags); --- 9 unchanged lines hidden (view full) --- 114 while (arch_spin_is_locked(&rw->lock) && rw->counter >= 0) 115 cpu_relax(); 116 117 goto retry; 118} 119 120/* Note that we have to ensure interrupts are disabled in case we're 121 * interrupted by some other code that wants to read_trylock() this lock */ |
122static __inline__ void __raw_write_lock(arch_rwlock_t *rw) | 122static __inline__ void arch_write_lock(arch_rwlock_t *rw) |
123{ 124 unsigned long flags; 125retry: 126 local_irq_save(flags); 127 arch_spin_lock_flags(&rw->lock, flags); 128 129 if (rw->counter != 0) { 130 arch_spin_unlock(&rw->lock); --- 5 unchanged lines hidden (view full) --- 136 goto retry; 137 } 138 139 rw->counter = -1; /* mark as write-locked */ 140 mb(); 141 local_irq_restore(flags); 142} 143 | 123{ 124 unsigned long flags; 125retry: 126 local_irq_save(flags); 127 arch_spin_lock_flags(&rw->lock, flags); 128 129 if (rw->counter != 0) { 130 arch_spin_unlock(&rw->lock); --- 5 unchanged lines hidden (view full) --- 136 goto retry; 137 } 138 139 rw->counter = -1; /* mark as write-locked */ 140 mb(); 141 local_irq_restore(flags); 142} 143 |
144static __inline__ void __raw_write_unlock(arch_rwlock_t *rw) | 144static __inline__ void arch_write_unlock(arch_rwlock_t *rw) |
145{ 146 rw->counter = 0; 147 arch_spin_unlock(&rw->lock); 148} 149 150/* Note that we have to ensure interrupts are disabled in case we're 151 * interrupted by some other code that wants to read_trylock() this lock */ | 145{ 146 rw->counter = 0; 147 arch_spin_unlock(&rw->lock); 148} 149 150/* Note that we have to ensure interrupts are disabled in case we're 151 * interrupted by some other code that wants to read_trylock() this lock */ |
152static __inline__ int __raw_write_trylock(arch_rwlock_t *rw) | 152static __inline__ int arch_write_trylock(arch_rwlock_t *rw) |
153{ 154 unsigned long flags; 155 int result = 0; 156 157 local_irq_save(flags); 158 if (arch_spin_trylock(&rw->lock)) { 159 if (rw->counter == 0) { 160 rw->counter = -1; --- 7 unchanged lines hidden (view full) --- 168 169 return result; 170} 171 172/* 173 * read_can_lock - would read_trylock() succeed? 174 * @lock: the rwlock in question. 175 */ | 153{ 154 unsigned long flags; 155 int result = 0; 156 157 local_irq_save(flags); 158 if (arch_spin_trylock(&rw->lock)) { 159 if (rw->counter == 0) { 160 rw->counter = -1; --- 7 unchanged lines hidden (view full) --- 168 169 return result; 170} 171 172/* 173 * read_can_lock - would read_trylock() succeed? 174 * @lock: the rwlock in question. 175 */ |
176static __inline__ int __raw_read_can_lock(arch_rwlock_t *rw) | 176static __inline__ int arch_read_can_lock(arch_rwlock_t *rw) |
177{ 178 return rw->counter >= 0; 179} 180 181/* 182 * write_can_lock - would write_trylock() succeed? 183 * @lock: the rwlock in question. 184 */ | 177{ 178 return rw->counter >= 0; 179} 180 181/* 182 * write_can_lock - would write_trylock() succeed? 183 * @lock: the rwlock in question. 184 */ |
185static __inline__ int __raw_write_can_lock(arch_rwlock_t *rw) | 185static __inline__ int arch_write_can_lock(arch_rwlock_t *rw) |
186{ 187 return !rw->counter; 188} 189 | 186{ 187 return !rw->counter; 188} 189 |
190#define __raw_read_lock_flags(lock, flags) __raw_read_lock(lock) 191#define __raw_write_lock_flags(lock, flags) __raw_write_lock(lock) | 190#define arch_read_lock_flags(lock, flags) arch_read_lock(lock) 191#define arch_write_lock_flags(lock, flags) arch_write_lock(lock) |
192 193#define arch_spin_relax(lock) cpu_relax() 194#define arch_read_relax(lock) cpu_relax() 195#define arch_write_relax(lock) cpu_relax() 196 197#endif /* __ASM_SPINLOCK_H */ | 192 193#define arch_spin_relax(lock) cpu_relax() 194#define arch_read_relax(lock) cpu_relax() 195#define arch_write_relax(lock) cpu_relax() 196 197#endif /* __ASM_SPINLOCK_H */ |