Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/corelib/tools/qsharedpointer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ namespace QtSharedPointer {

void destroy() { destroyer(this); }

bool isShared() const noexcept {
return strongref.loadRelaxed() != 1;
}

bool needsDetach() const noexcept {
return strongref.loadRelaxed() > 1;
}

#ifndef QT_NO_QOBJECT
Q_CORE_EXPORT static ExternalRefCountData *getAndRef(const QObject *);
QT6_ONLY(
Expand Down Expand Up @@ -463,6 +471,11 @@ template <class T> class QSharedPointer
size_t owner_hash() const noexcept
{ return std::hash<Data *>()(d); }

bool isShared() const noexcept
{ return !d || d->isShared(); }
bool needsDetach() const noexcept
{ return !d || d->needsDetach(); }

private:
Q_NODISCARD_CTOR
explicit QSharedPointer(Qt::Initialization) {}
Expand Down Expand Up @@ -717,6 +730,11 @@ class QWeakPointer
size_t owner_hash() const noexcept
{ return std::hash<Data *>()(d); }

bool isShared() const noexcept
{ return !d || d->isShared(); }
bool needsDetach() const noexcept
{ return !d || d->needsDetach(); }

private:
friend struct QtPrivate::EnableInternalData;
template <class X> friend class QSharedPointer;
Expand Down