proxygen
Futex.h
Go to the documentation of this file.
1 /*
2  * Copyright 2013-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <atomic>
20 #include <cassert>
21 #include <chrono>
22 #include <cstdint>
23 #include <limits>
24 #include <type_traits>
25 
27 
28 namespace folly {
29 namespace detail {
30 
31 enum class FutexResult {
32  VALUE_CHANGED, /* futex value didn't match expected */
33  AWOKEN, /* wakeup by matching futex wake, or spurious wakeup */
34  INTERRUPTED, /* wakeup by interrupting signal */
35  TIMEDOUT, /* wakeup by expiring deadline */
36 };
37 
50 template <template <typename> class Atom = std::atomic>
51 using Futex = Atom<std::uint32_t>;
52 
58 template <typename Futex>
60 futexWait(const Futex* futex, uint32_t expected, uint32_t waitMask = -1);
61 
72 template <
73  typename Futex,
74  class Clock,
75  class Duration = typename Clock::duration>
77  const Futex* futex,
78  uint32_t expected,
79  std::chrono::time_point<Clock, Duration> const& deadline,
80  uint32_t waitMask = -1);
81 
91 template <typename Futex>
92 int futexWake(
93  const Futex* futex,
95  uint32_t wakeMask = -1);
96 
100 template <typename T>
101 struct EmulatedFutexAtomic : public std::atomic<T> {
102  EmulatedFutexAtomic() noexcept = default;
103  constexpr /* implicit */ EmulatedFutexAtomic(T init) noexcept
104  : std::atomic<T>(init) {}
105  // It doesn't copy or move
107 };
108 
109 } // namespace detail
110 } // namespace folly
111 
112 #include <folly/detail/Futex-inl.h>
constexpr EmulatedFutexAtomic(T init) noexcept
Definition: Futex.h:103
LogLevel max
Definition: LogLevel.cpp:31
Atom< std::uint32_t > Futex
Definition: Futex.h:51
folly::std T
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
requires E e noexcept(noexcept(s.error(std::move(e))))
FutexResult futexWait(const Futex *futex, uint32_t expected, uint32_t waitMask)
Definition: Futex-inl.h:100
FOLLY_PUSH_WARNING RHS rhs
Definition: Traits.h:649
void init(int *argc, char ***argv, bool removeFlags)
Definition: Init.cpp:34
std::chrono::milliseconds Duration
Definition: Types.h:36
#define Atom
FutexResult futexWaitUntil(const Futex *futex, uint32_t expected, std::chrono::time_point< Clock, Duration > const &deadline, uint32_t waitMask)
Definition: Futex-inl.h:112
int * count
int futexWake(const Futex *futex, int count, uint32_t wakeMask)
Definition: Futex-inl.h:107