1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _LINUX_LOCAL_LOCK_H 3 #define _LINUX_LOCAL_LOCK_H 4 5 #include <linux/local_lock_internal.h> 6 7 /** 8 * local_lock_init - Runtime initialize a lock instance 9 */ 10 #define local_lock_init(lock) __local_lock_init(lock) 11 12 /** 13 * local_lock - Acquire a per CPU local lock 14 * @lock: The lock variable 15 */ 16 #define local_lock(lock) __local_lock(lock) 17 18 /** 19 * local_lock_irq - Acquire a per CPU local lock and disable interrupts 20 * @lock: The lock variable 21 */ 22 #define local_lock_irq(lock) __local_lock_irq(lock) 23 24 /** 25 * local_lock_irqsave - Acquire a per CPU local lock, save and disable 26 * interrupts 27 * @lock: The lock variable 28 * @flags: Storage for interrupt flags 29 */ 30 #define local_lock_irqsave(lock, flags) \ 31 __local_lock_irqsave(lock, flags) 32 33 /** 34 * local_unlock - Release a per CPU local lock 35 * @lock: The lock variable 36 */ 37 #define local_unlock(lock) __local_unlock(lock) 38 39 /** 40 * local_unlock_irq - Release a per CPU local lock and enable interrupts 41 * @lock: The lock variable 42 */ 43 #define local_unlock_irq(lock) __local_unlock_irq(lock) 44 45 /** 46 * local_unlock_irqrestore - Release a per CPU local lock and restore 47 * interrupt flags 48 * @lock: The lock variable 49 * @flags: Interrupt flags to restore 50 */ 51 #define local_unlock_irqrestore(lock, flags) \ 52 __local_unlock_irqrestore(lock, flags) 53 54 /** 55 * local_lock_init - Runtime initialize a lock instance 56 */ 57 #define local_trylock_init(lock) __local_trylock_init(lock) 58 59 /** 60 * local_trylock - Try to acquire a per CPU local lock 61 * @lock: The lock variable 62 * 63 * The function can be used in any context such as NMI or HARDIRQ. Due to 64 * locking constrains it will _always_ fail to acquire the lock in NMI or 65 * HARDIRQ context on PREEMPT_RT. 66 */ 67 #define local_trylock(lock) __local_trylock(lock) 68 69 /** 70 * local_trylock_irqsave - Try to acquire a per CPU local lock, save and disable 71 * interrupts if acquired 72 * @lock: The lock variable 73 * @flags: Storage for interrupt flags 74 * 75 * The function can be used in any context such as NMI or HARDIRQ. Due to 76 * locking constrains it will _always_ fail to acquire the lock in NMI or 77 * HARDIRQ context on PREEMPT_RT. 78 */ 79 #define local_trylock_irqsave(lock, flags) \ 80 __local_trylock_irqsave(lock, flags) 81 82 DEFINE_GUARD(local_lock, local_lock_t __percpu*, 83 local_lock(_T), 84 local_unlock(_T)) 85 DEFINE_GUARD(local_lock_irq, local_lock_t __percpu*, 86 local_lock_irq(_T), 87 local_unlock_irq(_T)) 88 DEFINE_LOCK_GUARD_1(local_lock_irqsave, local_lock_t __percpu, 89 local_lock_irqsave(_T->lock, _T->flags), 90 local_unlock_irqrestore(_T->lock, _T->flags), 91 unsigned long flags) 92 93 #define local_lock_nested_bh(_lock) \ 94 __local_lock_nested_bh(_lock) 95 96 #define local_unlock_nested_bh(_lock) \ 97 __local_unlock_nested_bh(_lock) 98 99 DEFINE_GUARD(local_lock_nested_bh, local_lock_t __percpu*, 100 local_lock_nested_bh(_T), 101 local_unlock_nested_bh(_T)) 102 103 #endif 104