summaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/libcxx/include/mutex
diff options
context:
space:
mode:
authormikhnenko <[email protected]>2024-12-18 19:08:08 +0300
committermikhnenko <[email protected]>2024-12-18 19:29:26 +0300
commit7ed76959e6c06dbc4c249ce0f3b930463a6b65db (patch)
tree0e9528cb7261812a5ae7ed177048721eaebf8ed0 /contrib/libs/cxxsupp/libcxx/include/mutex
parent4c8e7f015711b5175d63e1a87cbd40c49ce7aa70 (diff)
libc++: Run clang-format from upstream and update to 9783f28cbb155e4a8d49c12e1c60ce14dcfaf0c7
commit_hash:ca4954fe054e5a7190ad11ab71bfc7ca0965bca2
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/include/mutex')
-rw-r--r--contrib/libs/cxxsupp/libcxx/include/mutex467
1 files changed, 210 insertions, 257 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/include/mutex b/contrib/libs/cxxsupp/libcxx/include/mutex
index a15e61de04c..a16ef589c69 100644
--- a/contrib/libs/cxxsupp/libcxx/include/mutex
+++ b/contrib/libs/cxxsupp/libcxx/include/mutex
@@ -203,7 +203,7 @@ template<class Callable, class ...Args>
#include <cstddef>
#include <limits>
#ifndef _LIBCPP_CXX03_LANG
-# include <tuple>
+# include <tuple>
#endif
#include <version>
@@ -214,347 +214,300 @@ template<class Callable, class ...Args>
_LIBCPP_PUSH_MACROS
#include <__undef_macros>
-
_LIBCPP_BEGIN_NAMESPACE_STD
#ifndef _LIBCPP_HAS_NO_THREADS
-class _LIBCPP_EXPORTED_FROM_ABI recursive_mutex
-{
- __libcpp_recursive_mutex_t __m_;
+class _LIBCPP_EXPORTED_FROM_ABI recursive_mutex {
+ __libcpp_recursive_mutex_t __m_;
public:
- recursive_mutex();
- ~recursive_mutex();
+ recursive_mutex();
+ ~recursive_mutex();
- recursive_mutex(const recursive_mutex&) = delete;
- recursive_mutex& operator=(const recursive_mutex&) = delete;
+ recursive_mutex(const recursive_mutex&) = delete;
+ recursive_mutex& operator=(const recursive_mutex&) = delete;
- void lock();
- bool try_lock() _NOEXCEPT;
- void unlock() _NOEXCEPT;
+ void lock();
+ bool try_lock() _NOEXCEPT;
+ void unlock() _NOEXCEPT;
- typedef __libcpp_recursive_mutex_t* native_handle_type;
+ typedef __libcpp_recursive_mutex_t* native_handle_type;
- _LIBCPP_HIDE_FROM_ABI
- native_handle_type native_handle() {return &__m_;}
+ _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() { return &__m_; }
};
-class _LIBCPP_EXPORTED_FROM_ABI timed_mutex
-{
- mutex __m_;
- condition_variable __cv_;
- bool __locked_;
+class _LIBCPP_EXPORTED_FROM_ABI timed_mutex {
+ mutex __m_;
+ condition_variable __cv_;
+ bool __locked_;
+
public:
- timed_mutex();
- ~timed_mutex();
+ timed_mutex();
+ ~timed_mutex();
- timed_mutex(const timed_mutex&) = delete;
- timed_mutex& operator=(const timed_mutex&) = delete;
+ timed_mutex(const timed_mutex&) = delete;
+ timed_mutex& operator=(const timed_mutex&) = delete;
public:
- void lock();
- bool try_lock() _NOEXCEPT;
- template <class _Rep, class _Period>
- _LIBCPP_HIDE_FROM_ABI
- bool try_lock_for(const chrono::duration<_Rep, _Period>& __d)
- {return try_lock_until(chrono::steady_clock::now() + __d);}
- template <class _Clock, class _Duration>
- _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
- bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
- void unlock() _NOEXCEPT;
+ void lock();
+ bool try_lock() _NOEXCEPT;
+ template <class _Rep, class _Period>
+ _LIBCPP_HIDE_FROM_ABI bool try_lock_for(const chrono::duration<_Rep, _Period>& __d) {
+ return try_lock_until(chrono::steady_clock::now() + __d);
+ }
+ template <class _Clock, class _Duration>
+ _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool
+ try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
+ void unlock() _NOEXCEPT;
};
template <class _Clock, class _Duration>
-bool
-timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t)
-{
- using namespace chrono;
- unique_lock<mutex> __lk(__m_);
- bool __no_timeout = _Clock::now() < __t;
- while (__no_timeout && __locked_)
- __no_timeout = __cv_.wait_until(__lk, __t) == cv_status::no_timeout;
- if (!__locked_)
- {
- __locked_ = true;
- return true;
- }
- return false;
+bool timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) {
+ using namespace chrono;
+ unique_lock<mutex> __lk(__m_);
+ bool __no_timeout = _Clock::now() < __t;
+ while (__no_timeout && __locked_)
+ __no_timeout = __cv_.wait_until(__lk, __t) == cv_status::no_timeout;
+ if (!__locked_) {
+ __locked_ = true;
+ return true;
+ }
+ return false;
}
-class _LIBCPP_EXPORTED_FROM_ABI recursive_timed_mutex
-{
- mutex __m_;
- condition_variable __cv_;
- size_t __count_;
- __thread_id __id_;
-public:
- recursive_timed_mutex();
- ~recursive_timed_mutex();
-
- recursive_timed_mutex(const recursive_timed_mutex&) = delete;
- recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete;
+class _LIBCPP_EXPORTED_FROM_ABI recursive_timed_mutex {
+ mutex __m_;
+ condition_variable __cv_;
+ size_t __count_;
+ __thread_id __id_;
- void lock();
- bool try_lock() _NOEXCEPT;
- template <class _Rep, class _Period>
- _LIBCPP_HIDE_FROM_ABI
- bool try_lock_for(const chrono::duration<_Rep, _Period>& __d)
- {return try_lock_until(chrono::steady_clock::now() + __d);}
- template <class _Clock, class _Duration>
- _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
- bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
- void unlock() _NOEXCEPT;
+public:
+ recursive_timed_mutex();
+ ~recursive_timed_mutex();
+
+ recursive_timed_mutex(const recursive_timed_mutex&) = delete;
+ recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete;
+
+ void lock();
+ bool try_lock() _NOEXCEPT;
+ template <class _Rep, class _Period>
+ _LIBCPP_HIDE_FROM_ABI bool try_lock_for(const chrono::duration<_Rep, _Period>& __d) {
+ return try_lock_until(chrono::steady_clock::now() + __d);
+ }
+ template <class _Clock, class _Duration>
+ _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS bool
+ try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
+ void unlock() _NOEXCEPT;
};
template <class _Clock, class _Duration>
-bool
-recursive_timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t)
-{
- using namespace chrono;
- __thread_id __id = this_thread::get_id();
- unique_lock<mutex> __lk(__m_);
- if (__id == __id_)
- {
- if (__count_ == numeric_limits<size_t>::max())
- return false;
- ++__count_;
- return true;
- }
- bool __no_timeout = _Clock::now() < __t;
- while (__no_timeout && __count_ != 0)
- __no_timeout = __cv_.wait_until(__lk, __t) == cv_status::no_timeout;
- if (__count_ == 0)
- {
- __count_ = 1;
- __id_ = __id;
- return true;
- }
- return false;
+bool recursive_timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t) {
+ using namespace chrono;
+ __thread_id __id = this_thread::get_id();
+ unique_lock<mutex> __lk(__m_);
+ if (__id == __id_) {
+ if (__count_ == numeric_limits<size_t>::max())
+ return false;
+ ++__count_;
+ return true;
+ }
+ bool __no_timeout = _Clock::now() < __t;
+ while (__no_timeout && __count_ != 0)
+ __no_timeout = __cv_.wait_until(__lk, __t) == cv_status::no_timeout;
+ if (__count_ == 0) {
+ __count_ = 1;
+ __id_ = __id;
+ return true;
+ }
+ return false;
}
template <class _L0, class _L1>
-_LIBCPP_HIDE_FROM_ABI int
-try_lock(_L0& __l0, _L1& __l1)
-{
- unique_lock<_L0> __u0(__l0, try_to_lock_t());
- if (__u0.owns_lock())
- {
- if (__l1.try_lock())
- {
- __u0.release();
- return -1;
- }
- else
- return 1;
- }
- return 0;
+_LIBCPP_HIDE_FROM_ABI int try_lock(_L0& __l0, _L1& __l1) {
+ unique_lock<_L0> __u0(__l0, try_to_lock_t());
+ if (__u0.owns_lock()) {
+ if (__l1.try_lock()) {
+ __u0.release();
+ return -1;
+ } else
+ return 1;
+ }
+ return 0;
}
-#ifndef _LIBCPP_CXX03_LANG
+# ifndef _LIBCPP_CXX03_LANG
template <class _L0, class _L1, class _L2, class... _L3>
-_LIBCPP_HIDE_FROM_ABI int
-try_lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3&... __l3)
-{
- int __r = 0;
- unique_lock<_L0> __u0(__l0, try_to_lock);
- if (__u0.owns_lock())
- {
- __r = std::try_lock(__l1, __l2, __l3...);
- if (__r == -1)
- __u0.release();
- else
- ++__r;
- }
- return __r;
+_LIBCPP_HIDE_FROM_ABI int try_lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3&... __l3) {
+ int __r = 0;
+ unique_lock<_L0> __u0(__l0, try_to_lock);
+ if (__u0.owns_lock()) {
+ __r = std::try_lock(__l1, __l2, __l3...);
+ if (__r == -1)
+ __u0.release();
+ else
+ ++__r;
+ }
+ return __r;
}
-#endif // _LIBCPP_CXX03_LANG
+# endif // _LIBCPP_CXX03_LANG
template <class _L0, class _L1>
-_LIBCPP_HIDE_FROM_ABI void
-lock(_L0& __l0, _L1& __l1)
-{
- while (true)
+_LIBCPP_HIDE_FROM_ABI void lock(_L0& __l0, _L1& __l1) {
+ while (true) {
{
- {
- unique_lock<_L0> __u0(__l0);
- if (__l1.try_lock())
- {
- __u0.release();
- break;
- }
- }
- __libcpp_thread_yield();
- {
- unique_lock<_L1> __u1(__l1);
- if (__l0.try_lock())
- {
- __u1.release();
- break;
- }
- }
- __libcpp_thread_yield();
+ unique_lock<_L0> __u0(__l0);
+ if (__l1.try_lock()) {
+ __u0.release();
+ break;
+ }
}
+ __libcpp_thread_yield();
+ {
+ unique_lock<_L1> __u1(__l1);
+ if (__l0.try_lock()) {
+ __u1.release();
+ break;
+ }
+ }
+ __libcpp_thread_yield();
+ }
}
-#ifndef _LIBCPP_CXX03_LANG
+# ifndef _LIBCPP_CXX03_LANG
-template <class _L0, class _L1, class _L2, class ..._L3>
-void
-__lock_first(int __i, _L0& __l0, _L1& __l1, _L2& __l2, _L3& ...__l3)
-{
- while (true)
- {
- switch (__i)
- {
- case 0:
- {
- unique_lock<_L0> __u0(__l0);
- __i = std::try_lock(__l1, __l2, __l3...);
- if (__i == -1)
- {
- __u0.release();
- return;
- }
- }
- ++__i;
- __libcpp_thread_yield();
- break;
- case 1:
- {
- unique_lock<_L1> __u1(__l1);
- __i = std::try_lock(__l2, __l3..., __l0);
- if (__i == -1)
- {
- __u1.release();
- return;
- }
- }
- if (__i == sizeof...(_L3) + 1)
- __i = 0;
- else
- __i += 2;
- __libcpp_thread_yield();
- break;
- default:
- std::__lock_first(__i - 2, __l2, __l3..., __l0, __l1);
- return;
- }
+template <class _L0, class _L1, class _L2, class... _L3>
+void __lock_first(int __i, _L0& __l0, _L1& __l1, _L2& __l2, _L3&... __l3) {
+ while (true) {
+ switch (__i) {
+ case 0: {
+ unique_lock<_L0> __u0(__l0);
+ __i = std::try_lock(__l1, __l2, __l3...);
+ if (__i == -1) {
+ __u0.release();
+ return;
+ }
+ }
+ ++__i;
+ __libcpp_thread_yield();
+ break;
+ case 1: {
+ unique_lock<_L1> __u1(__l1);
+ __i = std::try_lock(__l2, __l3..., __l0);
+ if (__i == -1) {
+ __u1.release();
+ return;
+ }
+ }
+ if (__i == sizeof...(_L3) + 1)
+ __i = 0;
+ else
+ __i += 2;
+ __libcpp_thread_yield();
+ break;
+ default:
+ std::__lock_first(__i - 2, __l2, __l3..., __l0, __l1);
+ return;
}
+ }
}
-template <class _L0, class _L1, class _L2, class ..._L3>
-inline _LIBCPP_HIDE_FROM_ABI
-void
-lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3& ...__l3)
-{
- std::__lock_first(0, __l0, __l1, __l2, __l3...);
+template <class _L0, class _L1, class _L2, class... _L3>
+inline _LIBCPP_HIDE_FROM_ABI void lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3&... __l3) {
+ std::__lock_first(0, __l0, __l1, __l2, __l3...);
}
template <class _L0>
-inline _LIBCPP_HIDE_FROM_ABI
-void __unlock(_L0& __l0) {
- __l0.unlock();
+inline _LIBCPP_HIDE_FROM_ABI void __unlock(_L0& __l0) {
+ __l0.unlock();
}
template <class _L0, class _L1>
-inline _LIBCPP_HIDE_FROM_ABI
-void __unlock(_L0& __l0, _L1& __l1) {
- __l0.unlock();
- __l1.unlock();
+inline _LIBCPP_HIDE_FROM_ABI void __unlock(_L0& __l0, _L1& __l1) {
+ __l0.unlock();
+ __l1.unlock();
}
-template <class _L0, class _L1, class _L2, class ..._L3>
-inline _LIBCPP_HIDE_FROM_ABI
-void __unlock(_L0& __l0, _L1& __l1, _L2& __l2, _L3&... __l3) {
- __l0.unlock();
- __l1.unlock();
- std::__unlock(__l2, __l3...);
+template <class _L0, class _L1, class _L2, class... _L3>
+inline _LIBCPP_HIDE_FROM_ABI void __unlock(_L0& __l0, _L1& __l1, _L2& __l2, _L3&... __l3) {
+ __l0.unlock();
+ __l1.unlock();
+ std::__unlock(__l2, __l3...);
}
-#endif // _LIBCPP_CXX03_LANG
+# endif // _LIBCPP_CXX03_LANG
-#if _LIBCPP_STD_VER >= 17
-template <class ..._Mutexes>
+# if _LIBCPP_STD_VER >= 17
+template <class... _Mutexes>
class _LIBCPP_TEMPLATE_VIS scoped_lock;
template <>
class _LIBCPP_TEMPLATE_VIS scoped_lock<> {
public:
- explicit scoped_lock() {}
- ~scoped_lock() = default;
+ explicit scoped_lock() {}
+ ~scoped_lock() = default;
- _LIBCPP_HIDE_FROM_ABI
- explicit scoped_lock(adopt_lock_t) {}
+ _LIBCPP_HIDE_FROM_ABI explicit scoped_lock(adopt_lock_t) {}
- scoped_lock(scoped_lock const&) = delete;
- scoped_lock& operator=(scoped_lock const&) = delete;
+ scoped_lock(scoped_lock const&) = delete;
+ scoped_lock& operator=(scoped_lock const&) = delete;
};
template <class _Mutex>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(scoped_lockable) scoped_lock<_Mutex> {
public:
- typedef _Mutex mutex_type;
+ typedef _Mutex mutex_type;
+
private:
- mutex_type& __m_;
+ mutex_type& __m_;
+
public:
- explicit scoped_lock(mutex_type & __m) _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability(__m))
- : __m_(__m) {__m_.lock();}
+ explicit scoped_lock(mutex_type& __m) _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability(__m)) : __m_(__m) {
+ __m_.lock();
+ }
- ~scoped_lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()) {__m_.unlock();}
+ ~scoped_lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()) { __m_.unlock(); }
- _LIBCPP_HIDE_FROM_ABI
- explicit scoped_lock(adopt_lock_t, mutex_type& __m) _LIBCPP_THREAD_SAFETY_ANNOTATION(requires_capability(__m))
- : __m_(__m) {}
+ _LIBCPP_HIDE_FROM_ABI explicit scoped_lock(adopt_lock_t, mutex_type& __m)
+ _LIBCPP_THREAD_SAFETY_ANNOTATION(requires_capability(__m))
+ : __m_(__m) {}
- scoped_lock(scoped_lock const&) = delete;
- scoped_lock& operator=(scoped_lock const&) = delete;
+ scoped_lock(scoped_lock const&) = delete;
+ scoped_lock& operator=(scoped_lock const&) = delete;
};
-template <class ..._MArgs>
-class _LIBCPP_TEMPLATE_VIS scoped_lock
-{
- static_assert(sizeof...(_MArgs) > 1, "At least 2 lock types required");
- typedef tuple<_MArgs&...> _MutexTuple;
+template <class... _MArgs>
+class _LIBCPP_TEMPLATE_VIS scoped_lock {
+ static_assert(sizeof...(_MArgs) > 1, "At least 2 lock types required");
+ typedef tuple<_MArgs&...> _MutexTuple;
public:
- _LIBCPP_HIDE_FROM_ABI
- explicit scoped_lock(_MArgs&... __margs)
- : __t_(__margs...)
- {
- std::lock(__margs...);
- }
+ _LIBCPP_HIDE_FROM_ABI explicit scoped_lock(_MArgs&... __margs) : __t_(__margs...) { std::lock(__margs...); }
- _LIBCPP_HIDE_FROM_ABI
- scoped_lock(adopt_lock_t, _MArgs&... __margs)
- : __t_(__margs...)
- {
- }
+ _LIBCPP_HIDE_FROM_ABI scoped_lock(adopt_lock_t, _MArgs&... __margs) : __t_(__margs...) {}
- _LIBCPP_HIDE_FROM_ABI
- ~scoped_lock() {
- typedef typename __make_tuple_indices<sizeof...(_MArgs)>::type _Indices;
- __unlock_unpack(_Indices{}, __t_);
- }
+ _LIBCPP_HIDE_FROM_ABI ~scoped_lock() {
+ typedef typename __make_tuple_indices<sizeof...(_MArgs)>::type _Indices;
+ __unlock_unpack(_Indices{}, __t_);
+ }
- scoped_lock(scoped_lock const&) = delete;
- scoped_lock& operator=(scoped_lock const&) = delete;
+ scoped_lock(scoped_lock const&) = delete;
+ scoped_lock& operator=(scoped_lock const&) = delete;
private:
- template <size_t ..._Indx>
- _LIBCPP_HIDE_FROM_ABI
- static void __unlock_unpack(__tuple_indices<_Indx...>, _MutexTuple& __mt) {
- std::__unlock(std::get<_Indx>(__mt)...);
- }
+ template <size_t... _Indx>
+ _LIBCPP_HIDE_FROM_ABI static void __unlock_unpack(__tuple_indices<_Indx...>, _MutexTuple& __mt) {
+ std::__unlock(std::get<_Indx>(__mt)...);
+ }
- _MutexTuple __t_;
+ _MutexTuple __t_;
};
_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(scoped_lock);
-#endif // _LIBCPP_STD_VER >= 17
-#endif // !_LIBCPP_HAS_NO_THREADS
+# endif // _LIBCPP_STD_VER >= 17
+#endif // !_LIBCPP_HAS_NO_THREADS
_LIBCPP_END_NAMESPACE_STD