diff options
| author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2023-09-24 22:39:13 +0200 |
|---|---|---|
| committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2023-09-26 22:32:51 +0200 |
| commit | 10324df60ebf42012adb81e0cdb9122df2aac72a (patch) | |
| tree | 8d21f23f2784f68996330117b833d9228a1f7883 /src/network/socket/qnativesocketengine_unix.cpp | |
| parent | 35878fa924d0598b1cdec5ba358e8488f6774676 (diff) | |
QWeakPointer: optimize the converting constructor
The converting constructor of QWeakPointer<T> from a QWeakPointer<X>
needs to adjust the X* received by the "source" to a T*.
In case of non-virtual inheritance, this adjustment can be done
statically, by applying an offset to the pointer. In case of virtual
inheritance, we instead need to dereference the pointer (=access the
pointee), get its vtable, and from there find where (=the offset at
which) the T subobject is located.
This latter scenario requires the pointee to be alive throughout this
operation. Since QWeakPointer isn't an owning smart pointer, it's
perfectly possible that the pointee has already been deleted (the
"source" QWeakPointer<X> is dangling) or is being deleted (e.g. from
another thread that has just released the last QSharedPointer). For
this reason the converting constructor of QWeakPointer employs a
protection: it will lock() itself, and extract the raw pointer from the
QSharedPointer so obtained. This ensures that we won't access a dangling
pointer or a pointee about to be deleted.
We can however limit this (relatively expensive) protection only to the
case where there is virtual inheritance. In the other cases we don't
need it. This commit overloads the converting constructor for
QWeakPointer to deal with the two scenarios separately, and only lock()
in case of virtual inheritance.
Change-Id: I7194b90478cf35024e60cff542091308e4131ec2
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/network/socket/qnativesocketengine_unix.cpp')
0 files changed, 0 insertions, 0 deletions
