Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / lib / scudo / standalone / condition_variable.h
blob549f6e9f787bad994deaddf1257cc9423f9f29c5
1 //===-- condition_variable.h ------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef SCUDO_CONDITION_VARIABLE_H_
10 #define SCUDO_CONDITION_VARIABLE_H_
12 #include "condition_variable_base.h"
14 #include "common.h"
15 #include "platform.h"
17 #include "condition_variable_linux.h"
19 namespace scudo {
21 // A default implementation of default condition variable. It doesn't do a real
22 // `wait`, instead it spins a short amount of time only.
23 class ConditionVariableDummy
24 : public ConditionVariableBase<ConditionVariableDummy> {
25 public:
26 void notifyAllImpl(UNUSED HybridMutex &M) REQUIRES(M) {}
28 void waitImpl(UNUSED HybridMutex &M) REQUIRES(M) {
29 M.unlock();
31 constexpr u32 SpinTimes = 64;
32 volatile u32 V = 0;
33 for (u32 I = 0; I < SpinTimes; ++I) {
34 u32 Tmp = V + 1;
35 V = Tmp;
38 M.lock();
42 template <typename Config, typename = const bool>
43 struct ConditionVariableState {
44 static constexpr bool enabled() { return false; }
45 // This is only used for compilation purpose so that we won't end up having
46 // many conditional compilations. If you want to use `ConditionVariableDummy`,
47 // define `ConditionVariableT` in your allocator configuration. See
48 // allocator_config.h for more details.
49 using ConditionVariableT = ConditionVariableDummy;
52 template <typename Config>
53 struct ConditionVariableState<Config, decltype(Config::UseConditionVariable)> {
54 static constexpr bool enabled() { return true; }
55 using ConditionVariableT = typename Config::ConditionVariableT;
58 } // namespace scudo
60 #endif // SCUDO_CONDITION_VARIABLE_H_