2007-01-26 19:36:29 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2002-10-23 17:54:44 +04:00
|
|
|
#ifndef _TLS_H
|
2003-01-06 10:57:10 +03:00
|
|
|
#define _TLS_H
|
2007-01-26 19:36:29 +03:00
|
|
|
|
2002-10-23 17:54:44 +04:00
|
|
|
|
|
|
|
#include <BeBuild.h>
|
|
|
|
#include <SupportDefs.h>
|
|
|
|
|
2007-01-26 19:36:29 +03:00
|
|
|
|
2003-01-06 10:57:10 +03:00
|
|
|
/* A maximum of 64 keys is allowed to store in TLS - the key is reserved
|
|
|
|
* process-wide. Note that tls_allocate() will return B_NO_MEMORY if you
|
|
|
|
* try to exceed this limit.
|
|
|
|
*/
|
2007-01-26 19:36:29 +03:00
|
|
|
#define TLS_MAX_KEYS 64
|
|
|
|
|
2002-10-23 17:54:44 +04:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2003-01-06 10:57:10 +03:00
|
|
|
extern int32 tls_allocate(void);
|
2002-10-23 17:54:44 +04:00
|
|
|
|
2003-01-06 10:57:10 +03:00
|
|
|
#if !_NO_INLINE_ASM && __INTEL__ && __GNUC__
|
2002-10-23 17:54:44 +04:00
|
|
|
|
2003-01-06 10:57:10 +03:00
|
|
|
static inline void *
|
|
|
|
tls_get(int32 index)
|
|
|
|
{
|
|
|
|
void *ret;
|
2002-10-23 17:54:44 +04:00
|
|
|
__asm__ __volatile__ (
|
|
|
|
"movl %%fs:(,%%edx, 4), %%eax \n\t"
|
|
|
|
: "=a"(ret) : "d"(index) );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-01-06 10:57:10 +03:00
|
|
|
static inline void **
|
|
|
|
tls_address(int32 index)
|
|
|
|
{
|
2003-01-07 03:20:52 +03:00
|
|
|
void **ret;
|
2002-10-23 17:54:44 +04:00
|
|
|
__asm__ __volatile__ (
|
|
|
|
"movl %%fs:0, %%eax \n\t"
|
|
|
|
"leal (%%eax, %%edx, 4), %%eax \n\t"
|
|
|
|
: "=a"(ret) : "d"(index) );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-01-06 10:57:10 +03:00
|
|
|
static inline void
|
|
|
|
tls_set(int32 index, void *value)
|
|
|
|
{
|
2002-10-23 17:54:44 +04:00
|
|
|
__asm__ __volatile__ (
|
|
|
|
"movl %%eax, %%fs:(,%%edx, 4) \n\t"
|
|
|
|
: : "d"(index), "a"(value) );
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2003-01-06 10:57:10 +03:00
|
|
|
extern void *tls_get(int32 index);
|
|
|
|
extern void **tls_address(int32 index);
|
|
|
|
extern void tls_set(int32 index, void *value);
|
2002-10-23 17:54:44 +04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-01-06 10:57:10 +03:00
|
|
|
#endif /* _TLS_H */
|