10b57cec5SDimitry Andric //===--------------------- mutex_destructor.cpp ---------------------------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric // Define ~mutex. 100b57cec5SDimitry Andric // 110b57cec5SDimitry Andric // On some platforms ~mutex has been made trivial and the definition is only 120b57cec5SDimitry Andric // provided for ABI compatibility. 130b57cec5SDimitry Andric // 140b57cec5SDimitry Andric // In order to avoid ODR violations within libc++ itself, we need to ensure 150b57cec5SDimitry Andric // that *nothing* sees the non-trivial mutex declaration. For this reason 160b57cec5SDimitry Andric // we re-declare the entire class in this file instead of using 170b57cec5SDimitry Andric // _LIBCPP_BUILDING_LIBRARY to change the definition in the headers. 180b57cec5SDimitry Andric 190b57cec5SDimitry Andric #include "__config" 200b57cec5SDimitry Andric #include "__threading_support" 210b57cec5SDimitry Andric 220b57cec5SDimitry Andric #if !defined(_LIBCPP_HAS_NO_THREADS) 230b57cec5SDimitry Andric #if _LIBCPP_ABI_VERSION == 1 || !defined(_LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION) 240b57cec5SDimitry Andric #define NEEDS_MUTEX_DESTRUCTOR 250b57cec5SDimitry Andric #endif 260b57cec5SDimitry Andric #endif 270b57cec5SDimitry Andric 280b57cec5SDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 290b57cec5SDimitry Andric 300b57cec5SDimitry Andric #ifdef NEEDS_MUTEX_DESTRUCTOR 310b57cec5SDimitry Andric class _LIBCPP_TYPE_VIS mutex 320b57cec5SDimitry Andric { 330b57cec5SDimitry Andric __libcpp_mutex_t __m_ = _LIBCPP_MUTEX_INITIALIZER; 340b57cec5SDimitry Andric 350b57cec5SDimitry Andric public: 360b57cec5SDimitry Andric _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY 370b57cec5SDimitry Andric constexpr mutex() = default; 380b57cec5SDimitry Andric mutex(const mutex&) = delete; 390b57cec5SDimitry Andric mutex& operator=(const mutex&) = delete; 400b57cec5SDimitry Andric ~mutex() noexcept; 410b57cec5SDimitry Andric }; 420b57cec5SDimitry Andric 430b57cec5SDimitry Andric ~mutex()44*5f7ddb14SDimitry Andricmutex::~mutex() noexcept 450b57cec5SDimitry Andric { 460b57cec5SDimitry Andric __libcpp_mutex_destroy(&__m_); 470b57cec5SDimitry Andric } 480b57cec5SDimitry Andric 490b57cec5SDimitry Andric #endif // !_LIBCPP_HAS_NO_THREADS 500b57cec5SDimitry Andric _LIBCPP_END_NAMESPACE_STD 51