summaryrefslogtreecommitdiffstats
path: root/uClinux-2.4.31-uc0/lib/brlock.c
blob: 9b365ebc6b565c4bc349afaf78f07d9d488b9053 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 *
 * 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>

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 fastcall __br_write_lock (enum brlock_indices idx)
{
	int i;

again:
	spin_lock(&__br_write_locks[idx].lock);
	for (i = 0; i < smp_num_cpus; i++)
		if (__brlock_array[cpu_logical_map(i)][idx] != 0) {
			spin_unlock(&__br_write_locks[idx].lock);
			barrier();
			cpu_relax();
			goto again;
		}
}

void fastcall __br_write_unlock (enum brlock_indices idx)
{
	spin_unlock(&__br_write_locks[idx].lock);
}

#endif /* CONFIG_SMP */