per_thread_tls.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2017 The Abseil Authors.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef ABSL_BASE_INTERNAL_PER_THREAD_TLS_H_
  15. #define ABSL_BASE_INTERNAL_PER_THREAD_TLS_H_
  16. // This header defines two macros:
  17. //
  18. // If the platform supports thread-local storage:
  19. //
  20. // * ABSL_PER_THREAD_TLS_KEYWORD is the C keyword needed to declare a
  21. // thread-local variable
  22. // * ABSL_PER_THREAD_TLS is 1
  23. //
  24. // Otherwise:
  25. //
  26. // * ABSL_PER_THREAD_TLS_KEYWORD is empty
  27. // * ABSL_PER_THREAD_TLS is 0
  28. //
  29. // Microsoft C supports thread-local storage.
  30. // GCC supports it if the appropriate version of glibc is available,
  31. // which the programmer can indicate by defining ABSL_HAVE_TLS
  32. #include "absl/base/port.h" // For ABSL_HAVE_TLS
  33. #if defined(ABSL_PER_THREAD_TLS)
  34. #error ABSL_PER_THREAD_TLS cannot be directly set
  35. #elif defined(ABSL_PER_THREAD_TLS_KEYWORD)
  36. #error ABSL_PER_THREAD_TLS_KEYWORD cannot be directly set
  37. #elif defined(ABSL_HAVE_TLS)
  38. #define ABSL_PER_THREAD_TLS_KEYWORD __thread
  39. #define ABSL_PER_THREAD_TLS 1
  40. #elif defined(_MSC_VER)
  41. #define ABSL_PER_THREAD_TLS_KEYWORD __declspec(thread)
  42. #define ABSL_PER_THREAD_TLS 1
  43. #else
  44. #define ABSL_PER_THREAD_TLS_KEYWORD
  45. #define ABSL_PER_THREAD_TLS 0
  46. #endif
  47. #endif // ABSL_BASE_INTERNAL_PER_THREAD_TLS_H_