summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonardo Sobral Cunha <leo.cunha@nokia.com>2009-08-28 16:23:05 (GMT)
committerLeonardo Sobral Cunha <leo.cunha@nokia.com>2009-08-28 17:10:53 (GMT)
commit93232a4283cf2fc1e64fe63f70ac3fb0250c8b23 (patch)
treea7d2d69dc4e42ba17975b9e11121c155895ad124
parent761793aec914f4af5b3145400091c58b74c37ebf (diff)
downloadQt-93232a4283cf2fc1e64fe63f70ac3fb0250c8b23.zip
Qt-93232a4283cf2fc1e64fe63f70ac3fb0250c8b23.tar.gz
Qt-93232a4283cf2fc1e64fe63f70ac3fb0250c8b23.tar.bz2
QMetaObjectPrivate: refactor internal disconnect to avoid duplicate code
Reviewed-by: ogoffart
-rw-r--r--src/corelib/kernel/qmetaobject_p.h5
-rw-r--r--src/corelib/kernel/qobject.cpp91
2 files changed, 47 insertions, 49 deletions
diff --git a/src/corelib/kernel/qmetaobject_p.h b/src/corelib/kernel/qmetaobject_p.h
index d843deb..fdf36f3 100644
--- a/src/corelib/kernel/qmetaobject_p.h
+++ b/src/corelib/kernel/qmetaobject_p.h
@@ -102,6 +102,7 @@ enum MetaObjectFlags {
DynamicMetaObject = 0x01
};
+class QMutex;
struct QMetaObjectPrivate
{
@@ -127,7 +128,9 @@ struct QMetaObjectPrivate
int type = 0, int *types = 0);
static bool disconnect(const QObject *sender, int signal_index,
const QObject *receiver, int method_index);
-
+ static inline bool disconnectHelper(QObjectPrivate::Connection *c,
+ const QObject *receiver, int method_index,
+ QMutex *senderMutex);
};
#ifndef UTILS_H
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index e080bd6..6a451d5 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -3079,6 +3079,43 @@ bool QMetaObject::disconnect(const QObject *sender, int signal_index,
}
/*! \internal
+ Helper function to remove the connection from the senders list and setting the receivers to 0
+ */
+bool QMetaObjectPrivate::disconnectHelper(QObjectPrivate::Connection *c,
+ const QObject *receiver, int method_index,
+ QMutex *senderMutex)
+{
+ bool success = false;
+ while (c) {
+ if (c->receiver
+ && (receiver == 0 || (c->receiver == receiver
+ && (method_index < 0 || c->method == method_index)))) {
+ bool needToUnlock = false;
+ QMutex *receiverMutex = 0;
+ if (!receiver) {
+ receiverMutex = signalSlotLock(c->receiver);
+ // need to relock this receiver and sender in the correct order
+ needToUnlock = QOrderedMutexLocker::relock(senderMutex, receiverMutex);
+ }
+ if (c->receiver) {
+ *c->prev = c->next;
+ if (c->next)
+ c->next->prev = c->prev;
+ }
+
+ if (needToUnlock)
+ receiverMutex->unlock();
+
+ c->receiver = 0;
+
+ success = true;
+ }
+ c = c->nextConnectionList;
+ }
+ return success;
+}
+
+/*! \internal
Same as the QMetaObject::disconnect, but \a signal_index must be the result of QObjectPrivate::signalIndex
*/
bool QMetaObjectPrivate::disconnect(const QObject *sender, int signal_index,
@@ -3088,7 +3125,6 @@ bool QMetaObjectPrivate::disconnect(const QObject *sender, int signal_index,
return false;
QObject *s = const_cast<QObject *>(sender);
- QObject *r = const_cast<QObject *>(receiver);
QMutex *senderMutex = signalSlotLock(sender);
QMutex *receiverMutex = receiver ? signalSlotLock(receiver) : 0;
@@ -3107,58 +3143,17 @@ bool QMetaObjectPrivate::disconnect(const QObject *sender, int signal_index,
for (signal_index = -1; signal_index < connectionLists->count(); ++signal_index) {
QObjectPrivate::Connection *c =
(*connectionLists)[signal_index].first;
- while (c) {
- if (c->receiver
- && (r == 0 || (c->receiver == r
- && (method_index < 0 || c->method == method_index)))) {
- QMutex *m = signalSlotLock(c->receiver);
- bool needToUnlock = false;
- if (!receiverMutex && senderMutex != m) {
- // need to relock this receiver and sender in the correct order
- needToUnlock = QOrderedMutexLocker::relock(senderMutex, m);
- }
- if (c->receiver) {
- *c->prev = c->next;
- if (c->next) c->next->prev = c->prev;
- }
-
- if (needToUnlock)
- m->unlock();
-
- c->receiver = 0;
-
- success = true;
- connectionLists->dirty = true;
- }
- c = c->nextConnectionList;
+ if (disconnectHelper(c, receiver, method_index, senderMutex)) {
+ success = true;
+ connectionLists->dirty = true;
}
}
} else if (signal_index < connectionLists->count()) {
QObjectPrivate::Connection *c =
(*connectionLists)[signal_index].first;
- while (c) {
- if (c->receiver
- && (r == 0 || (c->receiver == r
- && (method_index < 0 || c->method == method_index)))) {
- QMutex *m = signalSlotLock(c->receiver);
- bool needToUnlock = false;
- if (!receiverMutex && senderMutex != m) {
- // need to relock this receiver and sender in the correct order
- needToUnlock = QOrderedMutexLocker::relock(senderMutex, m);
- }
- if (c->receiver) {
- *c->prev = c->next;
- if (c->next) c->next->prev = c->prev;
- }
-
- if (needToUnlock)
- m->unlock();
- c->receiver = 0;
-
- success = true;
- connectionLists->dirty = true;
- }
- c = c->nextConnectionList;
+ if (disconnectHelper(c, receiver, method_index, senderMutex)) {
+ success = true;
+ connectionLists->dirty = true;
}
}