diff options
| author | mikhnenko <[email protected]> | 2024-12-18 19:08:08 +0300 | 
|---|---|---|
| committer | mikhnenko <[email protected]> | 2024-12-18 19:29:26 +0300 | 
| commit | 7ed76959e6c06dbc4c249ce0f3b930463a6b65db (patch) | |
| tree | 0e9528cb7261812a5ae7ed177048721eaebf8ed0 /contrib/libs/cxxsupp/libcxx/src/mutex.cpp | |
| parent | 4c8e7f015711b5175d63e1a87cbd40c49ce7aa70 (diff) | |
libc++: Run clang-format from upstream and update to 9783f28cbb155e4a8d49c12e1c60ce14dcfaf0c7
commit_hash:ca4954fe054e5a7190ad11ab71bfc7ca0965bca2
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/src/mutex.cpp')
| -rw-r--r-- | contrib/libs/cxxsupp/libcxx/src/mutex.cpp | 209 | 
1 files changed, 81 insertions, 128 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/src/mutex.cpp b/contrib/libs/cxxsupp/libcxx/src/mutex.cpp index 11f7be38e26..13c63247f1a 100644 --- a/contrib/libs/cxxsupp/libcxx/src/mutex.cpp +++ b/contrib/libs/cxxsupp/libcxx/src/mutex.cpp @@ -13,7 +13,7 @@  #include <mutex>  #if !defined(_LIBCPP_ABI_MICROSOFT) -#include "include/atomic_support.h" +#  include "include/atomic_support.h"  #endif  #if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB) @@ -27,164 +27,117 @@ _LIBCPP_BEGIN_NAMESPACE_STD  // ~mutex is defined elsewhere -void -mutex::lock() -{ -    int ec = __libcpp_mutex_lock(&__m_); -    if (ec) -        __throw_system_error(ec, "mutex lock failed"); +void mutex::lock() { +  int ec = __libcpp_mutex_lock(&__m_); +  if (ec) +    __throw_system_error(ec, "mutex lock failed");  } -bool -mutex::try_lock() noexcept -{ -    return __libcpp_mutex_trylock(&__m_); -} +bool mutex::try_lock() noexcept { return __libcpp_mutex_trylock(&__m_); } -void -mutex::unlock() noexcept -{ -    int ec = __libcpp_mutex_unlock(&__m_); -    (void)ec; -    _LIBCPP_ASSERT_UNCATEGORIZED(ec == 0, "call to mutex::unlock failed"); +void mutex::unlock() noexcept { +  int ec = __libcpp_mutex_unlock(&__m_); +  (void)ec; +  _LIBCPP_ASSERT_UNCATEGORIZED(ec == 0, "call to mutex::unlock failed");  }  // recursive_mutex -recursive_mutex::recursive_mutex() -{ -    int ec = __libcpp_recursive_mutex_init(&__m_); -    if (ec) -        __throw_system_error(ec, "recursive_mutex constructor failed"); +recursive_mutex::recursive_mutex() { +  int ec = __libcpp_recursive_mutex_init(&__m_); +  if (ec) +    __throw_system_error(ec, "recursive_mutex constructor failed");  } -recursive_mutex::~recursive_mutex() -{ -    int e = __libcpp_recursive_mutex_destroy(&__m_); -    (void)e; -    _LIBCPP_ASSERT_UNCATEGORIZED(e == 0, "call to ~recursive_mutex() failed"); +recursive_mutex::~recursive_mutex() { +  int e = __libcpp_recursive_mutex_destroy(&__m_); +  (void)e; +  _LIBCPP_ASSERT_UNCATEGORIZED(e == 0, "call to ~recursive_mutex() failed");  } -void -recursive_mutex::lock() -{ -    int ec = __libcpp_recursive_mutex_lock(&__m_); -    if (ec) -        __throw_system_error(ec, "recursive_mutex lock failed"); +void recursive_mutex::lock() { +  int ec = __libcpp_recursive_mutex_lock(&__m_); +  if (ec) +    __throw_system_error(ec, "recursive_mutex lock failed");  } -void -recursive_mutex::unlock() noexcept -{ -    int e = __libcpp_recursive_mutex_unlock(&__m_); -    (void)e; -    _LIBCPP_ASSERT_UNCATEGORIZED(e == 0, "call to recursive_mutex::unlock() failed"); +void recursive_mutex::unlock() noexcept { +  int e = __libcpp_recursive_mutex_unlock(&__m_); +  (void)e; +  _LIBCPP_ASSERT_UNCATEGORIZED(e == 0, "call to recursive_mutex::unlock() failed");  } -bool -recursive_mutex::try_lock() noexcept -{ -    return __libcpp_recursive_mutex_trylock(&__m_); -} +bool recursive_mutex::try_lock() noexcept { return __libcpp_recursive_mutex_trylock(&__m_); }  // timed_mutex -timed_mutex::timed_mutex() -    : __locked_(false) -{ -} +timed_mutex::timed_mutex() : __locked_(false) {} -timed_mutex::~timed_mutex() -{ -    lock_guard<mutex> _(__m_); -} +timed_mutex::~timed_mutex() { lock_guard<mutex> _(__m_); } -void -timed_mutex::lock() -{ -    unique_lock<mutex> lk(__m_); -    while (__locked_) -        __cv_.wait(lk); -    __locked_ = true; +void timed_mutex::lock() { +  unique_lock<mutex> lk(__m_); +  while (__locked_) +    __cv_.wait(lk); +  __locked_ = true;  } -bool -timed_mutex::try_lock() noexcept -{ -    unique_lock<mutex> lk(__m_, try_to_lock); -    if (lk.owns_lock() && !__locked_) -    { -        __locked_ = true; -        return true; -    } -    return false; +bool timed_mutex::try_lock() noexcept { +  unique_lock<mutex> lk(__m_, try_to_lock); +  if (lk.owns_lock() && !__locked_) { +    __locked_ = true; +    return true; +  } +  return false;  } -void -timed_mutex::unlock() noexcept -{ -    lock_guard<mutex> _(__m_); -    __locked_ = false; -    __cv_.notify_one(); +void timed_mutex::unlock() noexcept { +  lock_guard<mutex> _(__m_); +  __locked_ = false; +  __cv_.notify_one();  }  // recursive_timed_mutex -recursive_timed_mutex::recursive_timed_mutex() -    : __count_(0), -      __id_{} -{ -} - -recursive_timed_mutex::~recursive_timed_mutex() -{ -    lock_guard<mutex> _(__m_); -} - -void -recursive_timed_mutex::lock() -{ -    __thread_id id = this_thread::get_id(); -    unique_lock<mutex> lk(__m_); -    if (id ==__id_) -    { -        if (__count_ == numeric_limits<size_t>::max()) -            __throw_system_error(EAGAIN, "recursive_timed_mutex lock limit reached"); -        ++__count_; -        return; -    } -    while (__count_ != 0) -        __cv_.wait(lk); -    __count_ = 1; +recursive_timed_mutex::recursive_timed_mutex() : __count_(0), __id_{} {} + +recursive_timed_mutex::~recursive_timed_mutex() { lock_guard<mutex> _(__m_); } + +void recursive_timed_mutex::lock() { +  __thread_id id = this_thread::get_id(); +  unique_lock<mutex> lk(__m_); +  if (id == __id_) { +    if (__count_ == numeric_limits<size_t>::max()) +      __throw_system_error(EAGAIN, "recursive_timed_mutex lock limit reached"); +    ++__count_; +    return; +  } +  while (__count_ != 0) +    __cv_.wait(lk); +  __count_ = 1; +  __id_    = id; +} + +bool recursive_timed_mutex::try_lock() noexcept { +  __thread_id id = this_thread::get_id(); +  unique_lock<mutex> lk(__m_, try_to_lock); +  if (lk.owns_lock() && (__count_ == 0 || id == __id_)) { +    if (__count_ == numeric_limits<size_t>::max()) +      return false; +    ++__count_;      __id_ = id; +    return true; +  } +  return false;  } -bool -recursive_timed_mutex::try_lock() noexcept -{ -    __thread_id id = this_thread::get_id(); -    unique_lock<mutex> lk(__m_, try_to_lock); -    if (lk.owns_lock() && (__count_ == 0 || id == __id_)) -    { -        if (__count_ == numeric_limits<size_t>::max()) -            return false; -        ++__count_; -        __id_ = id; -        return true; -    } -    return false; -} - -void -recursive_timed_mutex::unlock() noexcept -{ -    unique_lock<mutex> lk(__m_); -    if (--__count_ == 0) -    { -        __id_.__reset(); -        lk.unlock(); -        __cv_.notify_one(); -    } +void recursive_timed_mutex::unlock() noexcept { +  unique_lock<mutex> lk(__m_); +  if (--__count_ == 0) { +    __id_.__reset(); +    lk.unlock(); +    __cv_.notify_one(); +  }  }  _LIBCPP_END_NAMESPACE_STD  | 
