]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/i386/IOSharedLockImp.h
xnu-792.2.4.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 * 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 *
35 * HISTORY
36 * 29 April 1992 Mike Paquette at NeXT
37 * Created.
38 *
39 * Multiprocessor locks used within the shared memory area between the
40 * kernel and event system. These must work in both user and kernel mode.
41 * The locks are defined in an include file so they get exported to the local
42 * include file area.
43 *
44 * This is basically a ripoff of the spin locks under the cthreads packages.
45 */
46
47 #ifndef _IOKIT_IOSHAREDLOCKIMP_H
48 #define _IOKIT_IOSHAREDLOCKIMP_H
49
50 #include <architecture/i386/asm_help.h>
51
52 /*
53 * void
54 * ev_lock(p)
55 * int *p;
56 *
57 * Lock the lock pointed to by p. Spin (possibly forever) until the next
58 * lock is available.
59 */
60 TEXT
61
62 #ifndef KERNEL
63 LEAF(_ev_lock, 0)
64 LEAF(_IOSpinLock, 0)
65 movl 4(%esp), %ecx
66 0:
67 xorl %eax, %eax
68 rep
69 nop /* pause for hyperthreaded CPU's */
70 lock
71 cmpxchgl %ecx, (%ecx)
72 jne 0b
73 ret
74 END(_ev_lock)
75 #endif
76
77 /*
78 * void
79 * ev_unlock(p)
80 * int *p;
81 *
82 * Unlock the lock pointed to by p.
83 */
84 LEAF(_ev_unlock, 0)
85 LEAF(_IOSpinUnlock, 0)
86 movl 4(%esp), %ecx
87 movl $0, (%ecx)
88 ret
89 END(_ev_unlock)
90
91
92
93 /*
94 * int
95 * ev_try_lock(p)
96 * int *p;
97 *
98 * Try to lock p. Return zero if not successful.
99 */
100
101 LEAF(_ev_try_lock, 0)
102 LEAF(_IOTrySpinLock, 0)
103 movl 4(%esp), %ecx
104 xorl %eax, %eax
105 lock
106 cmpxchgl %ecx, (%ecx)
107 jne 1f
108 movl $1, %eax /* yes */
109 ret
110 1:
111 xorl %eax, %eax /* no */
112 END(_ev_try_lock)
113
114
115 #endif /* ! _IOKIT_IOSHAREDLOCKIMP_H */