|
|
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: /* Copyright (c) 1997 Apple Computer, Inc. All rights reserved.
26: *
27: * File: mach/ppc/simple_lock.h
28: *
29: * This file contains machine dependent code for exclusion
30: * lock handling on PowerPC-based products.
31: *
32: */
33:
34: #ifndef _MACH_PPC_SIMPLE_LOCK_
35: #define _MACH_PPC_SIMPLE_LOCK_
36:
37: #include <mach/ppc/boolean.h>
38:
39: #define _MACHINE_SIMPLE_LOCK_DATA_
40:
41: struct slock{
42: volatile unsigned int lock_data[4];/* in general 1 bit is sufficient */
43: };
44:
45: typedef struct slock simple_lock_data_t;
46: typedef struct slock *simple_lock_t;
47:
48: #if defined(_KERNEL)
49:
50: #if !defined(DEFINE_SIMPLE_LOCK_PRIMS)
51: extern __inline__
52: #endif
53: void
54: simple_lock_init(
55: simple_lock_t slock
56: )
57: {
58: slock->lock_data[0] = 0;
59: slock->lock_data[1] = 0;
60: slock->lock_data[2] = 0;
61: slock->lock_data[3] = 0;
62: }
63:
64: #if !defined(DEFINE_SIMPLE_LOCK_PRIMS)
65: extern __inline__
66: #endif
67: void
68: simple_unlock(
69: simple_lock_t slock
70: )
71: {
72: __asm__ volatile ("sync");
73: *((volatile int *)(slock)) = 0;
74: }
75:
76: #if !defined(DEFINE_SIMPLE_LOCK_PRIMS)
77: extern __inline__
78: #endif
79: boolean_t
80: simple_lock_try(
81: simple_lock_t slock
82: )
83: {
84: extern boolean_t test_and_set();
85: boolean_t result;
86:
87: result = test_and_set(0, (int *)slock);
88:
89: return (!result);
90: }
91:
92:
93:
94: #if !defined(DEFINE_SIMPLE_LOCK_PRIMS)
95: extern __inline__
96: #endif
97: void
98: #if DIAGNOSTIC
99: real_simple_lock(
100: #else
101: simple_lock(
102: #endif
103: simple_lock_t slock
104: )
105: {
106: extern boolean_t test_and_set();
107: while (test_and_set(0, (int *)slock))
108: continue;
109: }
110:
111: #endif /* _KERNEL */
112: #endif /* _MACH_PPC_SIMPLE_LOCK_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.