libc-tsd.h 2.9 KB

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