1 //===-- condition_variable.h ------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef SCUDO_CONDITION_VARIABLE_H_
10 #define SCUDO_CONDITION_VARIABLE_H_
12 #include "condition_variable_base.h"
17 #include "condition_variable_linux.h"
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
> {
26 void notifyAllImpl(UNUSED HybridMutex
&M
) REQUIRES(M
) {}
28 void waitImpl(UNUSED HybridMutex
&M
) REQUIRES(M
) {
31 constexpr u32 SpinTimes
= 64;
33 for (u32 I
= 0; I
< SpinTimes
; ++I
) {
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
;
60 #endif // SCUDO_CONDITION_VARIABLE_H_