1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#ifndef __LINUX_LGLOCK_H
20#define __LINUX_LGLOCK_H
21
22#include <linux/spinlock.h>
23#include <linux/lockdep.h>
24#include <linux/percpu.h>
25#include <linux/cpu.h>
26#include <linux/notifier.h>
27
28#ifdef CONFIG_SMP
29
30#ifdef CONFIG_DEBUG_LOCK_ALLOC
31#define LOCKDEP_INIT_MAP lockdep_init_map
32#else
33#define LOCKDEP_INIT_MAP(a, b, c, d)
34#endif
35
36struct lglock {
37 arch_spinlock_t __percpu *lock;
38#ifdef CONFIG_DEBUG_LOCK_ALLOC
39 struct lock_class_key lock_key;
40 struct lockdep_map lock_dep_map;
41#endif
42};
43
44#define DEFINE_LGLOCK(name) \
45 static DEFINE_PER_CPU(arch_spinlock_t, name ## _lock) \
46 = __ARCH_SPIN_LOCK_UNLOCKED; \
47 struct lglock name = { .lock = &name ## _lock }
48
49#define DEFINE_STATIC_LGLOCK(name) \
50 static DEFINE_PER_CPU(arch_spinlock_t, name ## _lock) \
51 = __ARCH_SPIN_LOCK_UNLOCKED; \
52 static struct lglock name = { .lock = &name ## _lock }
53
54void lg_lock_init(struct lglock *lg, char *name);
55void lg_local_lock(struct lglock *lg);
56void lg_local_unlock(struct lglock *lg);
57void lg_local_lock_cpu(struct lglock *lg, int cpu);
58void lg_local_unlock_cpu(struct lglock *lg, int cpu);
59void lg_global_lock(struct lglock *lg);
60void lg_global_unlock(struct lglock *lg);
61
62#else
63
64#define lglock spinlock
65#define DEFINE_LGLOCK(name) DEFINE_SPINLOCK(name)
66#define DEFINE_STATIC_LGLOCK(name) static DEFINE_SPINLOCK(name)
67#define lg_lock_init(lg, name) spin_lock_init(lg)
68#define lg_local_lock spin_lock
69#define lg_local_unlock spin_unlock
70#define lg_local_lock_cpu(lg, cpu) spin_lock(lg)
71#define lg_local_unlock_cpu(lg, cpu) spin_unlock(lg)
72#define lg_global_lock spin_lock
73#define lg_global_unlock spin_unlock
74#endif
75
76#endif
77