]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm-project/libcxx/src/mutex_destructor.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm-project / libcxx / src / mutex_destructor.cpp
1 //===--------------------- mutex_destructor.cpp ---------------------------===//
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 //===----------------------------------------------------------------------===//
8
9 // Define ~mutex.
10 //
11 // On some platforms ~mutex has been made trivial and the definition is only
12 // provided for ABI compatibility.
13 //
14 // In order to avoid ODR violations within libc++ itself, we need to ensure
15 // that *nothing* sees the non-trivial mutex declaration. For this reason
16 // we re-declare the entire class in this file instead of using
17 // _LIBCPP_BUILDING_LIBRARY to change the definition in the headers.
18
19 #include "__config"
20 #include "__threading_support"
21
22 #if !defined(_LIBCPP_HAS_NO_THREADS)
23 #if _LIBCPP_ABI_VERSION == 1 || !defined(_LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION)
24 #define NEEDS_MUTEX_DESTRUCTOR
25 #endif
26 #endif
27
28 _LIBCPP_BEGIN_NAMESPACE_STD
29
30 #ifdef NEEDS_MUTEX_DESTRUCTOR
31 class _LIBCPP_TYPE_VIS mutex
32 {
33     __libcpp_mutex_t __m_ = _LIBCPP_MUTEX_INITIALIZER;
34
35 public:
36     _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY
37     constexpr mutex() = default;
38     mutex(const mutex&) = delete;
39     mutex& operator=(const mutex&) = delete;
40     ~mutex() noexcept;
41 };
42
43
44 mutex::~mutex() _NOEXCEPT
45 {
46     __libcpp_mutex_destroy(&__m_);
47 }
48
49 #endif // !_LIBCPP_HAS_NO_THREADS
50 _LIBCPP_END_NAMESPACE_STD
51