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_FUTEX_WAITER_H_
0017 #define ABSL_SYNCHRONIZATION_INTERNAL_FUTEX_WAITER_H_
0018 
0019 #include <atomic>
0020 #include <cstdint>
0021 
0022 #include "absl/base/config.h"
0023 #include "absl/synchronization/internal/kernel_timeout.h"
0024 #include "absl/synchronization/internal/futex.h"
0025 #include "absl/synchronization/internal/waiter_base.h"
0026 
0027 #ifdef ABSL_INTERNAL_HAVE_FUTEX
0028 
0029 namespace absl {
0030 ABSL_NAMESPACE_BEGIN
0031 namespace synchronization_internal {
0032 
0033 #define ABSL_INTERNAL_HAVE_FUTEX_WAITER 1
0034 
0035 class FutexWaiter : public WaiterCrtp<FutexWaiter> {
0036  public:
0037   FutexWaiter() : futex_(0) {}
0038 
0039   bool Wait(KernelTimeout t);
0040   void Post();
0041   void Poke();
0042 
0043   static constexpr char kName[] = "FutexWaiter";
0044 
0045  private:
0046   // Atomically check that `*v == val`, and if it is, then sleep until the
0047   // timeout `t` has been reached, or until woken by `Wake()`.
0048   static int WaitUntil(std::atomic<int32_t>* v, int32_t val,
0049                        KernelTimeout t);
0050 
0051   // Futexes are defined by specification to be 32-bits.
0052   // Thus std::atomic<int32_t> must be just an int32_t with lockfree methods.
0053   std::atomic<int32_t> futex_;
0054   static_assert(sizeof(int32_t) == sizeof(futex_), "Wrong size for futex");
0055 };
0056 
0057 }  // namespace synchronization_internal
0058 ABSL_NAMESPACE_END
0059 }  // namespace absl
0060 
0061 #endif  // ABSL_INTERNAL_HAVE_FUTEX
0062 
0063 #endif  // ABSL_SYNCHRONIZATION_INTERNAL_FUTEX_WAITER_H_