Path: blob/main/contrib/llvm-project/libcxx/src/mutex_destructor.cpp
35147 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78// Define ~mutex.9//10// On some platforms ~mutex has been made trivial and the definition is only11// provided for ABI compatibility.12//13// In order to avoid ODR violations within libc++ itself, we need to ensure14// that *nothing* sees the non-trivial mutex declaration. For this reason15// we re-declare the entire class in this file instead of using16// _LIBCPP_BUILDING_LIBRARY to change the definition in the headers.1718#include <__config>19#include <__thread/support.h>2021#if _LIBCPP_ABI_VERSION == 1 || !defined(_LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION)22# define NEEDS_MUTEX_DESTRUCTOR23#endif2425_LIBCPP_BEGIN_NAMESPACE_STD2627#ifdef NEEDS_MUTEX_DESTRUCTOR28class _LIBCPP_EXPORTED_FROM_ABI mutex {29__libcpp_mutex_t __m_ = _LIBCPP_MUTEX_INITIALIZER;3031public:32_LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI constexpr mutex() = default;33mutex(const mutex&) = delete;34mutex& operator=(const mutex&) = delete;35~mutex() noexcept;36};3738mutex::~mutex() noexcept { __libcpp_mutex_destroy(&__m_); }39#endif // !NEEDS_MUTEX_DESTRUCTOR4041_LIBCPP_END_NAMESPACE_STD424344