tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

stdcpp_waiter.h (1600B)


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