Path: blob/main/contrib/llvm-project/compiler-rt/lib/gwp_asan/mutex.h
35236 views
//===-- mutex.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 GWP_ASAN_MUTEX_H_9#define GWP_ASAN_MUTEX_H_1011#include "gwp_asan/platform_specific/mutex_fuchsia.h" // IWYU pragma: keep12#include "gwp_asan/platform_specific/mutex_posix.h" // IWYU pragma: keep1314namespace gwp_asan {15class Mutex final : PlatformMutex {16public:17constexpr Mutex() = default;18~Mutex() = default;19Mutex(const Mutex &) = delete;20Mutex &operator=(const Mutex &) = delete;21// Lock the mutex.22void lock();23// Nonblocking trylock of the mutex. Returns true if the lock was acquired.24bool tryLock();25// Unlock the mutex.26void unlock();27};2829class ScopedLock {30public:31explicit ScopedLock(Mutex &Mx) : Mu(Mx) { Mu.lock(); }32~ScopedLock() { Mu.unlock(); }33ScopedLock(const ScopedLock &) = delete;34ScopedLock &operator=(const ScopedLock &) = delete;3536private:37Mutex Μ38};39} // namespace gwp_asan4041#endif // GWP_ASAN_MUTEX_H_424344