2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
35 * Revision 1.1.1.1 1998/09/22 21:05:30 wsanchez
36 * Import of Mac OS X kernel (~semeria)
38 * Revision 1.1.1.1 1998/03/07 02:25:45 wsanchez
39 * Import of OSF Mach kernel (~mburg)
41 * Revision 1.1.4.1 1995/06/13 18:20:29 sjs
42 * Merged from flipc_shared.
45 * Revision 1.1.2.3 1995/03/09 19:42:30 rwd
46 * Move yield function out of macro and prototype.
47 * [1995/03/09 19:36:25 rwd]
49 * Revision 1.1.2.2 1995/02/21 17:23:11 randys
50 * Re-indented code to four space indentation
51 * [1995/02/21 16:25:39 randys]
53 * Revision 1.1.2.1 1994/12/20 19:02:06 randys
54 * Moved definition of flipc_simple_lock to flipc_cb.h
55 * [1994/12/20 17:34:44 randys]
57 * Separated the lock macros out into machine dependent and independent files;
58 * this is the machine independent file.
59 * [1994/12/20 16:43:38 randys]
67 * The machine independent part of the flipc_simple_locks definitions.
68 * Most of the locks definitions is in flipc_dep.h, but what isn't
69 * dependent on the platform being used is here.
73 * Note that the locks defined in this file and in flipc_dep.h are only
74 * for use by user level code. The reason why this file is visible to
75 * the kernel is that the kernel section of flipc needs to initialize
79 #ifndef _MACH_FLIPC_LOCKS_H_
80 #define _MACH_FLIPC_LOCKS_H_
82 /* Get the simple lock type. */
83 #include <mach/flipc_cb.h>
86 * Lock function prototypes. This needs to be before any lock definitions
87 * that happen to be macros.
90 /* Initializes lock. Always a macro (so that kernel code can use it without
91 library assistance). */
92 void flipc_simple_lock_init(flipc_simple_lock
*lock
);
94 /* Returns 1 if lock gained, 0 otherwise. */
95 int flipc_simple_lock_try(flipc_simple_lock
*lock
);
97 /* Returns 1 if lock is locked, 0 otherwise. */
98 int flipc_simple_lock_locked(flipc_simple_lock
*lock
);
100 /* Releases the lock. */
101 void flipc_simple_lock_release(flipc_simple_lock
*lock
);
104 void flipc_simple_lock_acquire(flipc_simple_lock
*lock
);
106 /* Take two locks. Does not hold one while spinning on the
108 void flipc_simple_lock_acquire_2(flipc_simple_lock
*lock1
,
109 flipc_simple_lock
*lock2
);
111 /* Get the machine dependent stuff. The things that need to be
112 * defined in a machine dependent fashion are:
114 * flipc_simple_lock_init (must be a macro)
115 * flipc_simple_lock_try
116 * flipc_simple_lock_locked
117 * flipc_simple_lock_release
119 * These last three don't necessarily have to be macros, but if they
120 * aren't definitions must be included in the machine dependent
121 * part of the user level library code.
123 #include <mach/machine/flipc_dep.h>
126 * Set at flipc initialization time to thread_yield argument to
130 extern void (*flipc_simple_lock_yield_fn
)(void);
133 * Machine independent definitions; defined in terms of above routines.
136 /* Take the lock. Assumes an external define saying how long to
137 spin, and an external function to call when we've spun too long. */
138 #define flipc_simple_lock_acquire(lock) \
140 int __spin_count = 0; \
142 while (flipc_simple_lock_locked(lock) \
143 || !flipc_simple_lock_try(lock)) \
144 if (++__spin_count > LOCK_SPIN_LIMIT) { \
145 (*flipc_simple_lock_yield_fn)(); \
150 /* Take two locks. Hold neither while spinning on the other. */
151 #define flipc_simple_lock_acquire_2(lock1, lock2) \
153 int __spin_count = 0; \
156 while (flipc_simple_lock_locked(lock1) \
157 || !flipc_simple_lock_try(lock1)) \
158 if (++__spin_count > LOCK_SPIN_LIMIT) { \
159 (*flipc_simple_lock_yield_fn)(); \
163 if (flipc_simple_lock_try(lock2)) \
165 flipc_simple_lock_release(lock1); \
167 while (flipc_simple_lock_locked(lock2) \
168 || !flipc_simple_lock_try(lock2)) \
169 if (++__spin_count > LOCK_SPIN_LIMIT) { \
170 (*flipc_simple_lock_yield_fn)(); \
174 if (flipc_simple_lock_try(lock1)) \
176 flipc_simple_lock_release(lock2); \
180 #endif /* _MACH_FLIPC_LOCKS_H_ */