waiter.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #ifndef ABSL_SYNCHRONIZATION_INTERNAL_WAITER_H_
  16. #define ABSL_SYNCHRONIZATION_INTERNAL_WAITER_H_
  17. #include "absl/base/config.h"
  18. #include "absl/synchronization/internal/futex_waiter.h"
  19. #include "absl/synchronization/internal/pthread_waiter.h"
  20. #include "absl/synchronization/internal/sem_waiter.h"
  21. #include "absl/synchronization/internal/stdcpp_waiter.h"
  22. #include "absl/synchronization/internal/win32_waiter.h"
  23. // May be chosen at compile time via -DABSL_FORCE_WAITER_MODE=<index>
  24. #define ABSL_WAITER_MODE_FUTEX 0
  25. #define ABSL_WAITER_MODE_SEM 1
  26. #define ABSL_WAITER_MODE_CONDVAR 2
  27. #define ABSL_WAITER_MODE_WIN32 3
  28. #define ABSL_WAITER_MODE_STDCPP 4
  29. #if defined(ABSL_FORCE_WAITER_MODE)
  30. #define ABSL_WAITER_MODE ABSL_FORCE_WAITER_MODE
  31. #elif defined(ABSL_INTERNAL_HAVE_WIN32_WAITER)
  32. #define ABSL_WAITER_MODE ABSL_WAITER_MODE_WIN32
  33. #elif defined(ABSL_INTERNAL_HAVE_FUTEX_WAITER)
  34. #define ABSL_WAITER_MODE ABSL_WAITER_MODE_FUTEX
  35. #elif defined(ABSL_INTERNAL_HAVE_SEM_WAITER)
  36. #define ABSL_WAITER_MODE ABSL_WAITER_MODE_SEM
  37. #elif defined(ABSL_INTERNAL_HAVE_PTHREAD_WAITER)
  38. #define ABSL_WAITER_MODE ABSL_WAITER_MODE_CONDVAR
  39. #elif defined(ABSL_INTERNAL_HAVE_STDCPP_WAITER)
  40. #define ABSL_WAITER_MODE ABSL_WAITER_MODE_STDCPP
  41. #else
  42. #error ABSL_WAITER_MODE is undefined
  43. #endif
  44. namespace absl {
  45. ABSL_NAMESPACE_BEGIN
  46. namespace synchronization_internal {
  47. #if ABSL_WAITER_MODE == ABSL_WAITER_MODE_FUTEX
  48. using Waiter = FutexWaiter;
  49. #elif ABSL_WAITER_MODE == ABSL_WAITER_MODE_SEM
  50. using Waiter = SemWaiter;
  51. #elif ABSL_WAITER_MODE == ABSL_WAITER_MODE_CONDVAR
  52. using Waiter = PthreadWaiter;
  53. #elif ABSL_WAITER_MODE == ABSL_WAITER_MODE_WIN32
  54. using Waiter = Win32Waiter;
  55. #elif ABSL_WAITER_MODE == ABSL_WAITER_MODE_STDCPP
  56. using Waiter = StdcppWaiter;
  57. #endif
  58. } // namespace synchronization_internal
  59. ABSL_NAMESPACE_END
  60. } // namespace absl
  61. #endif // ABSL_SYNCHRONIZATION_INTERNAL_WAITER_H_