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 <fatzer2@gmail.com>
feat/dedup-tqobject
Alexander Golubev 9 months ago
parent ba2deea50a
commit 13ecc38dcd

@ -769,6 +769,9 @@ TQObject::~TQObject()
while( (c=cit.current()) ) { // for each connected slot... while( (c=cit.current()) ) { // for each connected slot...
++cit; ++cit;
if ( (obj=c->object()) ) { if ( (obj=c->object()) ) {
#ifdef TQT_THREAD_SUPPORT
TQMutexLocker locker( obj->senderObjects->listMutex );
#endif // TQT_THREAD_SUPPORT
removeObjFromList( obj->senderObjects, this ); removeObjFromList( obj->senderObjects, this );
} }
} }
@ -2494,25 +2497,23 @@ bool TQObject::disconnectInternal( const TQObject *sender, int signal_index,
c = clist->first(); c = clist->first();
while ( c ) { // for all receivers... while ( c ) { // for all receivers...
if ( r == 0 ) { // remove all receivers if ( r == 0 ) { // remove all receivers
if (c->object()->senderObjects) {
#ifdef TQT_THREAD_SUPPORT #ifdef TQT_THREAD_SUPPORT
if (c->object()->senderObjects) c->object()->senderObjects->listMutex->lock(); TQMutexLocker locker(c->object()->senderObjects->listMutex);
#endif // TQT_THREAD_SUPPORT
removeObjFromList( c->object()->senderObjects, s );
#ifdef TQT_THREAD_SUPPORT
if (c->object()->senderObjects) c->object()->senderObjects->listMutex->unlock();
#endif // TQT_THREAD_SUPPORT #endif // TQT_THREAD_SUPPORT
removeObjFromList( c->object()->senderObjects, s );
}
success = TRUE; success = TRUE;
c = clist->next(); c = clist->next();
} else if ( r == c->object() && } else if ( r == c->object() &&
( (member_index == -1) || ( (member_index == -1) ||
((member_index == c->member()) && (c->memberType() == membcode)) ) ) { ((member_index == c->member()) && (c->memberType() == membcode)) ) ) {
if (c->object()->senderObjects) {
#ifdef TQT_THREAD_SUPPORT #ifdef TQT_THREAD_SUPPORT
if (c->object()->senderObjects) c->object()->senderObjects->listMutex->lock(); TQMutexLocker locker(c->object()->senderObjects->listMutex);
#endif // TQT_THREAD_SUPPORT
removeObjFromList( c->object()->senderObjects, s, TRUE );
#ifdef TQT_THREAD_SUPPORT
if (c->object()->senderObjects) c->object()->senderObjects->listMutex->unlock();
#endif // TQT_THREAD_SUPPORT #endif // TQT_THREAD_SUPPORT
removeObjFromList( c->object()->senderObjects, s, TRUE );
}
success = TRUE; success = TRUE;
clist->remove(); clist->remove();
c = clist->current(); c = clist->current();
@ -2531,25 +2532,23 @@ bool TQObject::disconnectInternal( const TQObject *sender, int signal_index,
c = clist->first(); c = clist->first();
while ( c ) { // for all receivers... while ( c ) { // for all receivers...
if ( r == 0 ) { // remove all receivers if ( r == 0 ) { // remove all receivers
if (c->object()->senderObjects) {
#ifdef TQT_THREAD_SUPPORT #ifdef TQT_THREAD_SUPPORT
if (c->object()->senderObjects) c->object()->senderObjects->listMutex->lock(); TQMutexLocker locker(c->object()->senderObjects->listMutex);
#endif // TQT_THREAD_SUPPORT
removeObjFromList( c->object()->senderObjects, s, TRUE );
#ifdef TQT_THREAD_SUPPORT
if (c->object()->senderObjects) c->object()->senderObjects->listMutex->unlock();
#endif // TQT_THREAD_SUPPORT #endif // TQT_THREAD_SUPPORT
removeObjFromList( c->object()->senderObjects, s, TRUE );
}
success = TRUE; success = TRUE;
c = clist->next(); c = clist->next();
} else if ( r == c->object() && } else if ( r == c->object() &&
( (member_index == -1) || ( (member_index == -1) ||
((member_index == c->member()) && (c->memberType() == membcode)) ) ) { ((member_index == c->member()) && (c->memberType() == membcode)) ) ) {
if (c->object()->senderObjects) {
#ifdef TQT_THREAD_SUPPORT #ifdef TQT_THREAD_SUPPORT
if (c->object()->senderObjects) c->object()->senderObjects->listMutex->lock(); TQMutexLocker locker(c->object()->senderObjects->listMutex);
#endif // TQT_THREAD_SUPPORT
removeObjFromList( c->object()->senderObjects, s, TRUE );
#ifdef TQT_THREAD_SUPPORT
if (c->object()->senderObjects) c->object()->senderObjects->listMutex->unlock();
#endif // TQT_THREAD_SUPPORT #endif // TQT_THREAD_SUPPORT
removeObjFromList( c->object()->senderObjects, s, TRUE );
}
success = TRUE; success = TRUE;
clist->remove(); clist->remove();
c = clist->current(); c = clist->current();

Loading…
Cancel
Save