Back to index

glibc  2.9
libc-tsd.h
Go to the documentation of this file.
00001 /* libc-internal interface for thread-specific data.  Stub or TLS version.
00002    Copyright (C) 1998,2001,2002,2008 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #ifndef _GENERIC_BITS_LIBC_TSD_H
00021 #define _GENERIC_BITS_LIBC_TSD_H 1
00022 
00023 /* This file defines the following macros for accessing a small fixed
00024    set of thread-specific `void *' data used only internally by libc.
00025 
00026    __libc_tsd_define(CLASS, TYPE, KEY)    -- Define or declare a datum with TYPE
00027                                       for KEY.  CLASS can be `static' for
00028                                       keys used in only one source file,
00029                                       empty for global definitions, or
00030                                       `extern' for global declarations.
00031    __libc_tsd_address(TYPE, KEY)   -- Return the `TYPE *' pointing to
00032                                       the current thread's datum for KEY.
00033    __libc_tsd_get(TYPE, KEY)              -- Return the `TYPE' datum for KEY.
00034    __libc_tsd_set(TYPE, KEY, VALUE)       -- Set the datum for KEY to VALUE.
00035 
00036    The set of available KEY's will usually be provided as an enum,
00037    and contains (at least):
00038               _LIBC_TSD_KEY_MALLOC
00039               _LIBC_TSD_KEY_DL_ERROR
00040               _LIBC_TSD_KEY_RPC_VARS
00041    All uses must be the literal _LIBC_TSD_* name in the __libc_tsd_* macros.
00042    Some implementations may not provide any enum at all and instead
00043    using string pasting in the macros.  */
00044 
00045 #include <tls.h>
00046 
00047 /* When full support for __thread variables is available, this interface is
00048    just a trivial wrapper for it.  Without TLS, this is the generic/stub
00049    implementation for wholly single-threaded systems.
00050 
00051    We don't define an enum for the possible key values, because the KEYs
00052    translate directly into variables by macro magic.  */
00053 
00054 #if USE___THREAD
00055 # define __libc_tsd_define(CLASS, TYPE, KEY)     \
00056   CLASS __thread TYPE __libc_tsd_##KEY attribute_tls_model_ie;
00057 
00058 # define __libc_tsd_address(TYPE, KEY)           (&__libc_tsd_##KEY)
00059 # define __libc_tsd_get(TYPE, KEY)        (__libc_tsd_##KEY)
00060 # define __libc_tsd_set(TYPE, KEY, VALUE) (__libc_tsd_##KEY = (VALUE))
00061 #else
00062 # define __libc_tsd_define(CLASS, TYPE, KEY)     \
00063   CLASS TYPE __libc_tsd_##KEY##_data;
00064 
00065 # define __libc_tsd_address(TYPE, KEY)           (&__libc_tsd_##KEY##_data)
00066 # define __libc_tsd_get(TYPE, KEY)        (__libc_tsd_##KEY##_data)
00067 # define __libc_tsd_set(TYPE, KEY, VALUE) (__libc_tsd_##KEY##_data = (VALUE))
00068 #endif
00069 
00070 #endif /* bits/libc-tsd.h */