xref: /freebsd/contrib/llvm-project/compiler-rt/lib/scudo/standalone/condition_variable.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1*5f757f3fSDimitry Andric //===-- condition_variable.h ------------------------------------*- C++ -*-===//
2*5f757f3fSDimitry Andric //
3*5f757f3fSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*5f757f3fSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*5f757f3fSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*5f757f3fSDimitry Andric //
7*5f757f3fSDimitry Andric //===----------------------------------------------------------------------===//
8*5f757f3fSDimitry Andric 
9*5f757f3fSDimitry Andric #ifndef SCUDO_CONDITION_VARIABLE_H_
10*5f757f3fSDimitry Andric #define SCUDO_CONDITION_VARIABLE_H_
11*5f757f3fSDimitry Andric 
12*5f757f3fSDimitry Andric #include "condition_variable_base.h"
13*5f757f3fSDimitry Andric 
14*5f757f3fSDimitry Andric #include "common.h"
15*5f757f3fSDimitry Andric #include "platform.h"
16*5f757f3fSDimitry Andric 
17*5f757f3fSDimitry Andric #include "condition_variable_linux.h"
18*5f757f3fSDimitry Andric 
19*5f757f3fSDimitry Andric namespace scudo {
20*5f757f3fSDimitry Andric 
21*5f757f3fSDimitry Andric // A default implementation of default condition variable. It doesn't do a real
22*5f757f3fSDimitry Andric // `wait`, instead it spins a short amount of time only.
23*5f757f3fSDimitry Andric class ConditionVariableDummy
24*5f757f3fSDimitry Andric     : public ConditionVariableBase<ConditionVariableDummy> {
25*5f757f3fSDimitry Andric public:
notifyAllImpl(UNUSED HybridMutex & M)26*5f757f3fSDimitry Andric   void notifyAllImpl(UNUSED HybridMutex &M) REQUIRES(M) {}
27*5f757f3fSDimitry Andric 
waitImpl(UNUSED HybridMutex & M)28*5f757f3fSDimitry Andric   void waitImpl(UNUSED HybridMutex &M) REQUIRES(M) {
29*5f757f3fSDimitry Andric     M.unlock();
30*5f757f3fSDimitry Andric 
31*5f757f3fSDimitry Andric     constexpr u32 SpinTimes = 64;
32*5f757f3fSDimitry Andric     volatile u32 V = 0;
33*5f757f3fSDimitry Andric     for (u32 I = 0; I < SpinTimes; ++I) {
34*5f757f3fSDimitry Andric       u32 Tmp = V + 1;
35*5f757f3fSDimitry Andric       V = Tmp;
36*5f757f3fSDimitry Andric     }
37*5f757f3fSDimitry Andric 
38*5f757f3fSDimitry Andric     M.lock();
39*5f757f3fSDimitry Andric   }
40*5f757f3fSDimitry Andric };
41*5f757f3fSDimitry Andric 
42*5f757f3fSDimitry Andric } // namespace scudo
43*5f757f3fSDimitry Andric 
44*5f757f3fSDimitry Andric #endif // SCUDO_CONDITION_VARIABLE_H_
45