pthread_waiter.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 Y_ABSL_SYNCHRONIZATION_INTERNAL_PTHREAD_WAITER_H_
  16. #define Y_ABSL_SYNCHRONIZATION_INTERNAL_PTHREAD_WAITER_H_
  17. #if !defined(_WIN32) && !defined(__MINGW32__)
  18. #include <pthread.h>
  19. #include "y_absl/base/config.h"
  20. #include "y_absl/synchronization/internal/kernel_timeout.h"
  21. #include "y_absl/synchronization/internal/waiter_base.h"
  22. namespace y_absl {
  23. Y_ABSL_NAMESPACE_BEGIN
  24. namespace synchronization_internal {
  25. #define Y_ABSL_INTERNAL_HAVE_PTHREAD_WAITER 1
  26. class PthreadWaiter : public WaiterCrtp<PthreadWaiter> {
  27. public:
  28. PthreadWaiter();
  29. bool Wait(KernelTimeout t);
  30. void Post();
  31. void Poke();
  32. static constexpr char kName[] = "PthreadWaiter";
  33. private:
  34. int TimedWait(KernelTimeout t);
  35. // REQUIRES: mu_ must be held.
  36. void InternalCondVarPoke();
  37. pthread_mutex_t mu_;
  38. pthread_cond_t cv_;
  39. int waiter_count_;
  40. int wakeup_count_; // Unclaimed wakeups.
  41. };
  42. } // namespace synchronization_internal
  43. Y_ABSL_NAMESPACE_END
  44. } // namespace y_absl
  45. #endif // !defined(_WIN32) && !defined(__MINGW32__)
  46. #endif // Y_ABSL_SYNCHRONIZATION_INTERNAL_PTHREAD_WAITER_H_