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 21 extern "C" { 22 #endif /* __cplusplus */ 23 24 extern int32 tls_allocate(void); 25 26 #if !_NO_INLINE_ASM && __i386__ && __GNUC__ 27 28 static inline void * 29 tls_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 38 static inline void ** 39 tls_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 49 static inline void 50 tls_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 59 extern void *tls_get(int32 index); 60 extern void **tls_address(int32 index); 61 extern 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