diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2011-11-22 14:45:35 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-10 16:11:48 +0100 |
commit | 6f0f9f69288925ef423c542ef5eb7302a5431867 (patch) | |
tree | a0ded9966183fb45b7868d25350affa2259f29a1 /src/corelib/kernel/qobject.cpp | |
parent | a6ae75f92a8628c727a9c5a9961fa91c583c008e (diff) |
Remove QMetaObject guards and deprecate QPointer.
QWeakPointer is superior and preferred.
Remove QMetaObject::addGuard(), QMetaObject::changeGuard(),
QMetaObject::removeGuard(), and QObjectPrivate::clearGuards().
Implement QPointer using QWeakPointer<T> instead. This changes the
behavior of QPointer in 2 ways:
- During destruction of a QWidget. Previously, the destructor of QWidget
would reset all QPointers so that they would return zero when destroying
children. Update tst_QPointer to account for this change.
- When constructing a QSharedPointer to take ownership of an object
after a QPointer is already tracking the object. Previously, the shared
pointer construction would not be affected by the QPointer, but now
that QPointer is implemented using QWeakPoiner, constructing the
QSharedPointer will cause an abort(). Fix tst_QSharedPointer by
removing the use of QPointer in the objectCast() test.
These behavior changes are documented in the QPointer class
documentation and in the changes file.
Change-Id: I92d0276219c076ece7bcb60f6e1b9120ce4f5747
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/kernel/qobject.cpp')
-rw-r--r-- | src/corelib/kernel/qobject.cpp | 114 |
1 files changed, 0 insertions, 114 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index f6e72e3e94..da06fc6433 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -177,7 +177,6 @@ QObjectPrivate::QObjectPrivate(int version) deleteWatch = 0; #endif metaObject = 0; - hasGuards = false; isWindow = false; } @@ -409,113 +408,6 @@ void QObjectPrivate::cleanConnectionLists() } } -typedef QMultiHash<QObject *, QObject **> GuardHash; -Q_GLOBAL_STATIC(GuardHash, guardHash) -Q_GLOBAL_STATIC(QMutex, guardHashLock) - -/*!\internal - */ -void QMetaObject::addGuard(QObject **ptr) -{ - if (!*ptr) - return; - GuardHash *hash = guardHash(); - if (!hash) { - *ptr = 0; - return; - } - QMutexLocker locker(guardHashLock()); - QObjectPrivate::get(*ptr)->hasGuards = true; - hash->insert(*ptr, ptr); -} - -/*!\internal - */ -void QMetaObject::removeGuard(QObject **ptr) -{ - if (!*ptr) - return; - GuardHash *hash = guardHash(); - /* check that the hash is empty - otherwise we might detach - the shared_null hash, which will alloc, which is not nice */ - if (!hash || hash->isEmpty()) - return; - QMutexLocker locker(guardHashLock()); - if (!*ptr) //check again, under the lock - return; - GuardHash::iterator it = hash->find(*ptr); - const GuardHash::iterator end = hash->end(); - bool more = false; //if the QObject has more pointer attached to it. - for (; it.key() == *ptr && it != end; ++it) { - if (it.value() == ptr) { - it = hash->erase(it); - if (!more) more = (it != end && it.key() == *ptr); - break; - } - more = true; - } - if (!more) - QObjectPrivate::get(*ptr)->hasGuards = false; -} - -/*!\internal - */ -void QMetaObject::changeGuard(QObject **ptr, QObject *o) -{ - GuardHash *hash = guardHash(); - if (!hash) { - *ptr = 0; - return; - } - QMutexLocker locker(guardHashLock()); - if (o) { - hash->insert(o, ptr); - QObjectPrivate::get(o)->hasGuards = true; - } - if (*ptr) { - bool more = false; //if the QObject has more pointer attached to it. - GuardHash::iterator it = hash->find(*ptr); - const GuardHash::iterator end = hash->end(); - for (; it.key() == *ptr && it != end; ++it) { - if (it.value() == ptr) { - it = hash->erase(it); - if (!more) more = (it != end && it.key() == *ptr); - break; - } - more = true; - } - if (!more) - QObjectPrivate::get(*ptr)->hasGuards = false; - } - *ptr = o; -} - -/*! \internal - */ -void QObjectPrivate::clearGuards(QObject *object) -{ - GuardHash *hash = 0; - QMutex *mutex = 0; - QT_TRY { - hash = guardHash(); - mutex = guardHashLock(); - } QT_CATCH(const std::bad_alloc &) { - // do nothing in case of OOM - code below is safe - } - - /* check that the hash is empty - otherwise we might detach - the shared_null hash, which will alloc, which is not nice */ - if (hash && !hash->isEmpty()) { - QMutexLocker locker(mutex); - GuardHash::iterator it = hash->find(object); - const GuardHash::iterator end = hash->end(); - while (it.key() == object && it != end) { - *it.value() = 0; - it = hash->erase(it); - } - } -} - /*! \internal */ QMetaCallEvent::QMetaCallEvent(ushort method_offset, ushort method_relative, QObjectPrivate::StaticMetaCallFunction callFunction, @@ -840,12 +732,6 @@ QObject::~QObject() d->wasDeleted = true; d->blockSig = 0; // unblock signals so we always emit destroyed() - if (d->hasGuards && !d->isWidget) { - // set all QPointers for this object to zero - note that - // ~QWidget() does this for us, so we don't have to do it twice - QObjectPrivate::clearGuards(this); - } - QtSharedPointer::ExternalRefCountData *sharedRefcount = d->sharedRefcount.load(); if (sharedRefcount) { if (sharedRefcount->strongref.load() > 0) { |