diff options
author | Ralf Baechle <ralf@linux-mips.org> | 2000-03-07 16:02:18 +0000 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2000-03-07 16:02:18 +0000 |
commit | 478add0ea718dee38702c066907a510525964b48 (patch) | |
tree | db719e8441d2c0bf223a6f86b36a5a25772957bd /lib/brlock.c | |
parent | 9f9f3e6e8548a596697778337110a423c384b6f3 (diff) |
Rest of the merge.
Diffstat (limited to 'lib/brlock.c')
-rw-r--r-- | lib/brlock.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/brlock.c b/lib/brlock.c new file mode 100644 index 000000000..3c3577309 --- /dev/null +++ b/lib/brlock.c @@ -0,0 +1,65 @@ +/* + * + * linux/lib/brlock.c + * + * 'Big Reader' read-write spinlocks. See linux/brlock.h for details. + * + * Copyright 2000, Ingo Molnar <mingo@redhat.com> + * Copyright 2000, David S. Miller <davem@redhat.com> + */ + +#include <linux/config.h> + +#ifdef CONFIG_SMP + +#include <linux/sched.h> +#include <linux/brlock.h> + +#ifdef __BRLOCK_USE_ATOMICS + +brlock_read_lock_t __brlock_array[NR_CPUS][__BR_IDX_MAX] = + { [0 ... NR_CPUS-1] = { [0 ... __BR_IDX_MAX-1] = RW_LOCK_UNLOCKED } }; + +void __br_write_lock (enum brlock_indices idx) +{ + int i; + + for (i = 0; i < smp_num_cpus; i++) + write_lock(__brlock_array[idx] + i); +} + +void __br_write_unlock (enum brlock_indices idx) +{ + int i; + + for (i = 0; i < smp_num_cpus; i++) + write_unlock(__brlock_array[idx] + i); +} + +#else /* ! __BRLOCK_USE_ATOMICS */ + +brlock_read_lock_t __brlock_array[NR_CPUS][__BR_IDX_MAX] = + { [0 ... NR_CPUS-1] = { [0 ... __BR_IDX_MAX-1] = 0 } }; + +struct br_wrlock __br_write_locks[__BR_IDX_MAX] = + { [0 ... __BR_IDX_MAX-1] = { SPIN_LOCK_UNLOCKED } }; + +void __br_write_lock (enum brlock_indices idx) +{ + int i; + + spin_lock(&__br_write_locks[idx].lock); +again: + for (i = 0; i < smp_num_cpus; i++) + if (__brlock_array[i][idx] != 0) + goto again; +} + +void __br_write_unlock (enum brlock_indices idx) +{ + spin_unlock(&__br_write_locks[idx].lock); +} + +#endif /* __BRLOCK_USE_ATOMICS */ + +#endif /* CONFIG_SMP */ |