Path: blob/main/contrib/llvm-project/compiler-rt/lib/scudo/standalone/condition_variable_linux.cpp
35291 views
//===-- condition_variable_linux.cpp ----------------------------*- 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#include "platform.h"910#if SCUDO_LINUX1112#include "condition_variable_linux.h"1314#include "atomic_helpers.h"1516#include <limits.h>17#include <linux/futex.h>18#include <sys/syscall.h>19#include <unistd.h>2021namespace scudo {2223void ConditionVariableLinux::notifyAllImpl(UNUSED HybridMutex &M) {24const u32 V = atomic_load_relaxed(&Counter);25atomic_store_relaxed(&Counter, V + 1);2627// TODO(chiahungduan): Move the waiters from the futex waiting queue28// `Counter` to futex waiting queue `M` so that the awoken threads won't be29// blocked again due to locked `M` by current thread.30if (LastNotifyAll != V) {31syscall(SYS_futex, reinterpret_cast<uptr>(&Counter), FUTEX_WAKE_PRIVATE,32INT_MAX, nullptr, nullptr, 0);33}3435LastNotifyAll = V + 1;36}3738void ConditionVariableLinux::waitImpl(HybridMutex &M) {39const u32 V = atomic_load_relaxed(&Counter) + 1;40atomic_store_relaxed(&Counter, V);4142// TODO: Use ScopedUnlock when it's supported.43M.unlock();44syscall(SYS_futex, reinterpret_cast<uptr>(&Counter), FUTEX_WAIT_PRIVATE, V,45nullptr, nullptr, 0);46M.lock();47}4849} // namespace scudo5051#endif // SCUDO_LINUX525354