]> git.saurik.com Git - apple/libc.git/blame_incremental - pthreads/pthread_machdep.h
Libc-498.tar.gz
[apple/libc.git] / pthreads / pthread_machdep.h
... / ...
CommitLineData
1/*
2 * Copyright (c) 2003-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*
24 * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991
25 * All Rights Reserved
26 *
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.
32 *
33 * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
34 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
35 * FOR A PARTICULAR PURPOSE.
36 *
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.
42 */
43/*
44 * MkLinux
45 */
46
47/* Machine-dependent definitions for pthread internals. */
48
49#ifndef _POSIX_PTHREAD_MACHDEP_H
50#define _POSIX_PTHREAD_MACHDEP_H
51
52#ifdef __LP64__
53#define _PTHREAD_TSD_OFFSET 0x60
54#else
55#define _PTHREAD_TSD_OFFSET 0x48
56#endif /* __LP64__ */
57
58#ifndef __ASSEMBLER__
59
60#include <System/machine/cpu_capabilities.h>
61
62/*
63** Define macros for inline pthread_getspecific() usage.
64** We reserve a number of slots for Apple internal use.
65** This number can grow dynamically, no need to fix it.
66*/
67
68/* This header contains pre defined thread specific keys */
69/* 0 is used for pthread_self */
70#define _PTHREAD_TSD_SLOT_PTHREAD_SELF 0
71/* Keys 1- 9 for use by dyld, directly or indirectly */
72#define _PTHREAD_TSD_SLOT_DYLD_1 1
73#define _PTHREAD_TSD_SLOT_DYLD_2 2
74#define _PTHREAD_TSD_SLOT_DYLD_3 3
75#define _PTHREAD_TSD_RESERVED_SLOT_COUNT 4
76
77/* Keys 10 - 29 are for Libc/Libsystem internal ussage */
78/* used as __pthread_tsd_first + Num */
79#define __PTK_LIBC_LOCALE_KEY 10
80#define __PTK_LIBC_TTYNAME_KEY 11
81#define __PTK_LIBC_LOCALTIME_KEY 12
82#define __PTK_LIBC_GMTIME_KEY 13
83
84
85/* Keys 30-255 for Non Libsystem usage */
86#define _PTHREAD_TSD_SLOT_OPENGL 30 /* backwards compat sake */
87#define __PTK_FRAMEWORK_OPENGL_KEY 30
88
89/*
90** Define macros for inline pthread_getspecific() usage.
91** We reserve a number of slots for Apple internal use.
92** This number can grow dynamically, no need to fix it.
93*/
94
95
96#if defined(__cplusplus)
97extern "C" {
98#endif
99
100extern void *pthread_getspecific(unsigned long);
101int pthread_key_init_np(int, void (*)(void *));
102
103#if defined(__cplusplus)
104}
105#endif
106
107typedef int pthread_lock_t;
108
109inline static int
110_pthread_has_direct_tsd(void)
111{
112#if defined(__ppc__)
113 int *caps = (int *)_COMM_PAGE_CPU_CAPABILITIES;
114 if (*caps & kFastThreadLocalStorage) {
115 return 1;
116 } else {
117 return 0;
118 }
119#else
120 return 1;
121#endif
122}
123
124inline static void *
125_pthread_getspecific_direct(unsigned long slot)
126{
127 void *ret;
128#if defined(__OPTIMIZE__)
129#if defined(__i386__) || defined(__x86_64__)
130 asm volatile("mov %%gs:%P1, %0" : "=r" (ret) : "i" (slot * sizeof(void *) + _PTHREAD_TSD_OFFSET));
131#elif defined(__ppc__)
132 void **__pthread_tsd;
133 asm volatile("mfspr %0, 259" : "=r" (__pthread_tsd));
134 ret = __pthread_tsd[slot + (_PTHREAD_TSD_OFFSET / sizeof(void *))];
135#elif defined(__ppc64__)
136 register void **__pthread_tsd asm ("r13");
137 ret = __pthread_tsd[slot + (_PTHREAD_TSD_OFFSET / sizeof(void *))];
138#else
139#error no pthread_getspecific_direct implementation for this arch
140#endif
141#else /* ! __OPTIMIZATION__ */
142 ret = pthread_getspecific(slot);
143#endif
144 return ret;
145}
146
147#define LOCK_INIT(l) ((l) = 0)
148#define LOCK_INITIALIZER 0
149
150#endif /* ! __ASSEMBLER__ */
151#endif /* _POSIX_PTHREAD_MACHDEP_H */