57 lines · c
1//===-- condition_variable_base.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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef SCUDO_CONDITION_VARIABLE_BASE_H_10#define SCUDO_CONDITION_VARIABLE_BASE_H_11 12#include "mutex.h"13#include "thread_annotations.h"14 15namespace scudo {16 17template <typename Derived> class ConditionVariableBase {18public:19 constexpr ConditionVariableBase() = default;20 21 void bindTestOnly(HybridMutex &Mutex) {22#if SCUDO_DEBUG23 boundMutex = &Mutex;24#else25 (void)Mutex;26#endif27 }28 29 void notifyAll(HybridMutex &M) REQUIRES(M) {30#if SCUDO_DEBUG31 CHECK_EQ(&M, boundMutex);32#endif33 getDerived()->notifyAllImpl(M);34 }35 36 void wait(HybridMutex &M) REQUIRES(M) {37#if SCUDO_DEBUG38 CHECK_EQ(&M, boundMutex);39#endif40 getDerived()->waitImpl(M);41 }42 43protected:44 Derived *getDerived() { return static_cast<Derived *>(this); }45 46#if SCUDO_DEBUG47 // Because thread-safety analysis doesn't support pointer aliasing, we are not48 // able to mark the proper annotations without false positive. Instead, we49 // pass the lock and do the same-lock check separately.50 HybridMutex *boundMutex = nullptr;51#endif52};53 54} // namespace scudo55 56#endif // SCUDO_CONDITION_VARIABLE_BASE_H_57