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