stdcpp_waiter.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2023 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_STDCPP_WAITER_H_
  16. #define ABSL_SYNCHRONIZATION_INTERNAL_STDCPP_WAITER_H_
  17. #include <condition_variable> // NOLINT(build/c++11)
  18. #include <mutex> // NOLINT(build/c++11)
  19. #include "absl/base/config.h"
  20. #include "absl/synchronization/internal/kernel_timeout.h"
  21. #include "absl/synchronization/internal/waiter_base.h"
  22. namespace absl {
  23. ABSL_NAMESPACE_BEGIN
  24. namespace synchronization_internal {
  25. #define ABSL_INTERNAL_HAVE_STDCPP_WAITER 1
  26. class StdcppWaiter : public WaiterCrtp<StdcppWaiter> {
  27. public:
  28. StdcppWaiter();
  29. bool Wait(KernelTimeout t);
  30. void Post();
  31. void Poke();
  32. static constexpr char kName[] = "StdcppWaiter";
  33. private:
  34. // REQUIRES: mu_ must be held.
  35. void InternalCondVarPoke();
  36. std::mutex mu_;
  37. std::condition_variable cv_;
  38. int waiter_count_;
  39. int wakeup_count_; // Unclaimed wakeups.
  40. };
  41. } // namespace synchronization_internal
  42. ABSL_NAMESPACE_END
  43. } // namespace absl
  44. #endif // ABSL_SYNCHRONIZATION_INTERNAL_STDCPP_WAITER_H_