]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/i386/IOSharedLockImp.h
0478bc429482438269765c2adbefd267389c91a1
[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 push %eax
79 push %ecx
80 movl $1, %ecx
81 movl 12(%esp), %eax
82 _spin:
83 xchgl %ecx,0(%eax)
84 cmp $0, %ecx
85 jne _spin
86 pop %ecx
87 pop %eax
88 END(_ev_lock)
89 #endif
90
91 /*
92 * void
93 * ev_unlock(p)
94 * int *p;
95 *
96 * Unlock the lock pointed to by p.
97 */
98 LEAF(_ev_unlock, 0)
99 LEAF(_IOSpinUnlock, 0)
100 push %eax
101 movl 8(%esp),%eax
102 movl $0,0(%eax)
103 ENABLE_PREEMPTION()
104 pop %eax
105 END(_ev_unlock)
106
107
108
109 /*
110 * int
111 * ev_try_lock(p)
112 * int *p;
113 *
114 * Try to lock p. Return zero if not successful.
115 */
116
117 LEAF(_ev_try_lock, 0)
118 LEAF(_IOTrySpinLock, 0)
119 DISABLE_PREEMPTION()
120 movl 4(%esp), %eax
121 lock;bts $0, 0(%eax)
122 jb 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 */