Go to the documentation of this file. 1 #ifndef __LINUX_RWLOCK_H
2 #define __LINUX_RWLOCK_H
4 #ifndef __LINUX_SPINLOCK_H
5 # error "please don't include this file directly"
17 #ifdef CONFIG_DEBUG_SPINLOCK
20 # define rwlock_init(lock) \
22 static struct lock_class_key __key; \
24 __rwlock_init((lock), #lock, &__key); \
27 # define rwlock_init(lock) \
28 do { *(lock) = __RW_LOCK_UNLOCKED(lock); } while (0)
31 #ifdef CONFIG_DEBUG_SPINLOCK
33 #define do_raw_read_lock_flags(lock, flags) do_raw_read_lock(lock)
37 #define do_raw_write_lock_flags(lock, flags) do_raw_write_lock(lock)
41 # define do_raw_read_lock(rwlock) do {__acquire(lock); arch_read_lock(&(rwlock)->raw_lock); } while (0)
42 # define do_raw_read_lock_flags(lock, flags) \
43 do {__acquire(lock); arch_read_lock_flags(&(lock)->raw_lock, *(flags)); } while (0)
44 # define do_raw_read_trylock(rwlock) arch_read_trylock(&(rwlock)->raw_lock)
45 # define do_raw_read_unlock(rwlock) do {arch_read_unlock(&(rwlock)->raw_lock); __release(lock); } while (0)
46 # define do_raw_write_lock(rwlock) do {__acquire(lock); arch_write_lock(&(rwlock)->raw_lock); } while (0)
47 # define do_raw_write_lock_flags(lock, flags) \
48 do {__acquire(lock); arch_write_lock_flags(&(lock)->raw_lock, *(flags)); } while (0)
49 # define do_raw_write_trylock(rwlock) arch_write_trylock(&(rwlock)->raw_lock)
50 # define do_raw_write_unlock(rwlock) do {arch_write_unlock(&(rwlock)->raw_lock); __release(lock); } while (0)
53 #define read_can_lock(rwlock) arch_read_can_lock(&(rwlock)->raw_lock)
54 #define write_can_lock(rwlock) arch_write_can_lock(&(rwlock)->raw_lock)
61 #define read_trylock(lock) __cond_lock(lock, _raw_read_trylock(lock))
62 #define write_trylock(lock) __cond_lock(lock, _raw_write_trylock(lock))
64 #define write_lock(lock) _raw_write_lock(lock)
65 #define read_lock(lock) _raw_read_lock(lock)
67 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
69 #define read_lock_irqsave(lock, flags) \
71 typecheck(unsigned long, flags); \
72 flags = _raw_read_lock_irqsave(lock); \
74 #define write_lock_irqsave(lock, flags) \
76 typecheck(unsigned long, flags); \
77 flags = _raw_write_lock_irqsave(lock); \
82 #define read_lock_irqsave(lock, flags) \
84 typecheck(unsigned long, flags); \
85 _raw_read_lock_irqsave(lock, flags); \
87 #define write_lock_irqsave(lock, flags) \
89 typecheck(unsigned long, flags); \
90 _raw_write_lock_irqsave(lock, flags); \
95 #define read_lock_irq(lock) _raw_read_lock_irq(lock)
96 #define read_lock_bh(lock) _raw_read_lock_bh(lock)
97 #define write_lock_irq(lock) _raw_write_lock_irq(lock)
98 #define write_lock_bh(lock) _raw_write_lock_bh(lock)
99 #define read_unlock(lock) _raw_read_unlock(lock)
100 #define write_unlock(lock) _raw_write_unlock(lock)
101 #define read_unlock_irq(lock) _raw_read_unlock_irq(lock)
102 #define write_unlock_irq(lock) _raw_write_unlock_irq(lock)
104 #define read_unlock_irqrestore(lock, flags) \
106 typecheck(unsigned long, flags); \
107 _raw_read_unlock_irqrestore(lock, flags); \
109 #define read_unlock_bh(lock) _raw_read_unlock_bh(lock)
111 #define write_unlock_irqrestore(lock, flags) \
113 typecheck(unsigned long, flags); \
114 _raw_write_unlock_irqrestore(lock, flags); \
116 #define write_unlock_bh(lock) _raw_write_unlock_bh(lock)
118 #define write_trylock_irqsave(lock, flags) \
120 local_irq_save(flags); \
121 write_trylock(lock) ? \
122 1 : ({ local_irq_restore(flags); 0; }); \