mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42:29 +00:00
Upgrade to 2022-era LLVM LIBCXX
This commit is contained in:
parent
2f4ca71f26
commit
8e68384e15
2078 changed files with 165657 additions and 65010 deletions
110
third_party/libcxx/shared_mutex
vendored
110
third_party/libcxx/shared_mutex
vendored
|
@ -1,5 +1,5 @@
|
|||
// -*- C++ -*-
|
||||
//===------------------------ shared_mutex --------------------------------===//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
|
@ -122,24 +122,35 @@ template <class Mutex>
|
|||
|
||||
*/
|
||||
|
||||
#include "third_party/libcxx/__config"
|
||||
#include "third_party/libcxx/version"
|
||||
#include <__assert> // all public C++ headers provide the assertion handler
|
||||
#include <__availability>
|
||||
#include <__chrono/duration.h>
|
||||
#include <__chrono/steady_clock.h>
|
||||
#include <__chrono/time_point.h>
|
||||
#include <__condition_variable/condition_variable.h>
|
||||
#include <__config>
|
||||
#include <__memory/addressof.h>
|
||||
#include <__mutex/mutex.h>
|
||||
#include <__mutex/tag_types.h>
|
||||
#include <__mutex/unique_lock.h>
|
||||
#include <__system_error/system_error.h>
|
||||
#include <__utility/swap.h>
|
||||
#include <cerrno>
|
||||
#include <version>
|
||||
|
||||
_LIBCPP_PUSH_MACROS
|
||||
#include "third_party/libcxx/__undef_macros"
|
||||
#include <__undef_macros>
|
||||
|
||||
|
||||
#if _LIBCPP_STD_VER > 11 || defined(_LIBCPP_BUILDING_LIBRARY)
|
||||
|
||||
#include "third_party/libcxx/__mutex_base"
|
||||
#if _LIBCPP_STD_VER >= 14 || defined(_LIBCPP_BUILDING_LIBRARY)
|
||||
|
||||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
||||
#pragma GCC system_header
|
||||
# pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#ifdef _LIBCPP_HAS_NO_THREADS
|
||||
#error <shared_mutex> is not supported on this single threaded system
|
||||
#else // !_LIBCPP_HAS_NO_THREADS
|
||||
# error "<shared_mutex> is not supported since libc++ has been configured without support for threads."
|
||||
#endif
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
|
@ -175,26 +186,26 @@ __shared_mutex_base
|
|||
};
|
||||
|
||||
|
||||
#if _LIBCPP_STD_VER > 14
|
||||
#if _LIBCPP_STD_VER >= 17
|
||||
class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_SHARED_MUTEX shared_mutex
|
||||
{
|
||||
__shared_mutex_base __base;
|
||||
__shared_mutex_base __base_;
|
||||
public:
|
||||
_LIBCPP_INLINE_VISIBILITY shared_mutex() : __base() {}
|
||||
_LIBCPP_INLINE_VISIBILITY shared_mutex() : __base_() {}
|
||||
_LIBCPP_INLINE_VISIBILITY ~shared_mutex() = default;
|
||||
|
||||
shared_mutex(const shared_mutex&) = delete;
|
||||
shared_mutex& operator=(const shared_mutex&) = delete;
|
||||
|
||||
// Exclusive ownership
|
||||
_LIBCPP_INLINE_VISIBILITY void lock() { return __base.lock(); }
|
||||
_LIBCPP_INLINE_VISIBILITY bool try_lock() { return __base.try_lock(); }
|
||||
_LIBCPP_INLINE_VISIBILITY void unlock() { return __base.unlock(); }
|
||||
_LIBCPP_INLINE_VISIBILITY void lock() { return __base_.lock(); }
|
||||
_LIBCPP_INLINE_VISIBILITY bool try_lock() { return __base_.try_lock(); }
|
||||
_LIBCPP_INLINE_VISIBILITY void unlock() { return __base_.unlock(); }
|
||||
|
||||
// Shared ownership
|
||||
_LIBCPP_INLINE_VISIBILITY void lock_shared() { return __base.lock_shared(); }
|
||||
_LIBCPP_INLINE_VISIBILITY bool try_lock_shared() { return __base.try_lock_shared(); }
|
||||
_LIBCPP_INLINE_VISIBILITY void unlock_shared() { return __base.unlock_shared(); }
|
||||
_LIBCPP_INLINE_VISIBILITY void lock_shared() { return __base_.lock_shared(); }
|
||||
_LIBCPP_INLINE_VISIBILITY bool try_lock_shared() { return __base_.try_lock_shared(); }
|
||||
_LIBCPP_INLINE_VISIBILITY void unlock_shared() { return __base_.unlock_shared(); }
|
||||
|
||||
// typedef __shared_mutex_base::native_handle_type native_handle_type;
|
||||
// _LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() { return __base::unlock_shared(); }
|
||||
|
@ -204,7 +215,7 @@ public:
|
|||
|
||||
class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_SHARED_MUTEX shared_timed_mutex
|
||||
{
|
||||
__shared_mutex_base __base;
|
||||
__shared_mutex_base __base_;
|
||||
public:
|
||||
shared_timed_mutex();
|
||||
_LIBCPP_INLINE_VISIBILITY ~shared_timed_mutex() = default;
|
||||
|
@ -250,30 +261,30 @@ bool
|
|||
shared_timed_mutex::try_lock_until(
|
||||
const chrono::time_point<_Clock, _Duration>& __abs_time)
|
||||
{
|
||||
unique_lock<mutex> __lk(__base.__mut_);
|
||||
if (__base.__state_ & __base.__write_entered_)
|
||||
unique_lock<mutex> __lk(__base_.__mut_);
|
||||
if (__base_.__state_ & __base_.__write_entered_)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
cv_status __status = __base.__gate1_.wait_until(__lk, __abs_time);
|
||||
if ((__base.__state_ & __base.__write_entered_) == 0)
|
||||
cv_status __status = __base_.__gate1_.wait_until(__lk, __abs_time);
|
||||
if ((__base_.__state_ & __base_.__write_entered_) == 0)
|
||||
break;
|
||||
if (__status == cv_status::timeout)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
__base.__state_ |= __base.__write_entered_;
|
||||
if (__base.__state_ & __base.__n_readers_)
|
||||
__base_.__state_ |= __base_.__write_entered_;
|
||||
if (__base_.__state_ & __base_.__n_readers_)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
cv_status __status = __base.__gate2_.wait_until(__lk, __abs_time);
|
||||
if ((__base.__state_ & __base.__n_readers_) == 0)
|
||||
cv_status __status = __base_.__gate2_.wait_until(__lk, __abs_time);
|
||||
if ((__base_.__state_ & __base_.__n_readers_) == 0)
|
||||
break;
|
||||
if (__status == cv_status::timeout)
|
||||
{
|
||||
__base.__state_ &= ~__base.__write_entered_;
|
||||
__base.__gate1_.notify_all();
|
||||
__base_.__state_ &= ~__base_.__write_entered_;
|
||||
__base_.__gate1_.notify_all();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -286,22 +297,22 @@ bool
|
|||
shared_timed_mutex::try_lock_shared_until(
|
||||
const chrono::time_point<_Clock, _Duration>& __abs_time)
|
||||
{
|
||||
unique_lock<mutex> __lk(__base.__mut_);
|
||||
if ((__base.__state_ & __base.__write_entered_) || (__base.__state_ & __base.__n_readers_) == __base.__n_readers_)
|
||||
unique_lock<mutex> __lk(__base_.__mut_);
|
||||
if ((__base_.__state_ & __base_.__write_entered_) || (__base_.__state_ & __base_.__n_readers_) == __base_.__n_readers_)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
cv_status status = __base.__gate1_.wait_until(__lk, __abs_time);
|
||||
if ((__base.__state_ & __base.__write_entered_) == 0 &&
|
||||
(__base.__state_ & __base.__n_readers_) < __base.__n_readers_)
|
||||
cv_status __status = __base_.__gate1_.wait_until(__lk, __abs_time);
|
||||
if ((__base_.__state_ & __base_.__write_entered_) == 0 &&
|
||||
(__base_.__state_ & __base_.__n_readers_) < __base_.__n_readers_)
|
||||
break;
|
||||
if (status == cv_status::timeout)
|
||||
if (__status == cv_status::timeout)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
unsigned __num_readers = (__base.__state_ & __base.__n_readers_) + 1;
|
||||
__base.__state_ &= ~__base.__n_readers_;
|
||||
__base.__state_ |= __num_readers;
|
||||
unsigned __num_readers = (__base_.__state_ & __base_.__n_readers_) + 1;
|
||||
__base_.__state_ &= ~__base_.__n_readers_;
|
||||
__base_.__state_ |= __num_readers;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -395,13 +406,13 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
void lock();
|
||||
bool try_lock();
|
||||
_LIBCPP_HIDE_FROM_ABI void lock();
|
||||
_LIBCPP_HIDE_FROM_ABI bool try_lock();
|
||||
template <class Rep, class Period>
|
||||
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
|
||||
_LIBCPP_HIDE_FROM_ABI bool try_lock_for(const chrono::duration<Rep, Period>& __rel_time);
|
||||
template <class Clock, class Duration>
|
||||
bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
|
||||
void unlock();
|
||||
_LIBCPP_HIDE_FROM_ABI bool try_lock_until(const chrono::time_point<Clock, Duration>& __abs_time);
|
||||
_LIBCPP_HIDE_FROM_ABI void unlock();
|
||||
|
||||
// Setters
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
|
@ -430,6 +441,7 @@ public:
|
|||
_LIBCPP_INLINE_VISIBILITY
|
||||
mutex_type* mutex() const _NOEXCEPT {return __m_;}
|
||||
};
|
||||
_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(shared_lock);
|
||||
|
||||
template <class _Mutex>
|
||||
void
|
||||
|
@ -499,10 +511,12 @@ swap(shared_lock<_Mutex>& __x, shared_lock<_Mutex>& __y) _NOEXCEPT
|
|||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // !_LIBCPP_HAS_NO_THREADS
|
||||
|
||||
#endif // _LIBCPP_STD_VER > 11
|
||||
#endif // _LIBCPP_STD_VER >= 14
|
||||
|
||||
_LIBCPP_POP_MACROS
|
||||
|
||||
#endif // _LIBCPP_SHARED_MUTEX
|
||||
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
|
||||
# include <system_error>
|
||||
#endif
|
||||
|
||||
#endif // _LIBCPP_SHARED_MUTEX
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue