1*4d6fc14bSjoerg //===--------------------- mutex_destructor.cpp ---------------------------===// 2*4d6fc14bSjoerg // 3*4d6fc14bSjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*4d6fc14bSjoerg // See https://llvm.org/LICENSE.txt for license information. 5*4d6fc14bSjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*4d6fc14bSjoerg // 7*4d6fc14bSjoerg //===----------------------------------------------------------------------===// 8*4d6fc14bSjoerg 9*4d6fc14bSjoerg // Define ~mutex. 10*4d6fc14bSjoerg // 11*4d6fc14bSjoerg // On some platforms ~mutex has been made trivial and the definition is only 12*4d6fc14bSjoerg // provided for ABI compatibility. 13*4d6fc14bSjoerg // 14*4d6fc14bSjoerg // In order to avoid ODR violations within libc++ itself, we need to ensure 15*4d6fc14bSjoerg // that *nothing* sees the non-trivial mutex declaration. For this reason 16*4d6fc14bSjoerg // we re-declare the entire class in this file instead of using 17*4d6fc14bSjoerg // _LIBCPP_BUILDING_LIBRARY to change the definition in the headers. 18*4d6fc14bSjoerg 19*4d6fc14bSjoerg #include "__config" 20*4d6fc14bSjoerg #include "__threading_support" 21*4d6fc14bSjoerg 22*4d6fc14bSjoerg #if !defined(_LIBCPP_HAS_NO_THREADS) 23*4d6fc14bSjoerg #if _LIBCPP_ABI_VERSION == 1 || !defined(_LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION) 24*4d6fc14bSjoerg #define NEEDS_MUTEX_DESTRUCTOR 25*4d6fc14bSjoerg #endif 26*4d6fc14bSjoerg #endif 27*4d6fc14bSjoerg 28*4d6fc14bSjoerg _LIBCPP_BEGIN_NAMESPACE_STD 29*4d6fc14bSjoerg 30*4d6fc14bSjoerg #ifdef NEEDS_MUTEX_DESTRUCTOR 31*4d6fc14bSjoerg class _LIBCPP_TYPE_VIS mutex 32*4d6fc14bSjoerg { 33*4d6fc14bSjoerg __libcpp_mutex_t __m_ = _LIBCPP_MUTEX_INITIALIZER; 34*4d6fc14bSjoerg 35*4d6fc14bSjoerg public: 36*4d6fc14bSjoerg _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY 37*4d6fc14bSjoerg constexpr mutex() = default; 38*4d6fc14bSjoerg mutex(const mutex&) = delete; 39*4d6fc14bSjoerg mutex& operator=(const mutex&) = delete; 40*4d6fc14bSjoerg ~mutex() noexcept; 41*4d6fc14bSjoerg }; 42*4d6fc14bSjoerg 43*4d6fc14bSjoerg ~mutex()44*4d6fc14bSjoergmutex::~mutex() noexcept 45*4d6fc14bSjoerg { 46*4d6fc14bSjoerg __libcpp_mutex_destroy(&__m_); 47*4d6fc14bSjoerg } 48*4d6fc14bSjoerg 49*4d6fc14bSjoerg #endif // !_LIBCPP_HAS_NO_THREADS 50*4d6fc14bSjoerg _LIBCPP_END_NAMESPACE_STD 51