tls.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. *
  3. * Copyright 2015 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #ifndef GRPC_SUPPORT_TLS_H
  19. #define GRPC_SUPPORT_TLS_H
  20. #include <grpc/support/port_platform.h>
  21. /** Thread local storage.
  22. A minimal wrapper that should be implementable across many compilers,
  23. and implementable efficiently across most modern compilers.
  24. Thread locals have type intptr_t.
  25. Declaring a thread local variable 'foo':
  26. GPR_TLS_DECL(foo);
  27. Thread locals always have static scope.
  28. Declaring a thread local class variable 'foo':
  29. GPR_TLS_CLASS_DECL(foo);
  30. Defining the thread local class variable:
  31. GPR_TLS_CLASS_DEF(foo);
  32. Initializing a thread local (must be done at library initialization
  33. time):
  34. gpr_tls_init(&foo);
  35. Destroying a thread local:
  36. gpr_tls_destroy(&foo);
  37. Setting a thread local (returns new_value):
  38. gpr_tls_set(&foo, new_value);
  39. Accessing a thread local:
  40. current_value = gpr_tls_get(&foo);
  41. ALL functions here may be implemented as macros. */
  42. #ifdef GPR_GCC_TLS
  43. #include <grpc/support/tls_gcc.h>
  44. #endif
  45. #ifdef GPR_MSVC_TLS
  46. #include <grpc/support/tls_msvc.h>
  47. #endif
  48. #ifdef GPR_PTHREAD_TLS
  49. #include <grpc/support/tls_pthread.h>
  50. #endif
  51. #endif /* GRPC_SUPPORT_TLS_H */