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
23
24extern int32 tls_allocate(void);
25
26#if !_NO_INLINE_ASM && __INTEL__ && __GNUC__
27
28static inline void *
29tls_get(int32 index)
30{
31	void *ret;
32	__asm__ __volatile__ (
33		"movl	%%fs:(,%%edx, 4), %%eax \n\t"
34		: "=a"(ret) : "d"(index) );
35	return ret;
36}
37
38static inline void **
39tls_address(int32 index)
40{
41	void **ret;
42	__asm__ __volatile__ (
43		"movl	%%fs:0, %%eax \n\t"
44		"leal	(%%eax, %%edx, 4), %%eax \n\t"
45		: "=a"(ret) : "d"(index) );
46	return ret;
47}
48
49static inline void
50tls_set(int32 index, void *value)
51{
52	__asm__ __volatile__ (
53		"movl	%%eax, %%fs:(,%%edx, 4) \n\t"
54		: : "d"(index), "a"(value) );
55}
56
57#else
58
59extern void *tls_get(int32 index);
60extern void **tls_address(int32 index);
61extern void tls_set(int32 index, void *value);
62
63#endif
64
65#ifdef __cplusplus
66}
67#endif
68
69#endif	/* _TLS_H */
70