1 //===-- mutex.h -------------------------------------------------*- C++ -*-===//
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-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef GWP_ASAN_MUTEX_H_
10 #define GWP_ASAN_MUTEX_H_
15 #error "GWP-ASan is not supported on this platform."
21 constexpr Mutex() = default;
23 Mutex(const Mutex &) = delete;
24 Mutex &operator=(const Mutex &) = delete;
27 // Nonblocking trylock of the mutex. Returns true if the lock was acquired.
34 pthread_mutex_t Mu = PTHREAD_MUTEX_INITIALIZER;
35 #endif // defined(__unix__)
40 explicit ScopedLock(Mutex &Mx) : Mu(Mx) { Mu.lock(); }
41 ~ScopedLock() { Mu.unlock(); }
42 ScopedLock(const ScopedLock &) = delete;
43 ScopedLock &operator=(const ScopedLock &) = delete;
48 } // namespace gwp_asan
50 #endif // GWP_ASAN_MUTEX_H_