1 //===-- condition_variable_base.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_BASE_H_
10 #define SCUDO_CONDITION_VARIABLE_BASE_H_
13 #include "thread_annotations.h"
17 template <typename Derived
> class ConditionVariableBase
{
19 constexpr ConditionVariableBase() = default;
21 void bindTestOnly(HybridMutex
&Mutex
) {
29 void notifyAll(HybridMutex
&M
) REQUIRES(M
) {
31 CHECK_EQ(&M
, boundMutex
);
33 getDerived()->notifyAllImpl(M
);
36 void wait(HybridMutex
&M
) REQUIRES(M
) {
38 CHECK_EQ(&M
, boundMutex
);
40 getDerived()->waitImpl(M
);
44 Derived
*getDerived() { return static_cast<Derived
*>(this); }
47 // Because thread-safety analysis doesn't support pointer aliasing, we are not
48 // able to mark the proper annotations without false positive. Instead, we
49 // pass the lock and do the same-lock check separately.
50 HybridMutex
*boundMutex
= nullptr;
56 #endif // SCUDO_CONDITION_VARIABLE_BASE_H_