The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/lib/brlock.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  *
    3  * linux/lib/brlock.c
    4  *
    5  * 'Big Reader' read-write spinlocks.  See linux/brlock.h for details.
    6  *
    7  * Copyright 2000, Ingo Molnar <mingo@redhat.com>
    8  * Copyright 2000, David S. Miller <davem@redhat.com>
    9  */
   10 
   11 #include <linux/config.h>
   12 
   13 #ifdef CONFIG_SMP
   14 
   15 #include <linux/sched.h>
   16 #include <linux/brlock.h>
   17 
   18 #ifdef __BRLOCK_USE_ATOMICS
   19 
   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 } };
   22 
   23 void __br_write_lock (enum brlock_indices idx)
   24 {
   25         int i;
   26 
   27         for (i = 0; i < smp_num_cpus; i++)
   28                 write_lock(&__brlock_array[cpu_logical_map(i)][idx]);
   29 }
   30 
   31 void __br_write_unlock (enum brlock_indices idx)
   32 {
   33         int i;
   34 
   35         for (i = 0; i < smp_num_cpus; i++)
   36                 write_unlock(&__brlock_array[cpu_logical_map(i)][idx]);
   37 }
   38 
   39 #else /* ! __BRLOCK_USE_ATOMICS */
   40 
   41 brlock_read_lock_t __brlock_array[NR_CPUS][__BR_IDX_MAX] =
   42    { [0 ... NR_CPUS-1] = { [0 ... __BR_IDX_MAX-1] = 0 } };
   43 
   44 struct br_wrlock __br_write_locks[__BR_IDX_MAX] =
   45    { [0 ... __BR_IDX_MAX-1] = { SPIN_LOCK_UNLOCKED } };
   46 
   47 void __br_write_lock (enum brlock_indices idx)
   48 {
   49         int i;
   50 
   51 again:
   52         spin_lock(&__br_write_locks[idx].lock);
   53         for (i = 0; i < smp_num_cpus; i++)
   54                 if (__brlock_array[cpu_logical_map(i)][idx] != 0) {
   55                         spin_unlock(&__br_write_locks[idx].lock);
   56                         barrier();
   57                         cpu_relax();
   58                         goto again;
   59                 }
   60 }
   61 
   62 void __br_write_unlock (enum brlock_indices idx)
   63 {
   64         spin_unlock(&__br_write_locks[idx].lock);
   65 }
   66 
   67 #endif /* __BRLOCK_USE_ATOMICS */
   68 
   69 #endif /* CONFIG_SMP */

Cache object: a6614732219040c7adfba0b3cbdfad04


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.