Files
clang-p2996/compiler-rt/lib/gwp_asan/platform_specific/mutex_fuchsia.cpp
Kostya Kortchinsky 3591721ada [GWP-ASan] Add mutexes for Fuchsia
Mitch expressed a preference to not have `#ifdef`s in platform agnostic
code, this change tries to accomodate this.

I am not attached to the method this CL proposes, so if anyone has a
suggestion, I am open.

We move the platform specific member of the mutex into its own platform
specific class that the main `Mutex` class inherits from. Functions are
implemented in their respective platform specific compilation units.

For Fuchsia, we use the sync APIs, as those are also the ones being
used in Scudo.

Differential Revision: https://reviews.llvm.org/D90351
2020-10-29 15:51:13 -07:00

22 lines
731 B
C++

//===-- mutex_fuchsia.cpp ---------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "gwp_asan/mutex.h"
#include <lib/sync/mutex.h>
namespace gwp_asan {
void Mutex::lock() __TA_NO_THREAD_SAFETY_ANALYSIS { sync_mutex_lock(&Mu); }
bool Mutex::tryLock() __TA_NO_THREAD_SAFETY_ANALYSIS {
return sync_mutex_trylock(&Mu) == ZX_OK;
}
void Mutex::unlock() __TA_NO_THREAD_SAFETY_ANALYSIS { sync_mutex_unlock(&Mu); }
} // namespace gwp_asan