~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/rwlock.h

Version: ~ [ linux-5.6-rc1 ] ~ [ linux-5.5.2 ] ~ [ linux-5.4.17 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.102 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.170 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.213 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.213 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.81 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #ifndef __LINUX_RWLOCK_H
  2 #define __LINUX_RWLOCK_H
  3 
  4 #ifndef __LINUX_SPINLOCK_H
  5 # error "please don't 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)                                      \
 21 do {                                                            \
 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(lock);
 33 #define do_raw_read_lock_flags(lock, flags) do_raw_read_lock(lock)
 34  extern int do_raw_read_trylock(rwlock_t *lock);
 35  extern void do_raw_read_unlock(rwlock_t *lock) __releases(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)
 38  extern int do_raw_write_trylock(rwlock_t *lock);
 39  extern void do_raw_write_unlock(rwlock_t *lock) __releases(lock);
 40 #else
 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)
 51 #endif
 52 
 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)
 55 
 56 /*
 57  * Define the various rw_lock methods.  Note we define these
 58  * regardless of whether CONFIG_SMP or CONFIG_PREEMPT are set. The various
 59  * methods are defined as nops in the case they are not required.
 60  */
 61 #define read_trylock(lock)      __cond_lock(lock, _raw_read_trylock(lock))
 62 #define write_trylock(lock)     __cond_lock(lock, _raw_write_trylock(lock))
 63 
 64 #define write_lock(lock)        _raw_write_lock(lock)
 65 #define read_lock(lock)         _raw_read_lock(lock)
 66 
 67 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
 68 
 69 #define read_lock_irqsave(lock, flags)                  \
 70         do {                                            \
 71                 typecheck(unsigned long, flags);        \
 72                 flags = _raw_read_lock_irqsave(lock);   \
 73         } while (0)
 74 #define write_lock_irqsave(lock, flags)                 \
 75         do {                                            \
 76                 typecheck(unsigned long, flags);        \
 77                 flags = _raw_write_lock_irqsave(lock);  \
 78         } while (0)
 79 
 80 #else
 81 
 82 #define read_lock_irqsave(lock, flags)                  \
 83         do {                                            \
 84                 typecheck(unsigned long, flags);        \
 85                 _raw_read_lock_irqsave(lock, flags);    \
 86         } while (0)
 87 #define write_lock_irqsave(lock, flags)                 \
 88         do {                                            \
 89                 typecheck(unsigned long, flags);        \
 90                 _raw_write_lock_irqsave(lock, flags);   \
 91         } while (0)
 92 
 93 #endif
 94 
 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)
103 
104 #define read_unlock_irqrestore(lock, flags)                     \
105         do {                                                    \
106                 typecheck(unsigned long, flags);                \
107                 _raw_read_unlock_irqrestore(lock, flags);       \
108         } while (0)
109 #define read_unlock_bh(lock)            _raw_read_unlock_bh(lock)
110 
111 #define write_unlock_irqrestore(lock, flags)            \
112         do {                                            \
113                 typecheck(unsigned long, flags);        \
114                 _raw_write_unlock_irqrestore(lock, flags);      \
115         } while (0)
116 #define write_unlock_bh(lock)           _raw_write_unlock_bh(lock)
117 
118 #define write_trylock_irqsave(lock, flags) \
119 ({ \
120         local_irq_save(flags); \
121         write_trylock(lock) ? \
122         1 : ({ local_irq_restore(flags); 0; }); \
123 })
124 
125 #endif /* __LINUX_RWLOCK_H */
126 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp