|
|
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: * Copyright (c) 1994 NeXT Computer, Inc. ! 27: * ! 28: * Kernel generic lock object. ! 29: * ! 30: * HISTORY ! 31: * ! 32: * 4 July 1994 ? at NeXT ! 33: * Created. ! 34: */ ! 35: ! 36: #import <cpus.h> ! 37: ! 38: #import <mach/mach_types.h> ! 39: ! 40: #import <driverkit/KernLock.h> ! 41: ! 42: @implementation KernLock ! 43: ! 44: - initWithLevel: (int)level ! 45: { ! 46: #if NCPUS > 1 ! 47: _slock = simple_lock_alloc(); ! 48: simple_lock_init(_slock); ! 49: #else ! 50: if (level == 0) ! 51: return [super free]; ! 52: #endif ! 53: ! 54: _lockLevel = level; ! 55: ! 56: return self; ! 57: } ! 58: ! 59: - init ! 60: { ! 61: return [self initWithLevel:0]; ! 62: } ! 63: ! 64: - free ! 65: { ! 66: #if NCPUS > 1 ! 67: simple_lock_free(_slock); ! 68: #endif ! 69: ! 70: return [super free]; ! 71: } ! 72: ! 73: - (int)level ! 74: { ! 75: return _lockLevel; ! 76: } ! 77: ! 78: - (void)acquire ! 79: { ! 80: int oldLevel = curipl(); ! 81: ! 82: if (oldLevel < _lockLevel) ! 83: spln(ipltospl(_lockLevel)); ! 84: ! 85: #if NCPUS > 1 ! 86: simple_lock(_slock); ! 87: #endif ! 88: _savedLevel = oldLevel; ! 89: } ! 90: ! 91: - (void)release ! 92: { ! 93: int oldLevel = _savedLevel; ! 94: ! 95: #if NCPUS > 1 ! 96: simple_unlock(_slock); ! 97: #endif ! 98: spln(ipltospl(oldLevel)); ! 99: } ! 100: ! 101: @end ! 102: ! 103: typedef struct KernLock_ { ! 104: @defs(KernLock) ! 105: } KernLock_; ! 106: ! 107: void ! 108: KernLockAcquire( ! 109: KernLock *_lock ! 110: ) ! 111: { ! 112: KernLock_ *lock = (KernLock_ *)_lock; ! 113: int oldLevel = curipl(); ! 114: ! 115: if (_lock == nil) ! 116: return; ! 117: ! 118: if (oldLevel < lock->_lockLevel) ! 119: spln(ipltospl(lock->_lockLevel)); ! 120: ! 121: #if NCPUS > 1 ! 122: simple_lock(lock->_slock); ! 123: #endif ! 124: lock->_savedLevel = oldLevel; ! 125: } ! 126: ! 127: void ! 128: KernLockRelease( ! 129: KernLock *_lock ! 130: ) ! 131: { ! 132: KernLock_ *lock = (KernLock_ *)_lock; ! 133: int oldLevel; ! 134: ! 135: if (_lock == nil) ! 136: return; ! 137: ! 138: oldLevel = lock->_savedLevel; ! 139: ! 140: #if NCPUS > 1 ! 141: simple_unlock(lock->_slock); ! 142: #endif ! 143: spln(ipltospl(oldLevel)); ! 144: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.