Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:36

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___CXX03___MUTEX_MUTEX_H
0010 #define _LIBCPP___CXX03___MUTEX_MUTEX_H
0011 
0012 #include <__cxx03/__config>
0013 #include <__cxx03/__thread/support.h>
0014 #include <__cxx03/__type_traits/is_nothrow_constructible.h>
0015 
0016 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0017 #  pragma GCC system_header
0018 #endif
0019 
0020 #ifndef _LIBCPP_HAS_NO_THREADS
0021 
0022 _LIBCPP_BEGIN_NAMESPACE_STD
0023 
0024 class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_THREAD_SAFETY_ANNOTATION(capability("mutex")) mutex {
0025   __libcpp_mutex_t __m_ = _LIBCPP_MUTEX_INITIALIZER;
0026 
0027 public:
0028   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR mutex() = default;
0029 
0030   mutex(const mutex&)            = delete;
0031   mutex& operator=(const mutex&) = delete;
0032 
0033 #  if defined(_LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION)
0034   _LIBCPP_HIDE_FROM_ABI ~mutex() = default;
0035 #  else
0036   ~mutex() _NOEXCEPT;
0037 #  endif
0038 
0039   void lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability());
0040   bool try_lock() _NOEXCEPT _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_capability(true));
0041   void unlock() _NOEXCEPT _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability());
0042 
0043   typedef __libcpp_mutex_t* native_handle_type;
0044   _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() { return &__m_; }
0045 };
0046 
0047 static_assert(is_nothrow_default_constructible<mutex>::value, "the default constructor for std::mutex must be nothrow");
0048 
0049 _LIBCPP_END_NAMESPACE_STD
0050 
0051 #endif // _LIBCPP_HAS_NO_THREADS
0052 
0053 #endif // _LIBCPP___CXX03___MUTEX_MUTEX_H