blob: 851b7783720d89685f7a0653f1efa43263118585 [file] [log] [blame]
Ingo Molnarfb1c8f92005-09-10 00:25:56 -07001#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
12#if defined(CONFIG_SMP)
13# include <asm/spinlock_types.h>
14#else
15# include <linux/spinlock_types_up.h>
16#endif
17
Peter Zijlstra21f8ca32007-07-19 01:48:53 -070018#include <linux/lockdep.h>
19
Thomas Gleixnerc2f21ce2009-12-02 20:02:59 +010020typedef struct raw_spinlock {
Thomas Gleixner445c8952009-12-02 19:49:50 +010021 arch_spinlock_t raw_lock;
Nick Piggin95c354f2008-01-30 13:31:20 +010022#ifdef CONFIG_GENERIC_LOCKBREAK
Ingo Molnarfb1c8f92005-09-10 00:25:56 -070023 unsigned int break_lock;
24#endif
25#ifdef CONFIG_DEBUG_SPINLOCK
26 unsigned int magic, owner_cpu;
27 void *owner;
28#endif
Ingo Molnar8a25d5d2006-07-03 00:24:54 -070029#ifdef CONFIG_DEBUG_LOCK_ALLOC
30 struct lockdep_map dep_map;
31#endif
Thomas Gleixnerc2f21ce2009-12-02 20:02:59 +010032} raw_spinlock_t;
Ingo Molnarfb1c8f92005-09-10 00:25:56 -070033
34#define SPINLOCK_MAGIC 0xdead4ead
35
Ingo Molnarfb1c8f92005-09-10 00:25:56 -070036#define SPINLOCK_OWNER_INIT ((void *)-1L)
37
Ingo Molnar8a25d5d2006-07-03 00:24:54 -070038#ifdef CONFIG_DEBUG_LOCK_ALLOC
39# define SPIN_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname }
40#else
41# define SPIN_DEP_MAP_INIT(lockname)
42#endif
43
Ingo Molnarfb1c8f92005-09-10 00:25:56 -070044#ifdef CONFIG_DEBUG_SPINLOCK
Thomas Gleixnerc2f21ce2009-12-02 20:02:59 +010045# define SPIN_DEBUG_INIT(lockname) \
46 .magic = SPINLOCK_MAGIC, \
47 .owner_cpu = -1, \
48 .owner = SPINLOCK_OWNER_INIT,
Ingo Molnarfb1c8f92005-09-10 00:25:56 -070049#else
Thomas Gleixnerc2f21ce2009-12-02 20:02:59 +010050# define SPIN_DEBUG_INIT(lockname)
Ingo Molnarfb1c8f92005-09-10 00:25:56 -070051#endif
52
Thomas Gleixnerc2f21ce2009-12-02 20:02:59 +010053#define __RAW_SPIN_LOCK_INITIALIZER(lockname) \
54 { \
55 .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, \
56 SPIN_DEBUG_INIT(lockname) \
57 SPIN_DEP_MAP_INIT(lockname) }
58
59#define __RAW_SPIN_LOCK_UNLOCKED(lockname) \
60 (raw_spinlock_t) __RAW_SPIN_LOCK_INITIALIZER(lockname)
61
62#define DEFINE_RAW_SPINLOCK(x) raw_spinlock_t x = __RAW_SPIN_LOCK_UNLOCKED(x)
63
64typedef struct spinlock {
65 union {
66 struct raw_spinlock rlock;
67
68#ifdef CONFIG_DEBUG_LOCK_ALLOC
69# define LOCK_PADSIZE (offsetof(struct raw_spinlock, dep_map))
70 struct {
71 u8 __padding[LOCK_PADSIZE];
72 struct lockdep_map dep_map;
73 };
74#endif
75 };
76} spinlock_t;
77
78#define __SPIN_LOCK_INITIALIZER(lockname) \
79 { { .rlock = __RAW_SPIN_LOCK_INITIALIZER(lockname) } }
80
81#define __SPIN_LOCK_UNLOCKED(lockname) \
82 (spinlock_t ) __SPIN_LOCK_INITIALIZER(lockname)
83
Michael Ellermand1ab8242007-05-08 00:30:22 -070084/*
Thomas Gleixneref12f102009-11-07 23:04:15 +010085 * SPIN_LOCK_UNLOCKED defeats lockdep state tracking and is hence
86 * deprecated.
87 * Please use DEFINE_SPINLOCK() or __SPIN_LOCK_UNLOCKED() as
88 * appropriate.
Michael Ellermand1ab8242007-05-08 00:30:22 -070089 */
Ingo Molnare4d91912006-07-03 00:24:34 -070090#define SPIN_LOCK_UNLOCKED __SPIN_LOCK_UNLOCKED(old_style_spin_init)
Ingo Molnare4d91912006-07-03 00:24:34 -070091
92#define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x)
Thomas Gleixneref12f102009-11-07 23:04:15 +010093
94#include <linux/rwlock_types.h>
Ingo Molnarfb1c8f92005-09-10 00:25:56 -070095
96#endif /* __LINUX_SPINLOCK_TYPES_H */