]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/i386/IOSharedLockImp.h
xnu-517.3.7.tar.gz
[apple/xnu.git] / iokit / IOKit / i386 / IOSharedLockImp.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
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
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
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.
1c79356b
A
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
76LEAF(_ev_lock, 0)
77LEAF(_IOSpinLock, 0)
55e303ae
A
78 movl 4(%esp), %ecx
790:
80 xorl %eax, %eax
81 rep
82 nop /* pause for hyperthreaded CPU's */
83 lock
84 cmpxchgl %ecx, (%ecx)
85 jne 0b
86 ret
1c79356b
A
87END(_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 */
97LEAF(_ev_unlock, 0)
98LEAF(_IOSpinUnlock, 0)
55e303ae
A
99 movl 4(%esp), %ecx
100 movl $0, (%ecx)
1c79356b 101 ENABLE_PREEMPTION()
55e303ae 102 ret
1c79356b
A
103END(_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
115LEAF(_ev_try_lock, 0)
116LEAF(_IOTrySpinLock, 0)
117 DISABLE_PREEMPTION()
55e303ae
A
118 movl 4(%esp), %ecx
119 xorl %eax, %eax
120 lock
121 cmpxchgl %ecx, (%ecx)
122 jne 1f
1c79356b
A
123 movl $1, %eax /* yes */
124 ret
1251:
126 ENABLE_PREEMPTION()
127 xorl %eax, %eax /* no */
128END(_ev_try_lock)
129
130
131#endif /* ! _IOKIT_IOSHAREDLOCKIMP_H */