mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-26 22:38:30 +00:00
Make more shared_ptr fixes (#1401)
Some checks failed
build / matrix_on_mode () (push) Has been cancelled
build / matrix_on_mode (optlinux) (push) Has been cancelled
build / matrix_on_mode (rel) (push) Has been cancelled
build / matrix_on_mode (tiny) (push) Has been cancelled
build / matrix_on_mode (tinylinux) (push) Has been cancelled
Some checks failed
build / matrix_on_mode () (push) Has been cancelled
build / matrix_on_mode (optlinux) (push) Has been cancelled
build / matrix_on_mode (rel) (push) Has been cancelled
build / matrix_on_mode (tiny) (push) Has been cancelled
build / matrix_on_mode (tinylinux) (push) Has been cancelled
* Make refcount reads explicitly atomic * Consistently put `const` in the same place * Write the general `operator=` on `weak_ptr`
This commit is contained in:
parent
9c68bc19b5
commit
455910e8f2
1 changed files with 11 additions and 4 deletions
|
@ -97,12 +97,12 @@ class shared_ref
|
|||
|
||||
size_t use_count() const noexcept
|
||||
{
|
||||
return shared + 1;
|
||||
return __atomic_load_n(&shared, __ATOMIC_RELAXED) + 1;
|
||||
}
|
||||
|
||||
size_t weak_count() const noexcept
|
||||
{
|
||||
return weak;
|
||||
return __atomic_load_n(&weak, __ATOMIC_RELAXED);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -382,7 +382,7 @@ class weak_ptr
|
|||
rc->keep_weak();
|
||||
}
|
||||
|
||||
weak_ptr(weak_ptr const& r) noexcept : p(r.p), rc(r.rc)
|
||||
weak_ptr(const weak_ptr& r) noexcept : p(r.p), rc(r.rc)
|
||||
{
|
||||
if (rc)
|
||||
rc->keep_weak();
|
||||
|
@ -390,7 +390,7 @@ class weak_ptr
|
|||
|
||||
template<typename U>
|
||||
requires __::shared_ptr_compatible<T, U>
|
||||
weak_ptr(weak_ptr<U> const& r) noexcept : p(r.p), rc(r.rc)
|
||||
weak_ptr(const weak_ptr<U>& r) noexcept : p(r.p), rc(r.rc)
|
||||
{
|
||||
if (rc)
|
||||
rc->keep_weak();
|
||||
|
@ -444,6 +444,13 @@ class weak_ptr
|
|||
return *this;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
requires __::shared_ptr_compatible<T, U>
|
||||
weak_ptr& operator=(weak_ptr<U> r) noexcept
|
||||
{
|
||||
weak_ptr<T>(move(r)).swap(*this);
|
||||
}
|
||||
|
||||
shared_ptr<T> lock() const noexcept
|
||||
{
|
||||
if (expired())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue