ia64/xen-unstable

view xen/common/spinlock.c @ 18705:ad39300ca063

spinlock: Add assertions for lock_irq() variants.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Oct 22 15:07:30 2008 +0100 (2008-10-22)
parents 876618c33914
children 0358305c6883
line source
1 #include <xen/config.h>
2 #include <xen/smp.h>
3 #include <xen/spinlock.h>
5 void _spin_lock(spinlock_t *lock)
6 {
7 _raw_spin_lock(&lock->raw);
8 }
10 void _spin_lock_irq(spinlock_t *lock)
11 {
12 ASSERT(local_irq_is_enabled());
13 local_irq_disable();
14 _raw_spin_lock(&lock->raw);
15 }
17 unsigned long _spin_lock_irqsave(spinlock_t *lock)
18 {
19 unsigned long flags;
20 local_irq_save(flags);
21 _raw_spin_lock(&lock->raw);
22 return flags;
23 }
25 void _spin_unlock(spinlock_t *lock)
26 {
27 _raw_spin_unlock(&lock->raw);
28 }
30 void _spin_unlock_irq(spinlock_t *lock)
31 {
32 _raw_spin_unlock(&lock->raw);
33 local_irq_enable();
34 }
36 void _spin_unlock_irqrestore(spinlock_t *lock, unsigned long flags)
37 {
38 _raw_spin_unlock(&lock->raw);
39 local_irq_restore(flags);
40 }
42 int _spin_is_locked(spinlock_t *lock)
43 {
44 return _raw_spin_is_locked(&lock->raw);
45 }
47 int _spin_trylock(spinlock_t *lock)
48 {
49 return _raw_spin_trylock(&lock->raw);
50 }
52 void _spin_barrier(spinlock_t *lock)
53 {
54 do { mb(); } while ( _raw_spin_is_locked(&lock->raw) );
55 mb();
56 }
58 void _spin_barrier_irq(spinlock_t *lock)
59 {
60 unsigned long flags;
61 local_irq_save(flags);
62 _spin_barrier(lock);
63 local_irq_restore(flags);
64 }
66 void _spin_lock_recursive(spinlock_t *lock)
67 {
68 int cpu = smp_processor_id();
70 /* Don't allow overflow of recurse_cpu field. */
71 BUILD_BUG_ON(NR_CPUS > 0xfffu);
73 if ( likely(lock->recurse_cpu != cpu) )
74 {
75 spin_lock(lock);
76 lock->recurse_cpu = cpu;
77 }
79 /* We support only fairly shallow recursion, else the counter overflows. */
80 ASSERT(lock->recurse_cnt < 0xfu);
81 lock->recurse_cnt++;
82 }
84 void _spin_unlock_recursive(spinlock_t *lock)
85 {
86 if ( likely(--lock->recurse_cnt == 0) )
87 {
88 lock->recurse_cpu = 0xfffu;
89 spin_unlock(lock);
90 }
91 }
93 void _read_lock(rwlock_t *lock)
94 {
95 _raw_read_lock(&lock->raw);
96 }
98 void _read_lock_irq(rwlock_t *lock)
99 {
100 ASSERT(local_irq_is_enabled());
101 local_irq_disable();
102 _raw_read_lock(&lock->raw);
103 }
105 unsigned long _read_lock_irqsave(rwlock_t *lock)
106 {
107 unsigned long flags;
108 local_irq_save(flags);
109 _raw_read_lock(&lock->raw);
110 return flags;
111 }
113 void _read_unlock(rwlock_t *lock)
114 {
115 _raw_read_unlock(&lock->raw);
116 }
118 void _read_unlock_irq(rwlock_t *lock)
119 {
120 _raw_read_unlock(&lock->raw);
121 local_irq_enable();
122 }
124 void _read_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
125 {
126 _raw_read_unlock(&lock->raw);
127 local_irq_restore(flags);
128 }
130 void _write_lock(rwlock_t *lock)
131 {
132 _raw_write_lock(&lock->raw);
133 }
135 void _write_lock_irq(rwlock_t *lock)
136 {
137 ASSERT(local_irq_is_enabled());
138 local_irq_disable();
139 _raw_write_lock(&lock->raw);
140 }
142 unsigned long _write_lock_irqsave(rwlock_t *lock)
143 {
144 unsigned long flags;
145 local_irq_save(flags);
146 _raw_write_lock(&lock->raw);
147 return flags;
148 }
150 void _write_unlock(rwlock_t *lock)
151 {
152 _raw_write_unlock(&lock->raw);
153 }
155 void _write_unlock_irq(rwlock_t *lock)
156 {
157 _raw_write_unlock(&lock->raw);
158 local_irq_enable();
159 }
161 void _write_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
162 {
163 _raw_write_unlock(&lock->raw);
164 local_irq_restore(flags);
165 }