tor-browser

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

pthread_waiter.h (1665B)


      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_PTHREAD_WAITER_H_
     17 #define ABSL_SYNCHRONIZATION_INTERNAL_PTHREAD_WAITER_H_
     18 
     19 #if !defined(_WIN32) && !defined(__MINGW32__)
     20 #include <pthread.h>
     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_PTHREAD_WAITER 1
     31 
     32 class PthreadWaiter : public WaiterCrtp<PthreadWaiter> {
     33 public:
     34  PthreadWaiter();
     35 
     36  bool Wait(KernelTimeout t);
     37  void Post();
     38  void Poke();
     39 
     40  static constexpr char kName[] = "PthreadWaiter";
     41 
     42 private:
     43  int TimedWait(KernelTimeout t);
     44 
     45  // REQUIRES: mu_ must be held.
     46  void InternalCondVarPoke();
     47 
     48  pthread_mutex_t mu_;
     49  pthread_cond_t cv_;
     50  int waiter_count_;
     51  int wakeup_count_;  // Unclaimed wakeups.
     52 };
     53 
     54 }  // namespace synchronization_internal
     55 ABSL_NAMESPACE_END
     56 }  // namespace absl
     57 
     58 #endif  // !defined(_WIN32) && !defined(__MINGW32__)
     59 
     60 #endif  // ABSL_SYNCHRONIZATION_INTERNAL_PTHREAD_WAITER_H_