mm, oom: do not schedule if current has been killed
[deliverable/linux.git] / include / linux / lglock.h
CommitLineData
2dc91abe
NP
1/*
2 * Specialised local-global spinlock. Can only be declared as global variables
3 * to avoid overhead and keep things simple (and we don't want to start using
4 * these inside dynamically allocated structures).
5 *
6 * "local/global locks" (lglocks) can be used to:
7 *
8 * - Provide fast exclusive access to per-CPU data, with exclusive access to
9 * another CPU's data allowed but possibly subject to contention, and to
10 * provide very slow exclusive access to all per-CPU data.
11 * - Or to provide very fast and scalable read serialisation, and to provide
12 * very slow exclusive serialisation of data (not necessarily per-CPU data).
13 *
14 * Brlocks are also implemented as a short-hand notation for the latter use
15 * case.
16 *
17 * Copyright 2009, 2010, Nick Piggin, Novell Inc.
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>
e30e2fdf 25#include <linux/cpu.h>
eea62f83 26#include <linux/notifier.h>
2dc91abe
NP
27
28/* can make br locks by using local lock for read side, global lock for write */
eea62f83
AK
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)
2dc91abe 34
2dc91abe
NP
35#define DEFINE_BRLOCK(name) DEFINE_LGLOCK(name)
36
2dc91abe
NP
37#ifdef CONFIG_DEBUG_LOCK_ALLOC
38#define LOCKDEP_INIT_MAP lockdep_init_map
39
40#define DEFINE_LGLOCK_LOCKDEP(name) \
41 struct lock_class_key name##_lock_key; \
42 struct lockdep_map name##_lock_dep_map; \
43 EXPORT_SYMBOL(name##_lock_dep_map)
44
45#else
46#define LOCKDEP_INIT_MAP(a, b, c, d)
47
48#define DEFINE_LGLOCK_LOCKDEP(name)
49#endif
50
eea62f83
AK
51struct lglock {
52 arch_spinlock_t __percpu *lock;
53#ifdef CONFIG_DEBUG_LOCK_ALLOC
54 struct lock_class_key lock_key;
55 struct lockdep_map lock_dep_map;
56#endif
57};
2dc91abe
NP
58
59#define DEFINE_LGLOCK(name) \
eea62f83
AK
60 DEFINE_LGLOCK_LOCKDEP(name); \
61 DEFINE_PER_CPU(arch_spinlock_t, name ## _lock) \
62 = __ARCH_SPIN_LOCK_UNLOCKED; \
63 struct lglock name = { .lock = &name ## _lock }
64
65void lg_lock_init(struct lglock *lg, char *name);
66void lg_local_lock(struct lglock *lg);
67void lg_local_unlock(struct lglock *lg);
68void lg_local_lock_cpu(struct lglock *lg, int cpu);
69void lg_local_unlock_cpu(struct lglock *lg, int cpu);
70void lg_global_lock(struct lglock *lg);
71void lg_global_unlock(struct lglock *lg);
72
2dc91abe 73#endif
This page took 0.230596 seconds and 5 git commands to generate.