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