Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:31:55

0001 // Copyright 2023 The Abseil Authors.
0002 //
0003 // Licensed under the Apache License, Version 2.0 (the "License");
0004 // you may not use this file except in compliance with the License.
0005 // You may obtain a copy of the License at
0006 //
0007 //      https://www.apache.org/licenses/LICENSE-2.0
0008 //
0009 // Unless required by applicable law or agreed to in writing, software
0010 // distributed under the License is distributed on an "AS IS" BASIS,
0011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0012 // See the License for the specific language governing permissions and
0013 // limitations under the License.
0014 //
0015 
0016 #ifndef ABSL_SYNCHRONIZATION_INTERNAL_SEM_WAITER_H_
0017 #define ABSL_SYNCHRONIZATION_INTERNAL_SEM_WAITER_H_
0018 
0019 #include "absl/base/config.h"
0020 
0021 #ifdef ABSL_HAVE_SEMAPHORE_H
0022 #include <semaphore.h>
0023 
0024 #include <atomic>
0025 #include <cstdint>
0026 
0027 #include "absl/base/internal/thread_identity.h"
0028 #include "absl/synchronization/internal/futex.h"
0029 #include "absl/synchronization/internal/kernel_timeout.h"
0030 #include "absl/synchronization/internal/waiter_base.h"
0031 
0032 namespace absl {
0033 ABSL_NAMESPACE_BEGIN
0034 namespace synchronization_internal {
0035 
0036 #define ABSL_INTERNAL_HAVE_SEM_WAITER 1
0037 
0038 class SemWaiter : public WaiterCrtp<SemWaiter> {
0039  public:
0040   SemWaiter();
0041 
0042   bool Wait(KernelTimeout t);
0043   void Post();
0044   void Poke();
0045 
0046   static constexpr char kName[] = "SemWaiter";
0047 
0048  private:
0049   int TimedWait(KernelTimeout t);
0050 
0051   sem_t sem_;
0052 
0053   // This seems superfluous, but for Poke() we need to cause spurious
0054   // wakeups on the semaphore. Hence we can't actually use the
0055   // semaphore's count.
0056   std::atomic<int> wakeups_;
0057 };
0058 
0059 }  // namespace synchronization_internal
0060 ABSL_NAMESPACE_END
0061 }  // namespace absl
0062 
0063 #endif  // ABSL_HAVE_SEMAPHORE_H
0064 
0065 #endif  // ABSL_SYNCHRONIZATION_INTERNAL_SEM_WAITER_H_