aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/libcxx/src/shared_mutex.cpp
diff options
context:
space:
mode:
authorhiddenpath <hiddenpath@yandex-team.com>2024-02-21 23:16:42 +0300
committerhiddenpath <hiddenpath@yandex-team.com>2024-02-21 23:33:25 +0300
commit9052eb5cc304b8da8885fc4e3364ebddc16945f3 (patch)
tree3c252f6161dd0745c7732d74c9304c000645ab47 /contrib/libs/cxxsupp/libcxx/src/shared_mutex.cpp
parentf5eb715f103692e7c7536e13bef3f281fd78e5e7 (diff)
downloadydb-9052eb5cc304b8da8885fc4e3364ebddc16945f3.tar.gz
Update libcxx to llvmorg-17.0.6
Update libcxx to llvmorg-17.0.6 c871ef572c71b4fef22d4a9e65bcebc57e625aea
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/src/shared_mutex.cpp')
-rw-r--r--contrib/libs/cxxsupp/libcxx/src/shared_mutex.cpp128
1 files changed, 54 insertions, 74 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/src/shared_mutex.cpp b/contrib/libs/cxxsupp/libcxx/src/shared_mutex.cpp
index 73d4dc1c1c..49a51e0271 100644
--- a/contrib/libs/cxxsupp/libcxx/src/shared_mutex.cpp
+++ b/contrib/libs/cxxsupp/libcxx/src/shared_mutex.cpp
@@ -10,106 +10,86 @@
#ifndef _LIBCPP_HAS_NO_THREADS
-#include <shared_mutex>
-#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
-# pragma comment(lib, "pthread")
-#endif
+# include <mutex>
+# include <shared_mutex>
+# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
+# pragma comment(lib, "pthread")
+# endif
_LIBCPP_BEGIN_NAMESPACE_STD
// Shared Mutex Base
-__shared_mutex_base::__shared_mutex_base()
- : __state_(0)
-{
-}
+__shared_mutex_base::__shared_mutex_base() : __state_(0) {}
// Exclusive ownership
-void
-__shared_mutex_base::lock()
-{
- unique_lock<mutex> lk(__mut_);
- while (__state_ & __write_entered_)
- __gate1_.wait(lk);
- __state_ |= __write_entered_;
- while (__state_ & __n_readers_)
- __gate2_.wait(lk);
+void __shared_mutex_base::lock() {
+ unique_lock<mutex> lk(__mut_);
+ while (__state_ & __write_entered_)
+ __gate1_.wait(lk);
+ __state_ |= __write_entered_;
+ while (__state_ & __n_readers_)
+ __gate2_.wait(lk);
}
-bool
-__shared_mutex_base::try_lock()
-{
- unique_lock<mutex> lk(__mut_);
- if (__state_ == 0)
- {
- __state_ = __write_entered_;
- return true;
- }
- return false;
+bool __shared_mutex_base::try_lock() {
+ unique_lock<mutex> lk(__mut_);
+ if (__state_ == 0) {
+ __state_ = __write_entered_;
+ return true;
+ }
+ return false;
}
-void
-__shared_mutex_base::unlock()
-{
- lock_guard<mutex> _(__mut_);
- __state_ = 0;
- __gate1_.notify_all();
+void __shared_mutex_base::unlock() {
+ lock_guard<mutex> _(__mut_);
+ __state_ = 0;
+ __gate1_.notify_all();
}
// Shared ownership
-void
-__shared_mutex_base::lock_shared()
-{
- unique_lock<mutex> lk(__mut_);
- while ((__state_ & __write_entered_) || (__state_ & __n_readers_) == __n_readers_)
- __gate1_.wait(lk);
- unsigned num_readers = (__state_ & __n_readers_) + 1;
- __state_ &= ~__n_readers_;
- __state_ |= num_readers;
-}
-
-bool
-__shared_mutex_base::try_lock_shared()
-{
- unique_lock<mutex> lk(__mut_);
- unsigned num_readers = __state_ & __n_readers_;
- if (!(__state_ & __write_entered_) && num_readers != __n_readers_)
- {
- ++num_readers;
- __state_ &= ~__n_readers_;
- __state_ |= num_readers;
- return true;
- }
- return false;
+void __shared_mutex_base::lock_shared() {
+ unique_lock<mutex> lk(__mut_);
+ while ((__state_ & __write_entered_) || (__state_ & __n_readers_) == __n_readers_)
+ __gate1_.wait(lk);
+ unsigned num_readers = (__state_ & __n_readers_) + 1;
+ __state_ &= ~__n_readers_;
+ __state_ |= num_readers;
}
-void
-__shared_mutex_base::unlock_shared()
-{
- lock_guard<mutex> _(__mut_);
- unsigned num_readers = (__state_ & __n_readers_) - 1;
+bool __shared_mutex_base::try_lock_shared() {
+ unique_lock<mutex> lk(__mut_);
+ unsigned num_readers = __state_ & __n_readers_;
+ if (!(__state_ & __write_entered_) && num_readers != __n_readers_) {
+ ++num_readers;
__state_ &= ~__n_readers_;
__state_ |= num_readers;
- if (__state_ & __write_entered_)
- {
- if (num_readers == 0)
- __gate2_.notify_one();
- }
- else
- {
- if (num_readers == __n_readers_ - 1)
- __gate1_.notify_one();
- }
+ return true;
+ }
+ return false;
}
+void __shared_mutex_base::unlock_shared() {
+ lock_guard<mutex> _(__mut_);
+ unsigned num_readers = (__state_ & __n_readers_) - 1;
+ __state_ &= ~__n_readers_;
+ __state_ |= num_readers;
+ if (__state_ & __write_entered_) {
+ if (num_readers == 0)
+ __gate2_.notify_one();
+ } else {
+ if (num_readers == __n_readers_ - 1)
+ __gate1_.notify_one();
+ }
+}
// Shared Timed Mutex
// These routines are here for ABI stability
shared_timed_mutex::shared_timed_mutex() : __base_() {}
-void shared_timed_mutex::lock() { return __base_.lock(); }
+void shared_timed_mutex::lock() { return __base_.lock(); }
bool shared_timed_mutex::try_lock() { return __base_.try_lock(); }
-void shared_timed_mutex::unlock() { return __base_.unlock(); }
+void shared_timed_mutex::unlock() { return __base_.unlock(); }
void shared_timed_mutex::lock_shared() { return __base_.lock_shared(); }
bool shared_timed_mutex::try_lock_shared() { return __base_.try_lock_shared(); }
void shared_timed_mutex::unlock_shared() { return __base_.unlock_shared(); }