diff options
author | Alexander Golubev <[email protected]> | 2024-03-13 23:01:57 +0300 |
---|---|---|
committer | Alexander Golubev <[email protected]> | 2024-03-16 02:45:44 +0300 |
commit | 13ecc38dcd0f6307fc119b4cc3b85b3491e129f2 (patch) | |
tree | fc73f003dac4d5f5e08ad9ee6923d1051a0e0472 | |
parent | ba2deea50adde9d33b65a4d1012f8402bf44b590 (diff) | |
download | tqt3-13ecc38dcd0f6307fc119b4cc3b85b3491e129f2.tar.gz tqt3-13ecc38dcd0f6307fc119b4cc3b85b3491e129f2.zip |
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 <[email protected]>
-rw-r--r-- | src/kernel/qobject.cpp | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/src/kernel/qobject.cpp b/src/kernel/qobject.cpp index 5c78c17bc..62ea618b9 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(); |