The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | **************************************************************************** |
| 3 | *** |
| 4 | *** This header was automatically generated from a Linux kernel header |
| 5 | *** of the same name, to make information necessary for userspace to |
| 6 | *** call into the kernel available to libc. It contains only constants, |
| 7 | *** structures, and macros generated from the original header, and thus, |
| 8 | *** contains no copyrightable information. |
| 9 | *** |
| 10 | **************************************************************************** |
| 11 | ****************************************************************************/ |
| 12 | #ifndef __LINUX_SPINLOCK_H |
| 13 | #define __LINUX_SPINLOCK_H |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 14 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 15 | #include <linux/preempt.h> |
| 16 | #include <linux/linkage.h> |
| 17 | #include <linux/compiler.h> |
| 18 | #include <linux/thread_info.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/stringify.h> |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 21 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 22 | #include <asm/system.h> |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 23 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 24 | #define LOCK_SECTION_NAME ".text.lock."KBUILD_BASENAME |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 25 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 26 | #define LOCK_SECTION_START(extra) ".subsection 1\n\t" extra ".ifndef " LOCK_SECTION_NAME "\n\t" LOCK_SECTION_NAME ":\n\t" ".endif\n" |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 27 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 28 | #define LOCK_SECTION_END ".previous\n\t" |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 29 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 30 | #define __lockfunc fastcall __attribute__((section(".spinlock.text"))) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 31 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 32 | #include <linux/spinlock_types.h> |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 33 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 34 | #include <linux/spinlock_up.h> |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 35 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 36 | #define spin_lock_init(lock) do { *(lock) = SPIN_LOCK_UNLOCKED; } while (0) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 37 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 38 | #define rwlock_init(lock) do { *(lock) = RW_LOCK_UNLOCKED; } while (0) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 39 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 40 | #define spin_is_locked(lock) __raw_spin_is_locked(&(lock)->raw_lock) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 41 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 42 | #define spin_unlock_wait(lock) __raw_spin_unlock_wait(&(lock)->raw_lock) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 43 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 44 | #include <linux/spinlock_api_up.h> |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 45 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 46 | #define _raw_spin_lock(lock) __raw_spin_lock(&(lock)->raw_lock) |
| 47 | #define _raw_spin_lock_flags(lock, flags) __raw_spin_lock_flags(&(lock)->raw_lock, *(flags)) |
| 48 | #define _raw_spin_trylock(lock) __raw_spin_trylock(&(lock)->raw_lock) |
| 49 | #define _raw_spin_unlock(lock) __raw_spin_unlock(&(lock)->raw_lock) |
| 50 | #define _raw_read_lock(rwlock) __raw_read_lock(&(rwlock)->raw_lock) |
| 51 | #define _raw_read_trylock(rwlock) __raw_read_trylock(&(rwlock)->raw_lock) |
| 52 | #define _raw_read_unlock(rwlock) __raw_read_unlock(&(rwlock)->raw_lock) |
| 53 | #define _raw_write_lock(rwlock) __raw_write_lock(&(rwlock)->raw_lock) |
| 54 | #define _raw_write_trylock(rwlock) __raw_write_trylock(&(rwlock)->raw_lock) |
| 55 | #define _raw_write_unlock(rwlock) __raw_write_unlock(&(rwlock)->raw_lock) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 56 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 57 | #define read_can_lock(rwlock) __raw_read_can_lock(&(rwlock)->raw_lock) |
| 58 | #define write_can_lock(rwlock) __raw_write_can_lock(&(rwlock)->raw_lock) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 59 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 60 | #define spin_trylock(lock) __cond_lock(_spin_trylock(lock)) |
| 61 | #define read_trylock(lock) __cond_lock(_read_trylock(lock)) |
| 62 | #define write_trylock(lock) __cond_lock(_write_trylock(lock)) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 63 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 64 | #define spin_lock(lock) _spin_lock(lock) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 65 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 66 | #define spin_lock_nested(lock, subclass) _spin_lock(lock) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 67 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 68 | #define write_lock(lock) _write_lock(lock) |
| 69 | #define read_lock(lock) _read_lock(lock) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 70 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 71 | #define spin_lock_irqsave(lock, flags) _spin_lock_irqsave(lock, flags) |
| 72 | #define read_lock_irqsave(lock, flags) _read_lock_irqsave(lock, flags) |
| 73 | #define write_lock_irqsave(lock, flags) _write_lock_irqsave(lock, flags) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 74 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 75 | #define spin_lock_irq(lock) _spin_lock_irq(lock) |
| 76 | #define spin_lock_bh(lock) _spin_lock_bh(lock) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 77 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 78 | #define read_lock_irq(lock) _read_lock_irq(lock) |
| 79 | #define read_lock_bh(lock) _read_lock_bh(lock) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 80 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 81 | #define write_lock_irq(lock) _write_lock_irq(lock) |
| 82 | #define write_lock_bh(lock) _write_lock_bh(lock) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 83 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 84 | #define spin_unlock(lock) _spin_unlock(lock) |
| 85 | #define read_unlock(lock) _read_unlock(lock) |
| 86 | #define write_unlock(lock) _write_unlock(lock) |
| 87 | #define spin_unlock_irq(lock) _spin_unlock_irq(lock) |
| 88 | #define read_unlock_irq(lock) _read_unlock_irq(lock) |
| 89 | #define write_unlock_irq(lock) _write_unlock_irq(lock) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 90 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 91 | #define spin_unlock_irqrestore(lock, flags) _spin_unlock_irqrestore(lock, flags) |
| 92 | #define spin_unlock_bh(lock) _spin_unlock_bh(lock) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 93 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 94 | #define read_unlock_irqrestore(lock, flags) _read_unlock_irqrestore(lock, flags) |
| 95 | #define read_unlock_bh(lock) _read_unlock_bh(lock) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 96 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 97 | #define write_unlock_irqrestore(lock, flags) _write_unlock_irqrestore(lock, flags) |
| 98 | #define write_unlock_bh(lock) _write_unlock_bh(lock) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 99 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 100 | #define spin_trylock_bh(lock) __cond_lock(_spin_trylock_bh(lock)) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 101 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 102 | #define spin_trylock_irq(lock) ({ local_irq_disable(); _spin_trylock(lock) ? 1 : ({ local_irq_enable(); 0; }); }) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 103 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 104 | #define spin_trylock_irqsave(lock, flags) ({ local_irq_save(flags); _spin_trylock(lock) ? 1 : ({ local_irq_restore(flags); 0; }); }) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 105 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 106 | #include <asm/atomic.h> |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 107 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 108 | #define atomic_dec_and_lock(atomic, lock) __cond_lock(_atomic_dec_and_lock(atomic, lock)) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 109 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 110 | #define spin_can_lock(lock) (!spin_is_locked(lock)) |
Ben Cheng | 4b29af0 | 2012-03-07 16:14:53 -0800 | [diff] [blame^] | 111 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 112 | #endif |