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