Path: blob/main/contrib/llvm-project/compiler-rt/lib/scudo/standalone/condition_variable_base.h
35291 views
//===-- condition_variable_base.h -------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef SCUDO_CONDITION_VARIABLE_BASE_H_9#define SCUDO_CONDITION_VARIABLE_BASE_H_1011#include "mutex.h"12#include "thread_annotations.h"1314namespace scudo {1516template <typename Derived> class ConditionVariableBase {17public:18constexpr ConditionVariableBase() = default;1920void bindTestOnly(HybridMutex &Mutex) {21#if SCUDO_DEBUG22boundMutex = &Mutex;23#else24(void)Mutex;25#endif26}2728void notifyAll(HybridMutex &M) REQUIRES(M) {29#if SCUDO_DEBUG30CHECK_EQ(&M, boundMutex);31#endif32getDerived()->notifyAllImpl(M);33}3435void wait(HybridMutex &M) REQUIRES(M) {36#if SCUDO_DEBUG37CHECK_EQ(&M, boundMutex);38#endif39getDerived()->waitImpl(M);40}4142protected:43Derived *getDerived() { return static_cast<Derived *>(this); }4445#if SCUDO_DEBUG46// Because thread-safety analysis doesn't support pointer aliasing, we are not47// able to mark the proper annotations without false positive. Instead, we48// pass the lock and do the same-lock check separately.49HybridMutex *boundMutex = nullptr;50#endif51};5253} // namespace scudo5455#endif // SCUDO_CONDITION_VARIABLE_BASE_H_565758