| 1 | /* $NetBSD: lock.h,v 1.86 2010/07/01 13:00:57 hannken Exp $ */ |
| 2 | |
| 3 | /*- |
| 4 | * Copyright (c) 1999, 2000, 2006, 2007 The NetBSD Foundation, Inc. |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * This code is derived from software contributed to The NetBSD Foundation |
| 8 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, |
| 9 | * NASA Ames Research Center, by Ross Harvey, and by Andrew Doran. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer. |
| 16 | * 2. Redistributions in binary form must reproduce the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer in the |
| 18 | * documentation and/or other materials provided with the distribution. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
| 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
| 24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 30 | * POSSIBILITY OF SUCH DAMAGE. |
| 31 | */ |
| 32 | |
| 33 | /* |
| 34 | * Copyright (c) 1995 |
| 35 | * The Regents of the University of California. All rights reserved. |
| 36 | * |
| 37 | * This code contains ideas from software contributed to Berkeley by |
| 38 | * Avadis Tevanian, Jr., Michael Wayne Young, and the Mach Operating |
| 39 | * System project at Carnegie-Mellon University. |
| 40 | * |
| 41 | * Redistribution and use in source and binary forms, with or without |
| 42 | * modification, are permitted provided that the following conditions |
| 43 | * are met: |
| 44 | * 1. Redistributions of source code must retain the above copyright |
| 45 | * notice, this list of conditions and the following disclaimer. |
| 46 | * 2. Redistributions in binary form must reproduce the above copyright |
| 47 | * notice, this list of conditions and the following disclaimer in the |
| 48 | * documentation and/or other materials provided with the distribution. |
| 49 | * 3. Neither the name of the University nor the names of its contributors |
| 50 | * may be used to endorse or promote products derived from this software |
| 51 | * without specific prior written permission. |
| 52 | * |
| 53 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 54 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 55 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 56 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 57 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 58 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 59 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 60 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 61 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 62 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 63 | * SUCH DAMAGE. |
| 64 | * |
| 65 | * @(#)lock.h 8.12 (Berkeley) 5/19/95 |
| 66 | */ |
| 67 | |
| 68 | #ifndef _SYS_LOCK_H_ |
| 69 | #define _SYS_LOCK_H_ |
| 70 | |
| 71 | #include <sys/stdint.h> |
| 72 | #include <sys/mutex.h> |
| 73 | |
| 74 | #include <machine/lock.h> |
| 75 | |
| 76 | #ifdef _KERNEL |
| 77 | |
| 78 | /* |
| 79 | * From <machine/lock.h>. |
| 80 | */ |
| 81 | #ifndef SPINLOCK_SPIN_HOOK |
| 82 | #define SPINLOCK_SPIN_HOOK |
| 83 | #endif |
| 84 | #ifndef SPINLOCK_BACKOFF_HOOK |
| 85 | #define SPINLOCK_BACKOFF_HOOK nullop(NULL) |
| 86 | #endif |
| 87 | #ifndef SPINLOCK_BACKOFF_MIN |
| 88 | #define SPINLOCK_BACKOFF_MIN 4 |
| 89 | #endif |
| 90 | #ifndef SPINLOCK_BACKOFF_MAX |
| 91 | #define SPINLOCK_BACKOFF_MAX 128 |
| 92 | #endif |
| 93 | |
| 94 | #define SPINLOCK_BACKOFF(count) \ |
| 95 | do { \ |
| 96 | int __i; \ |
| 97 | for (__i = (count); __i != 0; __i--) { \ |
| 98 | SPINLOCK_BACKOFF_HOOK; \ |
| 99 | } \ |
| 100 | if ((count) < SPINLOCK_BACKOFF_MAX) \ |
| 101 | (count) += (count); \ |
| 102 | } while (/* CONSTCOND */ 0); |
| 103 | |
| 104 | #define SPINLOCK_RUN_HOOK(count) ((count) >= SPINLOCK_BACKOFF_MAX) |
| 105 | |
| 106 | #ifdef LOCKDEBUG |
| 107 | #define SPINLOCK_SPINOUT(spins) ((spins)++ > 0x0fffffff) |
| 108 | #else |
| 109 | #define SPINLOCK_SPINOUT(spins) ((void)(spins), 0) |
| 110 | #endif |
| 111 | |
| 112 | extern __cpu_simple_lock_t kernel_lock[]; |
| 113 | |
| 114 | #endif /* _KERNEL */ |
| 115 | |
| 116 | #endif /* _SYS_LOCK_H_ */ |
| 117 | |