This is pre8 ...
[linux-2.6/linux-mips.git] / lib / brlock.c
blob046b6dc1c71eccb15d51818ebf8b8e2b0754508f
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 for (i = 0; i < smp_num_cpus; i++)
28 write_lock(__brlock_array[idx] + cpu_logical_map(i));
31 void __br_write_unlock (enum brlock_indices idx)
33 int i;
35 for (i = 0; i < smp_num_cpus; i++)
36 write_unlock(__brlock_array[idx] + cpu_logical_map(i));
39 #else /* ! __BRLOCK_USE_ATOMICS */
41 brlock_read_lock_t __brlock_array[NR_CPUS][__BR_IDX_MAX] =
42 { [0 ... NR_CPUS-1] = { [0 ... __BR_IDX_MAX-1] = 0 } };
44 struct br_wrlock __br_write_locks[__BR_IDX_MAX] =
45 { [0 ... __BR_IDX_MAX-1] = { SPIN_LOCK_UNLOCKED } };
47 void __br_write_lock (enum brlock_indices idx)
49 int i;
51 spin_lock(&__br_write_locks[idx].lock);
52 again:
53 for (i = 0; i < smp_num_cpus; i++)
54 if (__brlock_array[cpu_logical_map(i)][idx] != 0)
55 goto again;
58 void __br_write_unlock (enum brlock_indices idx)
60 spin_unlock(&__br_write_locks[idx].lock);
63 #endif /* __BRLOCK_USE_ATOMICS */
65 #endif /* CONFIG_SMP */