|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * The contents of this file constitute Original Code as defined in and ! 7: * are subject to the Apple Public Source License Version 1.1 (the ! 8: * "License"). You may not use this file except in compliance with the ! 9: * License. Please obtain a copy of the License at ! 10: * http://www.apple.com/publicsource and read it before using this file. ! 11: * ! 12: * This Original Code and all software distributed under the License are ! 13: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 14: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 15: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 16: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 17: * License for the specific language governing rights and limitations ! 18: * under the License. ! 19: * ! 20: * @APPLE_LICENSE_HEADER_END@ ! 21: */ ! 22: /* ! 23: * Copyright (c) 1998 Apple Computer, Inc. All rights reserved. ! 24: * ! 25: * HISTORY ! 26: * ! 27: */ ! 28: ! 29: /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. ! 30: * ! 31: * EventShmemLock.h - Shared memory area locks for use between the ! 32: * WindowServer and the Event Driver. ! 33: * ! 34: * HISTORY ! 35: * 30 Nov 1992 Ben Fathi ([email protected]) ! 36: * Ported to m98k. ! 37: * ! 38: * 29 April 1992 Mike Paquette at NeXT ! 39: * Created. ! 40: * ! 41: * Multiprocessor locks used within the shared memory area between the ! 42: * kernel and event system. These must work in both user and kernel mode. ! 43: * The locks are defined in an include file so they get exported to the local ! 44: * include file area. ! 45: */ ! 46: ! 47: ! 48: #ifndef _IOKIT_IOSHAREDLOCKIMP_H ! 49: #define _IOKIT_IOSHAREDLOCKIMP_H ! 50: ! 51: #include <architecture/ppc/asm_help.h> ! 52: ! 53: // 'Till we're building in kernel ! 54: .macro DISABLE_PREEMPTION ! 55: #ifdef KERNEL ! 56: #endif ! 57: .endmacro ! 58: .macro ENABLE_PREEMPTION ! 59: #ifdef KERNEL ! 60: #endif ! 61: .endmacro ! 62: ! 63: /* ! 64: * void ! 65: * ev_lock(p) ! 66: * register int *p; ! 67: * ! 68: * Lock the lock pointed to by p. Spin (possibly forever) until ! 69: * the lock is available. Test and test and set logic used. ! 70: */ ! 71: TEXT ! 72: ! 73: #ifndef KERNEL ! 74: LEAF(_ev_lock) ! 75: LEAF(_IOSpinLock) ! 76: li a6,1 // lock value ! 77: lwarx a7,0,a0 // CEMV10 ! 78: 9: ! 79: sync ! 80: lwarx a7,0,a0 // read the lock ! 81: cmpwi cr0,a7,0 // is it busy? ! 82: bne- 9b // yes, spin ! 83: sync ! 84: stwcx. a6,0,a0 // try to get the lock ! 85: bne- 9b // failed, try again ! 86: isync ! 87: blr // got it, return ! 88: END(_ev_lock) ! 89: #endif ! 90: ! 91: /* ! 92: * void ! 93: * spin_unlock(p) ! 94: * int *p; ! 95: * ! 96: * Unlock the lock pointed to by p. ! 97: */ ! 98: ! 99: LEAF(_ev_unlock) ! 100: LEAF(_IOSpinUnlock) ! 101: sync ! 102: li a7,0 ! 103: stw a7,0(a0) ! 104: ENABLE_PREEMPTION() ! 105: blr ! 106: END(_ev_unlock) ! 107: ! 108: ! 109: /* ! 110: * ev_try_lock(p) ! 111: * int *p; ! 112: * ! 113: * Try to lock p. Return TRUE if successful in obtaining lock. ! 114: */ ! 115: ! 116: LEAF(_ev_try_lock) ! 117: LEAF(_IOTrySpinLock) ! 118: li a6,1 // lock value ! 119: DISABLE_PREEMPTION() ! 120: lwarx a7,0,a0 // CEMV10 ! 121: 8: ! 122: sync ! 123: lwarx a7,0,a0 // read the lock ! 124: cmpwi cr0,a7,0 // is it busy? ! 125: bne- 9f // yes, give up ! 126: sync ! 127: stwcx. a6,0,a0 // try to get the lock ! 128: bne- 8b // failed, try again ! 129: li a0,1 // return TRUE ! 130: isync ! 131: blr ! 132: 9: ! 133: ENABLE_PREEMPTION() ! 134: li a0,0 // return FALSE ! 135: blr ! 136: END(_ev_try_lock) ! 137: ! 138: #endif /* ! _IOKIT_IOSHAREDLOCKIMP_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.