xref: /linux/include/linux/local_lock.h (revision c5bcab75)
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 DEFINE_GUARD(local_lock, local_lock_t __percpu*,
55 	     local_lock(_T),
56 	     local_unlock(_T))
57 DEFINE_GUARD(local_lock_irq, local_lock_t __percpu*,
58 	     local_lock_irq(_T),
59 	     local_unlock_irq(_T))
60 DEFINE_LOCK_GUARD_1(local_lock_irqsave, local_lock_t __percpu,
61 		    local_lock_irqsave(_T->lock, _T->flags),
62 		    local_unlock_irqrestore(_T->lock, _T->flags),
63 		    unsigned long flags)
64 
65 #define local_lock_nested_bh(_lock)				\
66 	__local_lock_nested_bh(_lock)
67 
68 #define local_unlock_nested_bh(_lock)				\
69 	__local_unlock_nested_bh(_lock)
70 
71 DEFINE_GUARD(local_lock_nested_bh, local_lock_t __percpu*,
72 	     local_lock_nested_bh(_T),
73 	     local_unlock_nested_bh(_T))
74 
75 #endif
76