tsan_mutex_interface.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. //
  15. // This file is intended solely for spinlock.h.
  16. // It provides ThreadSanitizer annotations for custom mutexes.
  17. // See <sanitizer/tsan_interface.h> for meaning of these annotations.
  18. #ifndef ABSL_BASE_INTERNAL_TSAN_MUTEX_INTERFACE_H_
  19. #define ABSL_BASE_INTERNAL_TSAN_MUTEX_INTERFACE_H_
  20. #include "absl/base/config.h"
  21. // ABSL_INTERNAL_HAVE_TSAN_INTERFACE
  22. // Macro intended only for internal use.
  23. //
  24. // Checks whether LLVM Thread Sanitizer interfaces are available.
  25. // First made available in LLVM 5.0 (Sep 2017).
  26. #ifdef ABSL_INTERNAL_HAVE_TSAN_INTERFACE
  27. #error "ABSL_INTERNAL_HAVE_TSAN_INTERFACE cannot be directly set."
  28. #endif
  29. #if defined(ABSL_HAVE_THREAD_SANITIZER) && defined(__has_include)
  30. #if __has_include(<sanitizer/tsan_interface.h>)
  31. #define ABSL_INTERNAL_HAVE_TSAN_INTERFACE 1
  32. #endif
  33. #endif
  34. #ifdef ABSL_INTERNAL_HAVE_TSAN_INTERFACE
  35. #include <sanitizer/tsan_interface.h>
  36. #define ABSL_TSAN_MUTEX_CREATE __tsan_mutex_create
  37. #define ABSL_TSAN_MUTEX_DESTROY __tsan_mutex_destroy
  38. #define ABSL_TSAN_MUTEX_PRE_LOCK __tsan_mutex_pre_lock
  39. #define ABSL_TSAN_MUTEX_POST_LOCK __tsan_mutex_post_lock
  40. #define ABSL_TSAN_MUTEX_PRE_UNLOCK __tsan_mutex_pre_unlock
  41. #define ABSL_TSAN_MUTEX_POST_UNLOCK __tsan_mutex_post_unlock
  42. #define ABSL_TSAN_MUTEX_PRE_SIGNAL __tsan_mutex_pre_signal
  43. #define ABSL_TSAN_MUTEX_POST_SIGNAL __tsan_mutex_post_signal
  44. #define ABSL_TSAN_MUTEX_PRE_DIVERT __tsan_mutex_pre_divert
  45. #define ABSL_TSAN_MUTEX_POST_DIVERT __tsan_mutex_post_divert
  46. #else
  47. #define ABSL_TSAN_MUTEX_CREATE(...)
  48. #define ABSL_TSAN_MUTEX_DESTROY(...)
  49. #define ABSL_TSAN_MUTEX_PRE_LOCK(...)
  50. #define ABSL_TSAN_MUTEX_POST_LOCK(...)
  51. #define ABSL_TSAN_MUTEX_PRE_UNLOCK(...)
  52. #define ABSL_TSAN_MUTEX_POST_UNLOCK(...)
  53. #define ABSL_TSAN_MUTEX_PRE_SIGNAL(...)
  54. #define ABSL_TSAN_MUTEX_POST_SIGNAL(...)
  55. #define ABSL_TSAN_MUTEX_PRE_DIVERT(...)
  56. #define ABSL_TSAN_MUTEX_POST_DIVERT(...)
  57. #endif
  58. #endif // ABSL_BASE_INTERNAL_TSAN_MUTEX_INTERFACE_H_