Merge tag 'perf-tools-for-v6.4-3-2023-05-06' of git://git.kernel.org/pub/scm/linux...
[linux-block.git] / include / linux / spinlock_types.h
CommitLineData
fb1c8f93
IM
1#ifndef __LINUX_SPINLOCK_TYPES_H
2#define __LINUX_SPINLOCK_TYPES_H
3
4/*
5 * include/linux/spinlock_types.h - generic spinlock type definitions
6 * and initializers
7 *
8 * portions Copyright 2005, Red Hat, Inc., Ingo Molnar
9 * Released under the General Public License (GPL).
10 */
11
4f084ca7 12#include <linux/spinlock_types_raw.h>
c2f21ce2 13
051790ee
TG
14#ifndef CONFIG_PREEMPT_RT
15
16/* Non PREEMPT_RT kernels map spinlock to raw_spinlock */
c2f21ce2
TG
17typedef struct spinlock {
18 union {
19 struct raw_spinlock rlock;
20
21#ifdef CONFIG_DEBUG_LOCK_ALLOC
22# define LOCK_PADSIZE (offsetof(struct raw_spinlock, dep_map))
23 struct {
24 u8 __padding[LOCK_PADSIZE];
25 struct lockdep_map dep_map;
26 };
27#endif
28 };
29} spinlock_t;
30
de8f5e4f
PZ
31#define ___SPIN_LOCK_INITIALIZER(lockname) \
32 { \
33 .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, \
34 SPIN_DEBUG_INIT(lockname) \
35 SPIN_DEP_MAP_INIT(lockname) }
36
c2f21ce2 37#define __SPIN_LOCK_INITIALIZER(lockname) \
de8f5e4f 38 { { .rlock = ___SPIN_LOCK_INITIALIZER(lockname) } }
c2f21ce2
TG
39
40#define __SPIN_LOCK_UNLOCKED(lockname) \
de8f5e4f 41 (spinlock_t) __SPIN_LOCK_INITIALIZER(lockname)
c2f21ce2 42
e4d91918 43#define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x)
ef12f109 44
051790ee
TG
45#else /* !CONFIG_PREEMPT_RT */
46
47/* PREEMPT_RT kernels map spinlock to rt_mutex */
48#include <linux/rtmutex.h>
49
50typedef struct spinlock {
51 struct rt_mutex_base lock;
52#ifdef CONFIG_DEBUG_LOCK_ALLOC
53 struct lockdep_map dep_map;
54#endif
55} spinlock_t;
56
57#define __SPIN_LOCK_UNLOCKED(name) \
58 { \
59 .lock = __RT_MUTEX_BASE_INITIALIZER(name.lock), \
60 SPIN_DEP_MAP_INIT(name) \
61 }
62
31552385
TG
63#define __LOCAL_SPIN_LOCK_UNLOCKED(name) \
64 { \
65 .lock = __RT_MUTEX_BASE_INITIALIZER(name.lock), \
66 LOCAL_SPIN_DEP_MAP_INIT(name) \
67 }
68
051790ee
TG
69#define DEFINE_SPINLOCK(name) \
70 spinlock_t name = __SPIN_LOCK_UNLOCKED(name)
71
72#endif /* CONFIG_PREEMPT_RT */
73
ef12f109 74#include <linux/rwlock_types.h>
fb1c8f93
IM
75
76#endif /* __LINUX_SPINLOCK_TYPES_H */