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