summaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/libcxx/include/__mutex
diff options
context:
space:
mode:
authorhiddenpath <[email protected]>2024-02-21 23:16:42 +0300
committerhiddenpath <[email protected]>2024-02-21 23:33:25 +0300
commit9052eb5cc304b8da8885fc4e3364ebddc16945f3 (patch)
tree3c252f6161dd0745c7732d74c9304c000645ab47 /contrib/libs/cxxsupp/libcxx/include/__mutex
parentf5eb715f103692e7c7536e13bef3f281fd78e5e7 (diff)
Update libcxx to llvmorg-17.0.6
Update libcxx to llvmorg-17.0.6 c871ef572c71b4fef22d4a9e65bcebc57e625aea
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/include/__mutex')
-rw-r--r--contrib/libs/cxxsupp/libcxx/include/__mutex/lock_guard.h53
-rw-r--r--contrib/libs/cxxsupp/libcxx/include/__mutex/mutex.h53
-rw-r--r--contrib/libs/cxxsupp/libcxx/include/__mutex/tag_types.h48
-rw-r--r--contrib/libs/cxxsupp/libcxx/include/__mutex/unique_lock.h173
4 files changed, 327 insertions, 0 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/include/__mutex/lock_guard.h b/contrib/libs/cxxsupp/libcxx/include/__mutex/lock_guard.h
new file mode 100644
index 00000000000..c075512fb97
--- /dev/null
+++ b/contrib/libs/cxxsupp/libcxx/include/__mutex/lock_guard.h
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___MUTEX_LOCK_GUARD_H
+#define _LIBCPP___MUTEX_LOCK_GUARD_H
+
+#include <__config>
+#include <__mutex/tag_types.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+#ifndef _LIBCPP_HAS_NO_THREADS
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Mutex>
+class _LIBCPP_TEMPLATE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(scoped_lockable) lock_guard {
+public:
+ typedef _Mutex mutex_type;
+
+private:
+ mutex_type& __m_;
+
+public:
+ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI explicit lock_guard(mutex_type& __m)
+ _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability(__m))
+ : __m_(__m) {
+ __m_.lock();
+ }
+
+ _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI lock_guard(mutex_type& __m, adopt_lock_t)
+ _LIBCPP_THREAD_SAFETY_ANNOTATION(requires_capability(__m))
+ : __m_(__m) {}
+ _LIBCPP_HIDE_FROM_ABI ~lock_guard() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()) { __m_.unlock(); }
+
+private:
+ lock_guard(lock_guard const&) = delete;
+ lock_guard& operator=(lock_guard const&) = delete;
+};
+_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(lock_guard);
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_HAS_NO_THREADS
+
+#endif // _LIBCPP___MUTEX_LOCK_GUARD_H
diff --git a/contrib/libs/cxxsupp/libcxx/include/__mutex/mutex.h b/contrib/libs/cxxsupp/libcxx/include/__mutex/mutex.h
new file mode 100644
index 00000000000..4423abf62b8
--- /dev/null
+++ b/contrib/libs/cxxsupp/libcxx/include/__mutex/mutex.h
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___MUTEX_MUTEX_H
+#define _LIBCPP___MUTEX_MUTEX_H
+
+#include <__config>
+#include <__threading_support>
+#include <__type_traits/is_nothrow_default_constructible.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+#ifndef _LIBCPP_HAS_NO_THREADS
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+class _LIBCPP_EXPORTED_FROM_ABI _LIBCPP_THREAD_SAFETY_ANNOTATION(capability("mutex")) mutex {
+ __libcpp_mutex_t __m_ = _LIBCPP_MUTEX_INITIALIZER;
+
+public:
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR mutex() = default;
+
+ mutex(const mutex&) = delete;
+ mutex& operator=(const mutex&) = delete;
+
+# if defined(_LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION)
+ _LIBCPP_HIDE_FROM_ABI ~mutex() = default;
+# else
+ ~mutex() _NOEXCEPT;
+# endif
+
+ void lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability());
+ bool try_lock() _NOEXCEPT _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_capability(true));
+ void unlock() _NOEXCEPT _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability());
+
+ typedef __libcpp_mutex_t* native_handle_type;
+ _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() { return &__m_; }
+};
+
+static_assert(is_nothrow_default_constructible<mutex>::value, "the default constructor for std::mutex must be nothrow");
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_HAS_NO_THREADS
+
+#endif // _LIBCPP___MUTEX_MUTEX_H
diff --git a/contrib/libs/cxxsupp/libcxx/include/__mutex/tag_types.h b/contrib/libs/cxxsupp/libcxx/include/__mutex/tag_types.h
new file mode 100644
index 00000000000..05ccb8b23a6
--- /dev/null
+++ b/contrib/libs/cxxsupp/libcxx/include/__mutex/tag_types.h
@@ -0,0 +1,48 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___MUTEX_TAG_TYPES_H
+#define _LIBCPP___MUTEX_TAG_TYPES_H
+
+#include <__config>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+#ifndef _LIBCPP_HAS_NO_THREADS
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+struct _LIBCPP_EXPORTED_FROM_ABI defer_lock_t {
+ explicit defer_lock_t() = default;
+};
+
+struct _LIBCPP_EXPORTED_FROM_ABI try_to_lock_t {
+ explicit try_to_lock_t() = default;
+};
+
+struct _LIBCPP_EXPORTED_FROM_ABI adopt_lock_t {
+ explicit adopt_lock_t() = default;
+};
+
+# if _LIBCPP_STD_VER >= 17
+inline constexpr defer_lock_t defer_lock = defer_lock_t();
+inline constexpr try_to_lock_t try_to_lock = try_to_lock_t();
+inline constexpr adopt_lock_t adopt_lock = adopt_lock_t();
+# elif !defined(_LIBCPP_CXX03_LANG)
+constexpr defer_lock_t defer_lock = defer_lock_t();
+constexpr try_to_lock_t try_to_lock = try_to_lock_t();
+constexpr adopt_lock_t adopt_lock = adopt_lock_t();
+# endif
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_HAS_NO_THREADS
+
+#endif // _LIBCPP___MUTEX_TAG_TYPES_H
diff --git a/contrib/libs/cxxsupp/libcxx/include/__mutex/unique_lock.h b/contrib/libs/cxxsupp/libcxx/include/__mutex/unique_lock.h
new file mode 100644
index 00000000000..c27ce4b24c1
--- /dev/null
+++ b/contrib/libs/cxxsupp/libcxx/include/__mutex/unique_lock.h
@@ -0,0 +1,173 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___MUTEX_UNIQUE_LOCK_H
+#define _LIBCPP___MUTEX_UNIQUE_LOCK_H
+
+#include <__chrono/duration.h>
+#include <__chrono/time_point.h>
+#include <__config>
+#include <__memory/addressof.h>
+#include <__mutex/tag_types.h>
+#include <__system_error/system_error.h>
+#include <__utility/swap.h>
+#include <cerrno>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+# pragma GCC system_header
+#endif
+
+#ifndef _LIBCPP_HAS_NO_THREADS
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+template <class _Mutex>
+class _LIBCPP_TEMPLATE_VIS unique_lock {
+public:
+ typedef _Mutex mutex_type;
+
+private:
+ mutex_type* __m_;
+ bool __owns_;
+
+public:
+ _LIBCPP_HIDE_FROM_ABI unique_lock() _NOEXCEPT : __m_(nullptr), __owns_(false) {}
+ _LIBCPP_HIDE_FROM_ABI explicit unique_lock(mutex_type& __m) : __m_(std::addressof(__m)), __owns_(true) {
+ __m_->lock();
+ }
+
+ _LIBCPP_HIDE_FROM_ABI unique_lock(mutex_type& __m, defer_lock_t) _NOEXCEPT
+ : __m_(std::addressof(__m)),
+ __owns_(false) {}
+
+ _LIBCPP_HIDE_FROM_ABI unique_lock(mutex_type& __m, try_to_lock_t)
+ : __m_(std::addressof(__m)), __owns_(__m.try_lock()) {}
+
+ _LIBCPP_HIDE_FROM_ABI unique_lock(mutex_type& __m, adopt_lock_t) : __m_(std::addressof(__m)), __owns_(true) {}
+
+ template <class _Clock, class _Duration>
+ _LIBCPP_HIDE_FROM_ABI unique_lock(mutex_type& __m, const chrono::time_point<_Clock, _Duration>& __t)
+ : __m_(std::addressof(__m)), __owns_(__m.try_lock_until(__t)) {}
+
+ template <class _Rep, class _Period>
+ _LIBCPP_HIDE_FROM_ABI unique_lock(mutex_type& __m, const chrono::duration<_Rep, _Period>& __d)
+ : __m_(std::addressof(__m)), __owns_(__m.try_lock_for(__d)) {}
+
+ _LIBCPP_HIDE_FROM_ABI ~unique_lock() {
+ if (__owns_)
+ __m_->unlock();
+ }
+
+ unique_lock(unique_lock const&) = delete;
+ unique_lock& operator=(unique_lock const&) = delete;
+
+ _LIBCPP_HIDE_FROM_ABI unique_lock(unique_lock&& __u) _NOEXCEPT : __m_(__u.__m_), __owns_(__u.__owns_) {
+ __u.__m_ = nullptr;
+ __u.__owns_ = false;
+ }
+
+ _LIBCPP_HIDE_FROM_ABI unique_lock& operator=(unique_lock&& __u) _NOEXCEPT {
+ if (__owns_)
+ __m_->unlock();
+
+ __m_ = __u.__m_;
+ __owns_ = __u.__owns_;
+ __u.__m_ = nullptr;
+ __u.__owns_ = false;
+ return *this;
+ }
+
+ void lock();
+ bool try_lock();
+
+ template <class _Rep, class _Period>
+ bool try_lock_for(const chrono::duration<_Rep, _Period>& __d);
+
+ template <class _Clock, class _Duration>
+ bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
+
+ void unlock();
+
+ _LIBCPP_HIDE_FROM_ABI void swap(unique_lock& __u) _NOEXCEPT {
+ std::swap(__m_, __u.__m_);
+ std::swap(__owns_, __u.__owns_);
+ }
+
+ _LIBCPP_HIDE_FROM_ABI mutex_type* release() _NOEXCEPT {
+ mutex_type* __m = __m_;
+ __m_ = nullptr;
+ __owns_ = false;
+ return __m;
+ }
+
+ _LIBCPP_HIDE_FROM_ABI bool owns_lock() const _NOEXCEPT { return __owns_; }
+ _LIBCPP_HIDE_FROM_ABI explicit operator bool() const _NOEXCEPT { return __owns_; }
+ _LIBCPP_HIDE_FROM_ABI mutex_type* mutex() const _NOEXCEPT { return __m_; }
+};
+_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(unique_lock);
+
+template <class _Mutex>
+void unique_lock<_Mutex>::lock() {
+ if (__m_ == nullptr)
+ __throw_system_error(EPERM, "unique_lock::lock: references null mutex");
+ if (__owns_)
+ __throw_system_error(EDEADLK, "unique_lock::lock: already locked");
+ __m_->lock();
+ __owns_ = true;
+}
+
+template <class _Mutex>
+bool unique_lock<_Mutex>::try_lock() {
+ if (__m_ == nullptr)
+ __throw_system_error(EPERM, "unique_lock::try_lock: references null mutex");
+ if (__owns_)
+ __throw_system_error(EDEADLK, "unique_lock::try_lock: already locked");
+ __owns_ = __m_->try_lock();
+ return __owns_;
+}
+
+template <class _Mutex>
+template <class _Rep, class _Period>
+bool unique_lock<_Mutex>::try_lock_for(const chrono::duration<_Rep, _Period>& __d) {
+ if (__m_ == nullptr)
+ __throw_system_error(EPERM, "unique_lock::try_lock_for: references null mutex");
+ if (__owns_)
+ __throw_system_error(EDEADLK, "unique_lock::try_lock_for: already locked");
+ __owns_ = __m_->try_lock_for(__d);
+ return __owns_;
+}
+
+template <class _Mutex>
+template <class _Clock, class _Duration>
+bool unique_lock<_Mutex>::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) {
+ if (__m_ == nullptr)
+ __throw_system_error(EPERM, "unique_lock::try_lock_until: references null mutex");
+ if (__owns_)
+ __throw_system_error(EDEADLK, "unique_lock::try_lock_until: already locked");
+ __owns_ = __m_->try_lock_until(__t);
+ return __owns_;
+}
+
+template <class _Mutex>
+void unique_lock<_Mutex>::unlock() {
+ if (!__owns_)
+ __throw_system_error(EPERM, "unique_lock::unlock: not locked");
+ __m_->unlock();
+ __owns_ = false;
+}
+
+template <class _Mutex>
+inline _LIBCPP_HIDE_FROM_ABI void swap(unique_lock<_Mutex>& __x, unique_lock<_Mutex>& __y) _NOEXCEPT {
+ __x.swap(__y);
+}
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP_HAS_NO_THREADS
+
+#endif // _LIBCPP___MUTEX_UNIQUE_LOCK_H