summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qobject_p.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2019-01-09 09:48:59 +0100
committerLars Knoll <lars.knoll@qt.io>2019-02-08 21:55:35 +0000
commit0e534bf8b704b8ae24b87a9b1dcb5cd829c9dd2f (patch)
tree52c5690afea6f2c1e1040f083e5e69c0e869d590 /src/corelib/kernel/qobject_p.h
parent5cc6f90910082f35e3f5340493facbc8c175f65f (diff)
Replace the ConnectionData::inUse int with a proper refcount
The main difference is that QObject itself also holds on reference on the structure. Also rename the orphaned flag to objectDeleted for clarity. Change-Id: Ief9b9ff9c8b9cc3630dcfd29806ed24cd07150e4 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/kernel/qobject_p.h')
-rw-r--r--src/corelib/kernel/qobject_p.h16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h
index 64998797ac..823c7a195a 100644
--- a/src/corelib/kernel/qobject_p.h
+++ b/src/corelib/kernel/qobject_p.h
@@ -210,9 +210,16 @@ public:
linked list.
*/
struct ConnectionData {
- bool orphaned = false; //the QObject owner of this vector has been destroyed while the vector was inUse
+ bool objectDeleted = false; //the QObject owner of this vector has been destroyed while the vector was inUse
+ struct Ref {
+ int _ref = 0;
+ void ref() { ++_ref; }
+ int deref() { return --_ref; }
+ operator int() const { return _ref; }
+ };
+
+ Ref ref;
bool dirty = false; //some Connection have been disconnected (their receiver is 0) but not removed from the list yet
- int inUse = 0; //number of functions that are currently accessing this object or its connections
ConnectionList allsignals;
QVector<ConnectionList> signalVector;
Connection *senders = nullptr;
@@ -274,12 +281,15 @@ public:
{
if (connections.load())
return;
- connections.store(new ConnectionData);
+ ConnectionData *cd = new ConnectionData;
+ cd->ref.ref();
+ connections.store(cd);
}
public:
ExtraData *extraData; // extra data set by the user
QThreadData *threadData; // id of the thread that owns the object
+ using ConnectionDataPointer = QExplicitlySharedDataPointer<ConnectionData>;
QAtomicPointer<ConnectionData> connections;
union {