|
|
1.1 root 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: // 'Till we're building in kernel
53: .macro DISABLE_PREEMPTION
54: #ifdef KERNEL
55: #endif
56: .endmacro
57: .macro ENABLE_PREEMPTION
58: #ifdef KERNEL
59: #endif
60: .endmacro
61:
62: /*
63: * void
64: * ev_lock(p)
65: * int *p;
66: *
67: * Lock the lock pointed to by p. Spin (possibly forever) until the next
68: * lock is available.
69: */
70: TEXT
71:
72: #ifndef KERNEL
73: LEAF(_ev_lock, 0)
74: LEAF(_IOSpinLock, 0)
75: push %eax
76: push %ecx
77: movl $1, %ecx
78: movl 12(%esp), %eax
79: _spin:
80: xchgl %ecx,0(%eax)
81: cmp $0, %ecx
82: jne _spin
83: pop %ecx
84: pop %eax
85: END(_ev_lock)
86: #endif
87:
88: /*
89: * void
90: * ev_unlock(p)
91: * int *p;
92: *
93: * Unlock the lock pointed to by p.
94: */
95: LEAF(_ev_unlock, 0)
96: LEAF(_IOSpinUnlock, 0)
97: push %eax
98: movl 8(%esp),%eax
99: movl $0,0(%eax)
100: ENABLE_PREEMPTION()
101: pop %eax
102: END(_ev_unlock)
103:
104:
105:
106: /*
107: * int
108: * ev_try_lock(p)
109: * int *p;
110: *
111: * Try to lock p. Return zero if not successful.
112: */
113:
114: LEAF(_ev_try_lock, 0)
115: LEAF(_IOTrySpinLock, 0)
116: DISABLE_PREEMPTION()
117: movl 4(%esp), %eax
118: lock;bts $0, 0(%eax)
119: jb 1f
120: movl $1, %eax /* yes */
121: ret
122: 1:
123: ENABLE_PREEMPTION()
124: xorl %eax, %eax /* no */
125: END(_ev_try_lock)
126:
127:
128: #endif /* ! _IOKIT_IOSHAREDLOCKIMP_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.