]>
git.saurik.com Git - apple/libc.git/blob - pthreads/pthread_spinlock.h
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991
27 * Permission to use, copy, modify, and distribute this software and
28 * its documentation for any purpose and without fee is hereby granted,
29 * provided that the above copyright notice appears in all copies and
30 * that both the copyright notice and this permission notice appear in
31 * supporting documentation.
33 * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
34 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
35 * FOR A PARTICULAR PURPOSE.
37 * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
38 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
39 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
40 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
41 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
49 * POSIX Threads - IEEE 1003.1c
52 #ifndef _POSIX_PTHREAD_SPINLOCK_H
53 #define _POSIX_PTHREAD_SPINLOCK_H
55 #include <mach/mach.h>
56 #define __APPLE_API_PRIVATE
57 #include <machine/cpu_capabilities.h>
63 #include "pthread_machdep.h" /* Machine-dependent definitions. */
65 /* Number of times to spin when the lock is unavailable and we are on a
66 multiprocessor. On a uniprocessor we yield the processor immediately. */
67 #define MP_SPIN_TRIES 1000
68 extern int _spin_tries
;
69 extern int __is_threaded
;
71 /* Internal mutex locks for data structures */
72 #define TRY_LOCK(v) (!__is_threaded || _spin_lock_try((pthread_lock_t *)&(v)))
74 /* _DO_SPINLOCK_LOCK() takes a (pthread_lock_t *) */
75 #define _DO_SPINLOCK_LOCK(v) _spin_lock(v)
77 /* _DO_SPINLOCK_UNLOCK() takes a (pthread_lock_t *) */
78 #define _DO_SPINLOCK_UNLOCK(v) _spin_unlock(v)
80 /* LOCK() takes a (pthread_lock_t) */
83 if (__is_threaded) { \
84 _DO_SPINLOCK_LOCK((pthread_lock_t *)&(v)); \
88 /* UNLOCK() takes a (pthread_lock_t) */
91 if (__is_threaded) { \
92 _DO_SPINLOCK_UNLOCK((pthread_lock_t *)&(v)); \
98 /* Functions defined in machine-dependent files. */
99 extern void _spin_lock(pthread_lock_t
*lockp
);
100 extern int _spin_lock_try(pthread_lock_t
*lockp
);
101 extern void _spin_unlock(pthread_lock_t
*lockp
);
103 #endif /* _POSIX_PTHREAD_SPINLOCK_H */