brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 34b91a2 Raw
43 lines · c
1//===-- mutex.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 GWP_ASAN_MUTEX_H_10#define GWP_ASAN_MUTEX_H_11 12#include "gwp_asan/platform_specific/mutex_fuchsia.h" // IWYU pragma: keep13#include "gwp_asan/platform_specific/mutex_posix.h"   // IWYU pragma: keep14 15namespace gwp_asan {16class Mutex final : PlatformMutex {17public:18  constexpr Mutex() = default;19  ~Mutex() = default;20  Mutex(const Mutex &) = delete;21  Mutex &operator=(const Mutex &) = delete;22  // Lock the mutex.23  void lock();24  // Nonblocking trylock of the mutex. Returns true if the lock was acquired.25  bool tryLock();26  // Unlock the mutex.27  void unlock();28};29 30class ScopedLock {31public:32  explicit ScopedLock(Mutex &Mx) : Mu(Mx) { Mu.lock(); }33  ~ScopedLock() { Mu.unlock(); }34  ScopedLock(const ScopedLock &) = delete;35  ScopedLock &operator=(const ScopedLock &) = delete;36 37private:38  Mutex Μ39};40} // namespace gwp_asan41 42#endif // GWP_ASAN_MUTEX_H_43