]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/i386/IOSharedLockImp.h
xnu-517.3.15.tar.gz
[apple/xnu.git] / iokit / IOKit / i386 / IOSharedLockImp.h
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
27 *
28 * HISTORY
29 *
30 */
31
32 /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
33 *
34 * EventShmemLock.h - Shared memory area locks for use between the
35 * WindowServer and the Event Driver.
36 *
37 *
38 * HISTORY
39 * 29 April 1992 Mike Paquette at NeXT
40 * Created.
41 *
42 * Multiprocessor locks used within the shared memory area between the
43 * kernel and event system. These must work in both user and kernel mode.
44 * The locks are defined in an include file so they get exported to the local
45 * include file area.
46 *
47 * This is basically a ripoff of the spin locks under the cthreads packages.
48 */
49
50 #ifndef _IOKIT_IOSHAREDLOCKIMP_H
51 #define _IOKIT_IOSHAREDLOCKIMP_H
52
53 #include <architecture/i386/asm_help.h>
54
55 // 'Till we're building in kernel
56 .macro DISABLE_PREEMPTION
57 #ifdef KERNEL
58 #endif
59 .endmacro
60 .macro ENABLE_PREEMPTION
61 #ifdef KERNEL
62 #endif
63 .endmacro
64
65 /*
66 * void
67 * ev_lock(p)
68 * int *p;
69 *
70 * Lock the lock pointed to by p. Spin (possibly forever) until the next
71 * lock is available.
72 */
73 TEXT
74
75 #ifndef KERNEL
76 LEAF(_ev_lock, 0)
77 LEAF(_IOSpinLock, 0)
78 movl 4(%esp), %ecx
79 0:
80 xorl %eax, %eax
81 rep
82 nop /* pause for hyperthreaded CPU's */
83 lock
84 cmpxchgl %ecx, (%ecx)
85 jne 0b
86 ret
87 END(_ev_lock)
88 #endif
89
90 /*
91 * void
92 * ev_unlock(p)
93 * int *p;
94 *
95 * Unlock the lock pointed to by p.
96 */
97 LEAF(_ev_unlock, 0)
98 LEAF(_IOSpinUnlock, 0)
99 movl 4(%esp), %ecx
100 movl $0, (%ecx)
101 ENABLE_PREEMPTION()
102 ret
103 END(_ev_unlock)
104
105
106
107 /*
108 * int
109 * ev_try_lock(p)
110 * int *p;
111 *
112 * Try to lock p. Return zero if not successful.
113 */
114
115 LEAF(_ev_try_lock, 0)
116 LEAF(_IOTrySpinLock, 0)
117 DISABLE_PREEMPTION()
118 movl 4(%esp), %ecx
119 xorl %eax, %eax
120 lock
121 cmpxchgl %ecx, (%ecx)
122 jne 1f
123 movl $1, %eax /* yes */
124 ret
125 1:
126 ENABLE_PREEMPTION()
127 xorl %eax, %eax /* no */
128 END(_ev_try_lock)
129
130
131 #endif /* ! _IOKIT_IOSHAREDLOCKIMP_H */