|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /*
26: * Copyright (c) 1992 NeXT Computer, Inc.
27: *
28: * Simple spin locks.
29: *
30: * HISTORY
31: *
32: * 19 November 1992 ? at NeXT
33: * Created.
34: */
35:
36: #import <mach/boolean.h>
37:
38: #ifndef _MACH_I386_SIMPLE_LOCK_H_
39: #define _MACH_I386_SIMPLE_LOCK_H_
40:
41: #define _MACHINE_SIMPLE_LOCK_DATA_
42:
43: struct slock {
44: boolean_t locked;
45: };
46:
47: typedef struct slock simple_lock_data_t;
48: typedef simple_lock_data_t *simple_lock_t;
49:
50: static __inline__
51: void
52: simple_lock_init(
53: simple_lock_t slock
54: )
55: {
56: slock->locked = FALSE;
57: }
58:
59: static __inline__
60: boolean_t
61: simple_lock_try(
62: simple_lock_t slock
63: )
64: {
65: boolean_t result;
66:
67: asm volatile(
68: "xchgl %1,%0; xorl %3,%0"
69: : "=r" (result), "=m" (slock->locked)
70: : "0" (TRUE), "i" (TRUE));
71:
72: return (result);
73: }
74:
75: static __inline__
76: void
77: simple_lock(
78: simple_lock_t slock
79: )
80: {
81: do
82: {
83: while (slock->locked)
84: continue;
85: }
86: while (!simple_lock_try(slock));
87: }
88:
89: static __inline__
90: void
91: simple_unlock(
92: simple_lock_t slock
93: )
94: {
95: boolean_t result;
96:
97: asm volatile(
98: "xchgl %1,%0"
99: : "=r" (result), "=m" (slock->locked)
100: : "0" (FALSE));
101: }
102:
103: #endif /* _MACH_I386_SIMPLE_LOCK_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.