xref: /haiku/src/system/libroot/posix/glibc/include/bits/libc-tsd.h (revision 5af32e752606778be5dd7379f319fe43cb3f6b8c)
1*5af32e75SAxel Dörfler /* libc-internal interface for thread-specific data.  Stub or TLS version.
2*5af32e75SAxel Dörfler    Copyright (C) 1998,2001,02 Free Software Foundation, Inc.
3*5af32e75SAxel Dörfler    This file is part of the GNU C Library.
4*5af32e75SAxel Dörfler 
5*5af32e75SAxel Dörfler    The GNU C Library is free software; you can redistribute it and/or
6*5af32e75SAxel Dörfler    modify it under the terms of the GNU Lesser General Public
7*5af32e75SAxel Dörfler    License as published by the Free Software Foundation; either
8*5af32e75SAxel Dörfler    version 2.1 of the License, or (at your option) any later version.
9*5af32e75SAxel Dörfler 
10*5af32e75SAxel Dörfler    The GNU C Library is distributed in the hope that it will be useful,
11*5af32e75SAxel Dörfler    but WITHOUT ANY WARRANTY; without even the implied warranty of
12*5af32e75SAxel Dörfler    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13*5af32e75SAxel Dörfler    Lesser General Public License for more details.
14*5af32e75SAxel Dörfler 
15*5af32e75SAxel Dörfler    You should have received a copy of the GNU Lesser General Public
16*5af32e75SAxel Dörfler    License along with the GNU C Library; if not, write to the Free
17*5af32e75SAxel Dörfler    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18*5af32e75SAxel Dörfler    02111-1307 USA.  */
19*5af32e75SAxel Dörfler 
20*5af32e75SAxel Dörfler #ifndef _GENERIC_BITS_LIBC_TSD_H
21*5af32e75SAxel Dörfler #define _GENERIC_BITS_LIBC_TSD_H 1
22*5af32e75SAxel Dörfler 
23*5af32e75SAxel Dörfler /* This file defines the following macros for accessing a small fixed
24*5af32e75SAxel Dörfler    set of thread-specific `void *' data used only internally by libc.
25*5af32e75SAxel Dörfler 
26*5af32e75SAxel Dörfler    __libc_tsd_define(CLASS, KEY)	-- Define or declare a `void *' datum
27*5af32e75SAxel Dörfler    					   for KEY.  CLASS can be `static' for
28*5af32e75SAxel Dörfler 					   keys used in only one source file,
29*5af32e75SAxel Dörfler 					   empty for global definitions, or
30*5af32e75SAxel Dörfler 					   `extern' for global declarations.
31*5af32e75SAxel Dörfler    __libc_tsd_address(KEY)		-- Return the `void **' pointing to
32*5af32e75SAxel Dörfler    					   the current thread's datum for KEY.
33*5af32e75SAxel Dörfler    __libc_tsd_get(KEY)			-- Return the `void *' datum for KEY.
34*5af32e75SAxel Dörfler    __libc_tsd_set(KEY, VALUE)		-- Set the datum for KEY to VALUE.
35*5af32e75SAxel Dörfler 
36*5af32e75SAxel Dörfler    The set of available KEY's will usually be provided as an enum,
37*5af32e75SAxel Dörfler    and contains (at least):
38*5af32e75SAxel Dörfler 		_LIBC_TSD_KEY_MALLOC
39*5af32e75SAxel Dörfler 		_LIBC_TSD_KEY_DL_ERROR
40*5af32e75SAxel Dörfler 		_LIBC_TSD_KEY_RPC_VARS
41*5af32e75SAxel Dörfler    All uses must be the literal _LIBC_TSD_* name in the __libc_tsd_* macros.
42*5af32e75SAxel Dörfler    Some implementations may not provide any enum at all and instead
43*5af32e75SAxel Dörfler    using string pasting in the macros.  */
44*5af32e75SAxel Dörfler 
45*5af32e75SAxel Dörfler #include <TLS.h>
46*5af32e75SAxel Dörfler 
47*5af32e75SAxel Dörfler /* When full support for __thread variables is available, this interface is
48*5af32e75SAxel Dörfler    just a trivial wrapper for it.  Without TLS, this is the generic/stub
49*5af32e75SAxel Dörfler    implementation for wholly single-threaded systems.
50*5af32e75SAxel Dörfler 
51*5af32e75SAxel Dörfler    We don't define an enum for the possible key values, because the KEYs
52*5af32e75SAxel Dörfler    translate directly into variables by macro magic.  */
53*5af32e75SAxel Dörfler 
54*5af32e75SAxel Dörfler #if USE___THREAD
55*5af32e75SAxel Dörfler # define __libc_tsd_define(CLASS, KEY)	\
56*5af32e75SAxel Dörfler   CLASS __thread void *__libc_tsd_##KEY attribute_tls_model_ie;
57*5af32e75SAxel Dörfler 
58*5af32e75SAxel Dörfler # define __libc_tsd_address(KEY)	(&__libc_tsd_##KEY)
59*5af32e75SAxel Dörfler # define __libc_tsd_get(KEY)		(__libc_tsd_##KEY)
60*5af32e75SAxel Dörfler # define __libc_tsd_set(KEY, VALUE)	(__libc_tsd_##KEY = (VALUE))
61*5af32e75SAxel Dörfler #else
62*5af32e75SAxel Dörfler # define __libc_tsd_define(CLASS, KEY)	CLASS void *__libc_tsd_##KEY##_data;
63*5af32e75SAxel Dörfler 
64*5af32e75SAxel Dörfler # define __libc_tsd_address(KEY)	(&__libc_tsd_##KEY##_data)
65*5af32e75SAxel Dörfler # define __libc_tsd_get(KEY)		(__libc_tsd_##KEY##_data)
66*5af32e75SAxel Dörfler # define __libc_tsd_set(KEY, VALUE)	(__libc_tsd_##KEY##_data = (VALUE))
67*5af32e75SAxel Dörfler #endif
68*5af32e75SAxel Dörfler 
69*5af32e75SAxel Dörfler #endif	/* bits/libc-tsd.h */
70