Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 6fdca3c5ab55d6a74277efcae2db9828f567a06a 134 lines 4.4 kB view raw
1#ifndef __LINUX_RWLOCK_H 2#define __LINUX_RWLOCK_H 3 4#ifndef __LINUX_INSIDE_SPINLOCK_H 5# error "Please do not include this file directly." 6#endif 7 8/* 9 * rwlock related methods 10 * 11 * split out from spinlock.h 12 * 13 * portions Copyright 2005, Red Hat, Inc., Ingo Molnar 14 * Released under the General Public License (GPL). 15 */ 16 17#ifdef CONFIG_DEBUG_SPINLOCK 18 extern void __rwlock_init(rwlock_t *lock, const char *name, 19 struct lock_class_key *key); 20# define rwlock_init(lock) \ 21do { \ 22 static struct lock_class_key __key; \ 23 \ 24 __rwlock_init((lock), #lock, &__key); \ 25} while (0) 26#else 27# define rwlock_init(lock) \ 28 do { *(lock) = __RW_LOCK_UNLOCKED(lock); } while (0) 29#endif 30 31#ifdef CONFIG_DEBUG_SPINLOCK 32 extern void do_raw_read_lock(rwlock_t *lock) __acquires_shared(lock); 33 extern int do_raw_read_trylock(rwlock_t *lock) __cond_acquires_shared(true, lock); 34 extern void do_raw_read_unlock(rwlock_t *lock) __releases_shared(lock); 35 extern void do_raw_write_lock(rwlock_t *lock) __acquires(lock); 36extern int do_raw_write_trylock(rwlock_t *lock) __cond_acquires(true, lock); 37 extern void do_raw_write_unlock(rwlock_t *lock) __releases(lock); 38#else 39# define do_raw_read_lock(rwlock) do {__acquire_shared(lock); arch_read_lock(&(rwlock)->raw_lock); } while (0) 40static inline int do_raw_read_trylock(rwlock_t *rwlock) 41 __cond_acquires_shared(true, rwlock) 42 __no_context_analysis 43{ 44 return arch_read_trylock(&(rwlock)->raw_lock); 45} 46# define do_raw_read_unlock(rwlock) do {arch_read_unlock(&(rwlock)->raw_lock); __release_shared(lock); } while (0) 47# define do_raw_write_lock(rwlock) do {__acquire(lock); arch_write_lock(&(rwlock)->raw_lock); } while (0) 48static inline int do_raw_write_trylock(rwlock_t *rwlock) 49 __cond_acquires(true, rwlock) 50 __no_context_analysis 51{ 52 return arch_write_trylock(&(rwlock)->raw_lock); 53} 54# define do_raw_write_unlock(rwlock) do {arch_write_unlock(&(rwlock)->raw_lock); __release(lock); } while (0) 55#endif 56 57/* 58 * Define the various rw_lock methods. Note we define these 59 * regardless of whether CONFIG_SMP or CONFIG_PREEMPT are set. The various 60 * methods are defined as nops in the case they are not required. 61 */ 62#define read_trylock(lock) _raw_read_trylock(lock) 63#define write_trylock(lock) _raw_write_trylock(lock) 64 65#define write_lock(lock) _raw_write_lock(lock) 66#define read_lock(lock) _raw_read_lock(lock) 67 68#ifdef CONFIG_DEBUG_LOCK_ALLOC 69#define write_lock_nested(lock, subclass) _raw_write_lock_nested(lock, subclass) 70#else 71#define write_lock_nested(lock, subclass) _raw_write_lock(lock) 72#endif 73 74#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) 75 76#define read_lock_irqsave(lock, flags) \ 77 do { \ 78 typecheck(unsigned long, flags); \ 79 flags = _raw_read_lock_irqsave(lock); \ 80 } while (0) 81#define write_lock_irqsave(lock, flags) \ 82 do { \ 83 typecheck(unsigned long, flags); \ 84 flags = _raw_write_lock_irqsave(lock); \ 85 } while (0) 86 87#else 88 89#define read_lock_irqsave(lock, flags) \ 90 do { \ 91 typecheck(unsigned long, flags); \ 92 _raw_read_lock_irqsave(lock, flags); \ 93 } while (0) 94#define write_lock_irqsave(lock, flags) \ 95 do { \ 96 typecheck(unsigned long, flags); \ 97 _raw_write_lock_irqsave(lock, flags); \ 98 } while (0) 99 100#endif 101 102#define read_lock_irq(lock) _raw_read_lock_irq(lock) 103#define read_lock_bh(lock) _raw_read_lock_bh(lock) 104#define write_lock_irq(lock) _raw_write_lock_irq(lock) 105#define write_lock_bh(lock) _raw_write_lock_bh(lock) 106#define read_unlock(lock) _raw_read_unlock(lock) 107#define write_unlock(lock) _raw_write_unlock(lock) 108#define read_unlock_irq(lock) _raw_read_unlock_irq(lock) 109#define write_unlock_irq(lock) _raw_write_unlock_irq(lock) 110 111#define read_unlock_irqrestore(lock, flags) \ 112 do { \ 113 typecheck(unsigned long, flags); \ 114 _raw_read_unlock_irqrestore(lock, flags); \ 115 } while (0) 116#define read_unlock_bh(lock) _raw_read_unlock_bh(lock) 117 118#define write_unlock_irqrestore(lock, flags) \ 119 do { \ 120 typecheck(unsigned long, flags); \ 121 _raw_write_unlock_irqrestore(lock, flags); \ 122 } while (0) 123#define write_unlock_bh(lock) _raw_write_unlock_bh(lock) 124 125#define write_trylock_irqsave(lock, flags) _raw_write_trylock_irqsave(lock, &(flags)) 126 127#ifdef arch_rwlock_is_contended 128#define rwlock_is_contended(lock) \ 129 arch_rwlock_is_contended(&(lock)->raw_lock) 130#else 131#define rwlock_is_contended(lock) ((void)(lock), 0) 132#endif /* arch_rwlock_is_contended */ 133 134#endif /* __LINUX_RWLOCK_H */