diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-05-14 19:35:54 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-05-14 19:35:54 -0500 |
commit | 9a4765a62e321af08ec96a03cdbef64039788e86 (patch) | |
tree | fd261fdcf042d490030a2a1d337cf1b7cc8b514f /src/kernel/qobject.cpp | |
parent | c740211ffba3330d951f4c3ddefea8edf23a01cd (diff) | |
download | tqt3-9a4765a62e321af08ec96a03cdbef64039788e86.tar.gz tqt3-9a4765a62e321af08ec96a03cdbef64039788e86.zip |
Automated update from Qt3
Diffstat (limited to 'src/kernel/qobject.cpp')
-rw-r--r-- | src/kernel/qobject.cpp | 199 |
1 files changed, 177 insertions, 22 deletions
diff --git a/src/kernel/qobject.cpp b/src/kernel/qobject.cpp index 2e3843761..d8b2047a0 100644 --- a/src/kernel/qobject.cpp +++ b/src/kernel/qobject.cpp @@ -73,6 +73,8 @@ public: } #endif TQThread* ownThread; + TQMutex* senderObjectListMutex; + TQMutex* childObjectListMutex; bool disableThreadPostedEvents; }; @@ -83,6 +85,10 @@ void TQObject::moveToThread_helper(TQThread *targetThread) TQEvent e(TQEvent::ThreadChange); TQApplication::sendEvent(this, &e); +#ifdef QT_THREAD_SUPPORT + TQMutexLocker locker( d->childObjectListMutex ); +#endif // QT_THREAD_SUPPORT + if (childObjects) { TQObject *child; TQObjectListIt it(*childObjects); @@ -97,12 +103,16 @@ void TQObject::setThreadObject_helper(TQThread *targetThread) { d->ownThread = targetThread; +#ifdef QT_THREAD_SUPPORT + TQMutexLocker locker( d->childObjectListMutex ); +#endif // QT_THREAD_SUPPORT + if (childObjects) { TQObject *child; TQObjectListIt it(*childObjects); while ( (child=it.current()) ) { ++it; - child->moveToThread_helper(targetThread); + child->setThreadObject_helper(targetThread); } } } @@ -123,7 +133,9 @@ void TQObject::setThreadObject_helper(TQThread *targetThread) */ void TQObject::moveToThread(TQThread *targetThread) { +#ifdef QT_THREAD_SUPPORT TQMutexLocker locker( TQApplication::tqt_mutex ); +#endif // QT_THREAD_SUPPORT if (parentObj) { #if defined(QT_DEBUG) @@ -179,11 +191,23 @@ void TQObject::disableThreadPostedEvents(bool disable) { class TQSenderObjectList : public TQObjectList, public TQShared { -public: - TQSenderObjectList() : currentSender( 0 ) { } - TQObject *currentSender; + public: + TQSenderObjectList(); + ~TQSenderObjectList(); + + public: + TQObject *currentSender; + TQMutex *listMutex; }; +TQSenderObjectList::TQSenderObjectList() : currentSender( 0 ) { + listMutex = new TQMutex( TRUE ); +} + +TQSenderObjectList::~TQSenderObjectList() { + delete listMutex; +} + class Q_EXPORT TQMetaCallEvent : public TQEvent { public: @@ -369,8 +393,9 @@ bool qKillTimer( TQObject *obj ); static void removeObjFromList( TQObjectList *objList, const TQObject *obj, bool single=FALSE ) { - if ( !objList ) + if ( !objList ) { return; + } int index = objList->findRef( obj ); while ( index >= 0 ) { objList->remove(); @@ -585,20 +610,25 @@ TQObject::TQObject( TQObject *parent, const char *name ) postedEvents( 0 ), // no events posted d( 0 ) { - if ( !metaObj ) // will create object dict + if ( !d ) { + d = new TQObjectPrivate(0); + } + + d->ownThread = TQThread::currentThreadObject(); + d->senderObjectListMutex = new TQMutex( TRUE ); + d->childObjectListMutex = new TQMutex( TRUE ); + + if ( !metaObj ) { // will create object dict (void) staticMetaObject(); + } if ( parent ) { // add object to parent parent->insertChild( this ); - } else { + } + else { insert_tree( this ); isTree = TRUE; } - - if ( !d ) - d = new TQObjectPrivate(0); - - d->ownThread = TQThread::currentThreadObject(); } @@ -630,10 +660,15 @@ TQObject::~TQObject() #endif return; } + if (tqApp) { + TQEvent destroyEvent(TQEvent::Destroy); + tqApp->notify(this, &destroyEvent); + } wasDeleted = 1; blockSig = 0; // unblock signals to keep TQGuardedPtr happy emit destroyed( this ); emit destroyed(); + if ( objname ) { delete [] (char*)objname; } @@ -669,8 +704,9 @@ TQObject::~TQObject() TQConnectionListIt cit(*clist); while( (c=cit.current()) ) { // for each connected slot... ++cit; - if ( (obj=c->object()) ) + if ( (obj=c->object()) ) { removeObjFromList( obj->senderObjects, this ); + } } } delete connections; @@ -691,6 +727,11 @@ TQObject::~TQObject() delete childObjects; } +#ifdef QT_THREAD_SUPPORT + delete d->childObjectListMutex; + delete d->senderObjectListMutex; +#endif // QT_THREAD_SUPPORT + delete d; } @@ -985,11 +1026,17 @@ bool TQObject::event( TQEvent *e ) TQSenderObjectList* sol; TQObject* oldSender = 0; sol = senderObjects; +#ifdef QT_THREAD_SUPPORT + sol->listMutex->lock(); +#endif // QT_THREAD_SUPPORT if ( sol ) { oldSender = sol->currentSender; sol->ref(); sol->currentSender = metaEvent->sender(); } +#ifdef QT_THREAD_SUPPORT + sol->listMutex->unlock(); +#endif // QT_THREAD_SUPPORT TQUObject *o = metaEvent->data(); if (metaEvent->type() == TQMetaCallEvent::MetaCallEmit) { tqt_emit( metaEvent->id(), o ); @@ -997,12 +1044,20 @@ bool TQObject::event( TQEvent *e ) if (metaEvent->type() == TQMetaCallEvent::MetaCallInvoke) { tqt_invoke( metaEvent->id(), o ); } +#ifdef QT_THREAD_SUPPORT + sol->listMutex->lock(); +#endif // QT_THREAD_SUPPORT if (sol ) { sol->currentSender = oldSender; if ( sol->deref() ) { + sol->listMutex->unlock(); delete sol; + sol = NULL; } } +#ifdef QT_THREAD_SUPPORT + if (sol) sol->listMutex->unlock(); +#endif // QT_THREAD_SUPPORT } else { tqWarning("TQObject: Ignoring metacall event from non-owning thread"); @@ -1509,6 +1564,10 @@ TQConnectionList *TQObject::receivers( int signal ) const void TQObject::insertChild( TQObject *obj ) { +#ifdef QT_THREAD_SUPPORT + TQMutexLocker locker( d->childObjectListMutex ); +#endif // QT_THREAD_SUPPORT + if ( obj->isTree ) { remove_tree( obj ); obj->isTree = FALSE; @@ -1551,6 +1610,10 @@ void TQObject::insertChild( TQObject *obj ) void TQObject::removeChild( TQObject *obj ) { +#ifdef QT_THREAD_SUPPORT + TQMutexLocker locker( d->childObjectListMutex ); +#endif // QT_THREAD_SUPPORT + if ( childObjects && childObjects->removeRef(obj) ) { obj->parentObj = 0; if ( !obj->wasDeleted ) { @@ -2135,9 +2198,25 @@ void TQObject::connectInternal( const TQObject *sender, int signal_index, const TQConnection *c = new TQConnection( r, member_index, rm ? rm->name : "qt_invoke", membcode ); TQ_CHECK_PTR( c ); clist->append( c ); - if ( !r->senderObjects ) // create list of senders + if ( !r->senderObjects ) { // create list of senders +#ifdef QT_THREAD_SUPPORT + r->d->senderObjectListMutex->lock(); +#endif // QT_THREAD_SUPPORT r->senderObjects = new TQSenderObjectList; +#ifdef QT_THREAD_SUPPORT + r->senderObjects->listMutex->lock(); + r->d->senderObjectListMutex->unlock(); +#endif // QT_THREAD_SUPPORT + } + else { +#ifdef QT_THREAD_SUPPORT + r->senderObjects->listMutex->lock(); +#endif // QT_THREAD_SUPPORT + } r->senderObjects->append( s ); // add sender to list +#ifdef QT_THREAD_SUPPORT + r->senderObjects->listMutex->unlock(); +#endif // QT_THREAD_SUPPORT } @@ -2343,13 +2422,25 @@ bool TQObject::disconnectInternal( const TQObject *sender, int signal_index, c = clist->first(); while ( c ) { // for all receivers... if ( r == 0 ) { // remove all receivers +#ifdef QT_THREAD_SUPPORT + if (c->object()->senderObjects) c->object()->senderObjects->listMutex->lock(); +#endif // QT_THREAD_SUPPORT removeObjFromList( c->object()->senderObjects, s ); +#ifdef QT_THREAD_SUPPORT + if (c->object()->senderObjects) c->object()->senderObjects->listMutex->unlock(); +#endif // QT_THREAD_SUPPORT success = TRUE; c = clist->next(); } else if ( r == c->object() && ( (member_index == -1) || ((member_index == c->member()) && (c->memberType() == membcode)) ) ) { +#ifdef QT_THREAD_SUPPORT + if (c->object()->senderObjects) c->object()->senderObjects->listMutex->lock(); +#endif // QT_THREAD_SUPPORT removeObjFromList( c->object()->senderObjects, s, TRUE ); +#ifdef QT_THREAD_SUPPORT + if (c->object()->senderObjects) c->object()->senderObjects->listMutex->unlock(); +#endif // QT_THREAD_SUPPORT success = TRUE; clist->remove(); c = clist->current(); @@ -2368,13 +2459,25 @@ bool TQObject::disconnectInternal( const TQObject *sender, int signal_index, c = clist->first(); while ( c ) { // for all receivers... if ( r == 0 ) { // remove all receivers +#ifdef QT_THREAD_SUPPORT + if (c->object()->senderObjects) c->object()->senderObjects->listMutex->lock(); +#endif // QT_THREAD_SUPPORT removeObjFromList( c->object()->senderObjects, s, TRUE ); +#ifdef QT_THREAD_SUPPORT + if (c->object()->senderObjects) c->object()->senderObjects->listMutex->unlock(); +#endif // QT_THREAD_SUPPORT success = TRUE; c = clist->next(); } else if ( r == c->object() && ( (member_index == -1) || ((member_index == c->member()) && (c->memberType() == membcode)) ) ) { +#ifdef QT_THREAD_SUPPORT + if (c->object()->senderObjects) c->object()->senderObjects->listMutex->lock(); +#endif // QT_THREAD_SUPPORT removeObjFromList( c->object()->senderObjects, s, TRUE ); +#ifdef QT_THREAD_SUPPORT + if (c->object()->senderObjects) c->object()->senderObjects->listMutex->unlock(); +#endif // QT_THREAD_SUPPORT success = TRUE; clist->remove(); c = clist->current(); @@ -2382,8 +2485,9 @@ bool TQObject::disconnectInternal( const TQObject *sender, int signal_index, c = clist->next(); } } - if ( r == 0 ) // disconnect all receivers + if ( r == 0 ) { // disconnect all receivers s->connections->insert( signal_index, 0 ); + } } return success; } @@ -2578,11 +2682,13 @@ void TQObject::activate_signal( int signal ) } #endif - if ( !connections || signalsBlocked() || signal < 0 ) + if ( !connections || signalsBlocked() || signal < 0 ) { return; + } TQConnectionList *clist = connections->at( signal ); - if ( !clist ) + if ( !clist ) { return; + } TQUObject o[1]; o[0].isLastObject = true; activate_signal( clist, o ); @@ -2592,12 +2698,14 @@ void TQObject::activate_signal( int signal ) void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o ) { - if ( !clist ) + if ( !clist ) { return; + } #ifndef QT_NO_PRELIMINARY_SIGNAL_SPY - if ( tqt_preliminary_signal_spy ) + if ( tqt_preliminary_signal_spy ) { qt_spy_signal( this, connections->findRef( clist), o ); + } #endif const TQThread *currentThread = TQThread::currentThreadObject(); @@ -2610,6 +2718,9 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o ) c = clist->first(); object = c->object(); sol = object->senderObjects; +#ifdef QT_THREAD_SUPPORT + sol->listMutex->lock(); +#endif // QT_THREAD_SUPPORT if ( sol ) { oldSender = sol->currentSender; sol->ref(); @@ -2617,7 +2728,13 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o ) } if ( c->memberType() == TQSIGNAL_CODE ) { if ((d->disableThreadPostedEvents) || (object->d->ownThread == currentThread)) { +#ifdef QT_THREAD_SUPPORT + sol->listMutex->unlock(); +#endif // QT_THREAD_SUPPORT object->tqt_emit( c->member(), o ); +#ifdef QT_THREAD_SUPPORT + sol->listMutex->lock(); +#endif // QT_THREAD_SUPPORT } else { if (object->d->ownThread && !object->d->ownThread->finished()) { @@ -2627,7 +2744,13 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o ) } else { if ((d->disableThreadPostedEvents) || (object->d->ownThread == currentThread)) { +#ifdef QT_THREAD_SUPPORT + sol->listMutex->unlock(); +#endif // QT_THREAD_SUPPORT object->tqt_invoke( c->member(), o ); +#ifdef QT_THREAD_SUPPORT + sol->listMutex->lock(); +#endif // QT_THREAD_SUPPORT } else { if (object->d->ownThread && !object->d->ownThread->finished()) { @@ -2637,9 +2760,15 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o ) } if ( sol ) { sol->currentSender = oldSender; - if ( sol->deref() ) + if ( sol->deref() ) { + sol->listMutex->unlock(); delete sol; + sol = NULL; + } } +#ifdef QT_THREAD_SUPPORT + if (sol) sol->listMutex->unlock(); +#endif // QT_THREAD_SUPPORT } else { TQConnection *cd = 0; TQConnectionListIt it(*clist); @@ -2650,6 +2779,9 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o ) cd = c; object = c->object(); sol = object->senderObjects; +#ifdef QT_THREAD_SUPPORT + sol->listMutex->lock(); +#endif // QT_THREAD_SUPPORT if ( sol ) { oldSender = sol->currentSender; sol->ref(); @@ -2657,7 +2789,13 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o ) } if ( c->memberType() == TQSIGNAL_CODE ) { if ((d->disableThreadPostedEvents) || (object->d->ownThread == currentThread)) { +#ifdef QT_THREAD_SUPPORT + sol->listMutex->unlock(); +#endif // QT_THREAD_SUPPORT object->tqt_emit( c->member(), o ); +#ifdef QT_THREAD_SUPPORT + sol->listMutex->lock(); +#endif // QT_THREAD_SUPPORT } else { if (object->d->ownThread && !object->d->ownThread->finished()) { @@ -2667,7 +2805,13 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o ) } else { if ((d->disableThreadPostedEvents) || (object->d->ownThread == currentThread)) { +#ifdef QT_THREAD_SUPPORT + sol->listMutex->unlock(); +#endif // QT_THREAD_SUPPORT object->tqt_invoke( c->member(), o ); +#ifdef QT_THREAD_SUPPORT + sol->listMutex->lock(); +#endif // QT_THREAD_SUPPORT } else { if (object->d->ownThread && !object->d->ownThread->finished()) { @@ -2677,9 +2821,15 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o ) } if (sol ) { sol->currentSender = oldSender; - if ( sol->deref() ) + if ( sol->deref() ) { + sol->listMutex->unlock(); delete sol; + sol = NULL; + } } +#ifdef QT_THREAD_SUPPORT + if (sol) sol->listMutex->unlock(); +#endif // QT_THREAD_SUPPORT } } } @@ -2818,6 +2968,10 @@ void TQObject::dumpObjectTree() void TQObject::dumpObjectInfo() { +#ifdef QT_THREAD_SUPPORT + TQMutexLocker locker( d->senderObjectListMutex ); +#endif // QT_THREAD_SUPPORT + #if defined(QT_DEBUG) tqDebug( "OBJECT %s::%s", className(), name( "unnamed" ) ); int n = 0; @@ -2852,8 +3006,9 @@ void TQObject::dumpObjectInfo() sender = senderObjects->next(); } } - if ( n == 0 ) + if ( n == 0 ) { tqDebug( "\t<None>" ); + } #endif } |