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 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef SCUDO_CONDITION_VARIABLE_H_ |
10 | #define SCUDO_CONDITION_VARIABLE_H_ |
11 | |
12 | #include "condition_variable_base.h" |
13 | |
14 | #include "common.h" |
15 | #include "platform.h" |
16 | |
17 | #include "condition_variable_linux.h" |
18 | |
19 | namespace scudo { |
20 | |
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) {} |
27 | |
28 | void waitImpl(UNUSED HybridMutex &M) REQUIRES(M) { |
29 | M.unlock(); |
30 | |
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; |
36 | } |
37 | |
38 | M.lock(); |
39 | } |
40 | }; |
41 | |
42 | } // namespace scudo |
43 | |
44 | #endif // SCUDO_CONDITION_VARIABLE_H_ |
45 | |