Fix macho-merged-funcs-dwarf.yaml test on Windows
[llvm-project.git] / libcxx / include / __cxx03 / __mutex / mutex.h
blob46c7546f77e32d6aae683bbc91659e036f57c181
1 //===----------------------------------------------------------------------===//
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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___CXX03___MUTEX_MUTEX_H
10 #define _LIBCPP___CXX03___MUTEX_MUTEX_H
12 #include <__cxx03/__config>
13 #include <__cxx03/__thread/support.h>
14 #include <__cxx03/__type_traits/is_nothrow_constructible.h>
16 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17 # pragma GCC system_header
18 #endif
20 #ifndef _LIBCPP_HAS_NO_THREADS
22 _LIBCPP_BEGIN_NAMESPACE_STD
24 class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_THREAD_SAFETY_ANNOTATION(capability("mutex")) mutex {
25 __libcpp_mutex_t __m_ = _LIBCPP_MUTEX_INITIALIZER;
27 public:
28 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR mutex() = default;
30 mutex(const mutex&) = delete;
31 mutex& operator=(const mutex&) = delete;
33 # if defined(_LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION)
34 _LIBCPP_HIDE_FROM_ABI ~mutex() = default;
35 # else
36 ~mutex() _NOEXCEPT;
37 # endif
39 void lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability());
40 bool try_lock() _NOEXCEPT _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_capability(true));
41 void unlock() _NOEXCEPT _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability());
43 typedef __libcpp_mutex_t* native_handle_type;
44 _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() { return &__m_; }
47 static_assert(is_nothrow_default_constructible<mutex>::value, "the default constructor for std::mutex must be nothrow");
49 _LIBCPP_END_NAMESPACE_STD
51 #endif // _LIBCPP_HAS_NO_THREADS
53 #endif // _LIBCPP___CXX03___MUTEX_MUTEX_H