TLS.h revision 5ffbe7d7
1/*
2 * Copyright 2003-2007 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _TLS_H
6#define _TLS_H
7
8
9#include <BeBuild.h>
10#include <SupportDefs.h>
11
12
13/* A maximum of 64 keys is allowed to store in TLS - the key is reserved
14 * process-wide. Note that tls_allocate() will return B_NO_MEMORY if you
15 * try to exceed this limit.
16 */
17#define TLS_MAX_KEYS 64
18
19
20#ifdef __cplusplus
21extern "C" {
22#endif	/* __cplusplus */
23
24extern int32 tls_allocate(void);
25
26#if !_NO_INLINE_ASM && __i386__ && __GNUC__
27
28static inline void *
29tls_get(int32 index)
30{
31	void *ret;
32	__asm__ __volatile__ (
33		"movl	%%fs:(, %1, 4), %0"
34		: "=r" (ret) : "r" (index));
35	return ret;
36}
37
38static inline void **
39tls_address(int32 index)
40{
41	void **ret;
42	__asm__ __volatile__ (
43		"movl	%%fs:0, %0\n\t"
44		"leal	(%0, %1, 4), %0\n\t"
45		: "=&r" (ret) : "r" (index));
46	return ret;
47}
48
49static inline void
50tls_set(int32 index, void *value)
51{
52	__asm__ __volatile__ (
53		"movl	%1, %%fs:(, %0, 4)"
54		: : "r" (index), "r" (value));
55}
56
57#else	/* !_NO_INLINE_ASM && __i386__ && __GNUC__ */
58
59extern void *tls_get(int32 index);
60extern void **tls_address(int32 index);
61extern void tls_set(int32 index, void *value);
62
63#endif	/* !_NO_INLINE_ASM && __i386__ && __GNUC__ */
64
65#ifdef __cplusplus
66}
67#endif	/* __cplusplus */
68
69#endif	/* _TLS_H */
70