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
29#define br_lock_init(name) lg_lock_init(name, #name)
30#define br_read_lock(name) lg_local_lock(name)
31#define br_read_unlock(name) lg_local_unlock(name)
32#define br_write_lock(name) lg_global_lock(name)
33#define br_write_unlock(name) lg_global_unlock(name)
34
35#define DEFINE_BRLOCK(name) DEFINE_LGLOCK(name)
36#define DEFINE_STATIC_BRLOCK(name) DEFINE_STATIC_LGLOCK(name)
37
38#ifdef CONFIG_DEBUG_LOCK_ALLOC
39#define LOCKDEP_INIT_MAP lockdep_init_map
40#else
41#define LOCKDEP_INIT_MAP(a, b, c, d)
42#endif
43
44struct lglock {
45 arch_spinlock_t __percpu *lock;
46#ifdef CONFIG_DEBUG_LOCK_ALLOC
47 struct lock_class_key lock_key;
48 struct lockdep_map lock_dep_map;
49#endif
50};
51
52#define DEFINE_LGLOCK(name) \
53 static DEFINE_PER_CPU(arch_spinlock_t, name ## _lock) \
54 = __ARCH_SPIN_LOCK_UNLOCKED; \
55 struct lglock name = { .lock = &name ## _lock }
56
57#define DEFINE_STATIC_LGLOCK(name) \
58 static DEFINE_PER_CPU(arch_spinlock_t, name ## _lock) \
59 = __ARCH_SPIN_LOCK_UNLOCKED; \
60 static struct lglock name = { .lock = &name ## _lock }
61
62void lg_lock_init(struct lglock *lg, char *name);
63
64void lg_local_lock(struct lglock *lg);
65void lg_local_unlock(struct lglock *lg);
66void lg_local_lock_cpu(struct lglock *lg, int cpu);
67void lg_local_unlock_cpu(struct lglock *lg, int cpu);
68
69void lg_double_lock(struct lglock *lg, int cpu1, int cpu2);
70void lg_double_unlock(struct lglock *lg, int cpu1, int cpu2);
71
72void lg_global_lock(struct lglock *lg);
73void lg_global_unlock(struct lglock *lg);
74
75#endif
76