[PATCH] share i386/x86-64 oprofile code
[linux-2.6/history.git] / lib / brlock.c
blob7e9121378da1bc58cc193769d6d34f7065e39204
1 /*
3 * linux/lib/brlock.c
5 * 'Big Reader' read-write spinlocks. See linux/brlock.h for details.
7 * Copyright 2000, Ingo Molnar <mingo@redhat.com>
8 * Copyright 2000, David S. Miller <davem@redhat.com>
9 */
11 #include <linux/config.h>
13 #ifdef CONFIG_SMP
15 #include <linux/sched.h>
16 #include <linux/brlock.h>
18 #ifdef __BRLOCK_USE_ATOMICS
20 brlock_read_lock_t __brlock_array[NR_CPUS][__BR_IDX_MAX] =
21 { [0 ... NR_CPUS-1] = { [0 ... __BR_IDX_MAX-1] = RW_LOCK_UNLOCKED } };
23 void __br_write_lock (enum brlock_indices idx)
25 int i;
27 preempt_disable();
28 for (i = 0; i < NR_CPUS; i++)
29 _raw_write_lock(&__brlock_array[i][idx]);
32 void __br_write_unlock (enum brlock_indices idx)
34 int i;
36 for (i = 0; i < NR_CPUS; i++)
37 _raw_write_unlock(&__brlock_array[i][idx]);
38 preempt_enable();
41 #else /* ! __BRLOCK_USE_ATOMICS */
43 brlock_read_lock_t __brlock_array[NR_CPUS][__BR_IDX_MAX] =
44 { [0 ... NR_CPUS-1] = { [0 ... __BR_IDX_MAX-1] = 0 } };
46 struct br_wrlock __br_write_locks[__BR_IDX_MAX] =
47 { [0 ... __BR_IDX_MAX-1] = { SPIN_LOCK_UNLOCKED } };
49 void __br_write_lock (enum brlock_indices idx)
51 int i;
53 preempt_disable();
54 again:
55 _raw_spin_lock(&__br_write_locks[idx].lock);
56 for (i = 0; i < NR_CPUS; i++)
57 if (__brlock_array[i][idx] != 0) {
58 _raw_spin_unlock(&__br_write_locks[idx].lock);
59 barrier();
60 cpu_relax();
61 goto again;
65 void __br_write_unlock (enum brlock_indices idx)
67 spin_unlock(&__br_write_locks[idx].lock);
70 #endif /* __BRLOCK_USE_ATOMICS */
72 #endif /* CONFIG_SMP */