|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: ! 25: /* ! 26: * Mach Operating System ! 27: * Copyright (c) 1993-1987 Carnegie Mellon University ! 28: * All Rights Reserved. ! 29: * ! 30: * Permission to use, copy, modify and distribute this software and its ! 31: * documentation is hereby granted, provided that both the copyright ! 32: * notice and this permission notice appear in all copies of the ! 33: * software, derivative works or modified versions, and any portions ! 34: * thereof, and that both notices appear in supporting documentation. ! 35: * ! 36: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" ! 37: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR ! 38: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. ! 39: * ! 40: * Carnegie Mellon requests users of this software to return to ! 41: * ! 42: * Software Distribution Coordinator or [email protected] ! 43: * School of Computer Science ! 44: * Carnegie Mellon University ! 45: * Pittsburgh PA 15213-3890 ! 46: * ! 47: * any improvements or extensions that they make and grant Carnegie Mellon ! 48: * the rights to redistribute these changes. ! 49: */ ! 50: /* ! 51: * File: kern/lock.h ! 52: * Author: Avadis Tevanian, Jr., Michael Wayne Young ! 53: * Date: 1985 ! 54: * ! 55: * Locking primitives definitions ! 56: */ ! 57: ! 58: #ifndef _KERN_LOCK_H_ ! 59: #define _KERN_LOCK_H_ ! 60: ! 61: #import <mach/features.h> ! 62: ! 63: #include <mach/boolean.h> ! 64: #include <mach/machine/vm_types.h> ! 65: ! 66: #define MACH_SLOCKS ((NCPUS > 1) || MACH_LDEBUG || DRIVERKIT) ! 67: ! 68: #ifndef _MACHINE_SIMPLE_LOCK_DATA_ ! 69: /* ! 70: * A simple spin lock. ! 71: */ ! 72: ! 73: struct slock { ! 74: volatile natural_t lock_data; /* in general 1 bit is sufficient */ ! 75: }; ! 76: ! 77: typedef struct slock simple_lock_data_t; ! 78: typedef struct slock *simple_lock_t; ! 79: #endif /* _MACHINE_SIMPLE_LOCK_DATA_ */ ! 80: ! 81: #if MACH_SLOCKS ! 82: /* ! 83: * Use the locks. ! 84: */ ! 85: ! 86: #define decl_simple_lock_data(class,name) \ ! 87: class simple_lock_data_t name; ! 88: ! 89: #define simple_lock_addr(lock) (&(lock)) ! 90: ! 91: #else /* MACH_SLOCKS */ ! 92: /* ! 93: * Do not allocate storage for locks if not needed. ! 94: */ ! 95: #define decl_simple_lock_data(class,name) ! 96: #define simple_lock_addr(lock) ((simple_lock_t)0) ! 97: ! 98: /* ! 99: * No multiprocessor locking is necessary. ! 100: */ ! 101: #define simple_lock_init(l) ! 102: #define simple_lock(l) ! 103: #define simple_unlock(l) ! 104: #define simple_lock_try(l) (TRUE) /* always succeeds */ ! 105: #define simple_lock_taken(l) (1) /* always succeeds */ ! 106: #define check_simple_locks() ! 107: #define simple_lock_pause() ! 108: ! 109: #endif /* MACH_SLOCKS */ ! 110: ! 111: extern simple_lock_t simple_lock_alloc(void); ! 112: extern void simple_lock_free(simple_lock_t); ! 113: ! 114: /* ! 115: * The general lock structure. Provides for multiple readers, ! 116: * upgrading from read to write, and sleeping until the lock ! 117: * can be gained. ! 118: * ! 119: * On some architectures, assembly language code in the 'inline' ! 120: * program fiddles the lock structures. It must be changed in ! 121: * concert with the structure layout. ! 122: * ! 123: * Only the "interlock" field is used for hardware exclusion; ! 124: * other fields are modified with normal instructions after ! 125: * acquiring the interlock bit. ! 126: */ ! 127: struct lock { ! 128: struct thread *thread; /* Thread that has lock, if ! 129: recursive locking allowed */ ! 130: unsigned int read_count:16, /* Number of accepted readers */ ! 131: /* boolean_t */ want_upgrade:1, /* Read-to-write upgrade waiting */ ! 132: /* boolean_t */ want_write:1, /* Writer is waiting, or ! 133: locked for write */ ! 134: /* boolean_t */ waiting:1, /* Someone is sleeping on lock */ ! 135: /* boolean_t */ can_sleep:1, /* Can attempts to lock go to sleep? */ ! 136: recursion_depth:12, /* Depth of recursion */ ! 137: :0; ! 138: decl_simple_lock_data(,interlock) ! 139: /* Hardware interlock field. ! 140: Last in the structure so that ! 141: field offsets are the same whether ! 142: or not it is present. */ ! 143: }; ! 144: ! 145: typedef struct lock lock_data_t; ! 146: typedef struct lock *lock_t; ! 147: ! 148: /* Sleep locks must work even if no multiprocessing */ ! 149: ! 150: extern void lock_init(lock_t, boolean_t); ! 151: extern void lock_sleepable(lock_t, boolean_t); ! 152: extern void lock_write(lock_t); ! 153: extern void lock_read(lock_t); ! 154: extern void lock_done(lock_t); ! 155: extern boolean_t lock_read_to_write(lock_t); ! 156: extern void lock_write_to_read(lock_t); ! 157: extern boolean_t lock_try_write(lock_t); ! 158: extern boolean_t lock_try_read(lock_t); ! 159: extern boolean_t lock_try_read_to_write(lock_t); ! 160: ! 161: #define lock_read_done(l) lock_done(l) ! 162: #define lock_write_done(l) lock_done(l) ! 163: ! 164: extern void lock_set_recursive(lock_t); ! 165: extern void lock_clear_recursive(lock_t); ! 166: ! 167: extern lock_t lock_alloc(void); ! 168: extern void lock_free(lock_t); ! 169: ! 170: #endif /* _KERN_LOCK_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.