From 13ecc38dcd0f6307fc119b4cc3b85b3491e129f2 Mon Sep 17 00:00:00 2001 From: Alexander Golubev Date: Wed, 13 Mar 2024 23:01:57 +0300 Subject: [PATCH] Add a lock to removing ourself from another's object's sender list Also simplify locks around removeObjFromList() in disconnectInternal(). Signed-off-by: Alexander Golubev --- src/kernel/qobject.cpp | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/kernel/qobject.cpp b/src/kernel/qobject.cpp index 5c78c17b..62ea618b 100644 --- a/src/kernel/qobject.cpp +++ b/src/kernel/qobject.cpp @@ -769,6 +769,9 @@ TQObject::~TQObject() while( (c=cit.current()) ) { // for each connected slot... ++cit; if ( (obj=c->object()) ) { +#ifdef TQT_THREAD_SUPPORT + TQMutexLocker locker( obj->senderObjects->listMutex ); +#endif // TQT_THREAD_SUPPORT removeObjFromList( obj->senderObjects, this ); } } @@ -2494,25 +2497,23 @@ bool TQObject::disconnectInternal( const TQObject *sender, int signal_index, c = clist->first(); while ( c ) { // for all receivers... if ( r == 0 ) { // remove all receivers + if (c->object()->senderObjects) { #ifdef TQT_THREAD_SUPPORT - if (c->object()->senderObjects) c->object()->senderObjects->listMutex->lock(); -#endif // TQT_THREAD_SUPPORT - removeObjFromList( c->object()->senderObjects, s ); -#ifdef TQT_THREAD_SUPPORT - if (c->object()->senderObjects) c->object()->senderObjects->listMutex->unlock(); + TQMutexLocker locker(c->object()->senderObjects->listMutex); #endif // TQT_THREAD_SUPPORT + removeObjFromList( c->object()->senderObjects, s ); + } success = TRUE; c = clist->next(); } else if ( r == c->object() && ( (member_index == -1) || ((member_index == c->member()) && (c->memberType() == membcode)) ) ) { + if (c->object()->senderObjects) { #ifdef TQT_THREAD_SUPPORT - if (c->object()->senderObjects) c->object()->senderObjects->listMutex->lock(); -#endif // TQT_THREAD_SUPPORT - removeObjFromList( c->object()->senderObjects, s, TRUE ); -#ifdef TQT_THREAD_SUPPORT - if (c->object()->senderObjects) c->object()->senderObjects->listMutex->unlock(); + TQMutexLocker locker(c->object()->senderObjects->listMutex); #endif // TQT_THREAD_SUPPORT + removeObjFromList( c->object()->senderObjects, s, TRUE ); + } success = TRUE; clist->remove(); c = clist->current(); @@ -2531,25 +2532,23 @@ bool TQObject::disconnectInternal( const TQObject *sender, int signal_index, c = clist->first(); while ( c ) { // for all receivers... if ( r == 0 ) { // remove all receivers + if (c->object()->senderObjects) { #ifdef TQT_THREAD_SUPPORT - if (c->object()->senderObjects) c->object()->senderObjects->listMutex->lock(); -#endif // TQT_THREAD_SUPPORT - removeObjFromList( c->object()->senderObjects, s, TRUE ); -#ifdef TQT_THREAD_SUPPORT - if (c->object()->senderObjects) c->object()->senderObjects->listMutex->unlock(); + TQMutexLocker locker(c->object()->senderObjects->listMutex); #endif // TQT_THREAD_SUPPORT + removeObjFromList( c->object()->senderObjects, s, TRUE ); + } success = TRUE; c = clist->next(); } else if ( r == c->object() && ( (member_index == -1) || ((member_index == c->member()) && (c->memberType() == membcode)) ) ) { + if (c->object()->senderObjects) { #ifdef TQT_THREAD_SUPPORT - if (c->object()->senderObjects) c->object()->senderObjects->listMutex->lock(); -#endif // TQT_THREAD_SUPPORT - removeObjFromList( c->object()->senderObjects, s, TRUE ); -#ifdef TQT_THREAD_SUPPORT - if (c->object()->senderObjects) c->object()->senderObjects->listMutex->unlock(); + TQMutexLocker locker(c->object()->senderObjects->listMutex); #endif // TQT_THREAD_SUPPORT + removeObjFromList( c->object()->senderObjects, s, TRUE ); + } success = TRUE; clist->remove(); c = clist->current();