summaryrefslogtreecommitdiffstats
path: root/src/kernel
diff options
context:
space:
mode:
authorAlexander Golubev <fatzer2@gmail.com>2024-03-10 16:39:03 +0300
committerAlexander Golubev <fatzer2@gmail.com>2024-03-10 16:39:03 +0300
commit4100c9e29f3ccb324a68ff1759ebbf1d35849a40 (patch)
tree33ca1537e3eaff6d4208a1644c013affe1df37cf /src/kernel
parentbd8bd100a41d205592a3c4d41c52617bfdeb602d (diff)
downloadtqt3-4100c9e29f3ccb324a68ff1759ebbf1d35849a40.tar.gz
tqt3-4100c9e29f3ccb324a68ff1759ebbf1d35849a40.zip
Fix compilation with -no-thread
Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/qapplication.cpp20
-rw-r--r--src/kernel/qeventloop.cpp2
-rw-r--r--src/kernel/qobject.cpp63
3 files changed, 59 insertions, 26 deletions
diff --git a/src/kernel/qapplication.cpp b/src/kernel/qapplication.cpp
index 4b2684f18..fbdb9330c 100644
--- a/src/kernel/qapplication.cpp
+++ b/src/kernel/qapplication.cpp
@@ -572,8 +572,6 @@ private:
static TQCoreApplicationThread tqt_main_thread;
static TQThread *mainThread() { return &tqt_main_thread; }
-#else
-static TQThread* mainThread() { return TQThread::currentThread(); }
#endif
// Definitions for posted events
@@ -3033,6 +3031,7 @@ int TQApplication::exec()
*/
void TQApplication::exit( int retcode )
{
+#ifdef TQT_THREAD_SUPPORT
TQThread* thread = tqApp->guiThread();
if (thread) {
if (thread->d) {
@@ -3041,6 +3040,9 @@ void TQApplication::exit( int retcode )
}
}
}
+#else
+ tqApp->eventLoop()->exit( retcode );
+#endif // TQT_THREAD_SUPPORT
}
/*!
@@ -3540,12 +3542,18 @@ void TQApplication::sendPostedEvents( TQObject *receiver, int event_type )
TQPostEvent *pe;
while ( (pe=it.current()) != 0 ) {
++it;
+ Q_ASSERT(pe->receiver);
if ( pe->event // hasn't been sent yet
&& ( receiver == 0 // we send to all receivers
|| receiver == pe->receiver ) // we send to THAT receiver
&& ( event_type == 0 // we send all types
|| event_type == pe->event->type() ) // we send THAT type
- && ( (!pe->receiver) || ((pe->receiver) && (!pe->receiver->wasDeleted) && (pe->receiver->contextThreadObject() == TQThread::currentThreadObject())) ) ) { // only send if active thread is receiver object owning thread
+ && ( !pe->receiver->wasDeleted ) // don't send if receiver was deleted
+#ifdef TQT_THREAD_SUPPORT
+ // only send if active thread is receiver object owning thread
+ && ( pe->receiver->contextThreadObject() == TQThread::currentThreadObject() )
+#endif
+ ) {
// first, we diddle the event so that we can deliver
// it, and that noone will try to touch it later.
pe->event->posted = FALSE;
@@ -3796,8 +3804,8 @@ void TQApplication::removePostedEvent( TQEvent * event )
}
}
-void tqThreadTerminationHandlerRecursive( TQObject* object, TQThread* originThread, TQThread* destinationThread ) {
#ifdef TQT_THREAD_SUPPORT
+static void tqThreadTerminationHandlerRecursive( TQObject* object, TQThread* originThread, TQThread* destinationThread ) {
TQThread* objectThread = object->contextThreadObject();
if (objectThread && (objectThread == originThread)) {
TQThread::CleanupType cleanupType = objectThread->cleanupType();
@@ -3822,7 +3830,6 @@ void tqThreadTerminationHandlerRecursive( TQObject* object, TQThread* originThre
for ( childObject = children.first(); childObject; childObject = children.next() ) {
tqThreadTerminationHandlerRecursive(childObject, originThread, destinationThread);
}
-#endif // TQT_THREAD_SUPPORT
}
/*!\internal
@@ -3831,15 +3838,14 @@ void tqThreadTerminationHandlerRecursive( TQObject* object, TQThread* originThre
for thread destruction.
*/
void TQApplication::threadTerminationHandler( TQThread *originThread ) {
-#ifdef TQT_THREAD_SUPPORT
TQMutexLocker locker( tqt_mutex );
TQThread* destinationThread = guiThread();
const TQObjectList* objects = TQObject::objectTrees();
for ( TQObjectListIt objectit( *objects ) ; *objectit; ++objectit ) {
tqThreadTerminationHandlerRecursive((*objectit), originThread, destinationThread);
}
-#endif // TQT_THREAD_SUPPORT
}
+#endif // TQT_THREAD_SUPPORT
/*!\internal
diff --git a/src/kernel/qeventloop.cpp b/src/kernel/qeventloop.cpp
index 2aa96de69..402894f2a 100644
--- a/src/kernel/qeventloop.cpp
+++ b/src/kernel/qeventloop.cpp
@@ -107,9 +107,11 @@ TQEventLoop::TQEventLoop( TQObject *parent, const char *name )
#if defined(QT_CHECK_STATE)
if ( TQApplication::currentEventLoop() )
tqFatal( "TQEventLoop: there must be only one event loop object per thread. \nIf this is supposed to be the main GUI event loop, construct it before TQApplication." );
+#ifdef TQT_THREAD_SUPPORT
if (!TQThread::currentThreadObject()) {
tqFatal( "TQEventLoop: this object can only be used in threads constructed via TQThread." );
}
+#endif // TQT_THREAD_SUPPORT
#endif // QT_CHECK_STATE
d = new TQEventLoopPrivate;
diff --git a/src/kernel/qobject.cpp b/src/kernel/qobject.cpp
index e931cdbe7..3ab2d9b97 100644
--- a/src/kernel/qobject.cpp
+++ b/src/kernel/qobject.cpp
@@ -97,8 +97,10 @@ class TQObjectPrivate {
public:
#ifndef TQT_NO_USERDATA
TQObjectPrivate( uint s ) : TQPtrVector<TQObjectUserData>(s) {
+#ifdef TQT_THREAD_SUPPORT
ownThread = NULL;
disableThreadPostedEvents = false;
+#endif
setAutoDelete( TRUE );
controlElementData = NULL;
controlElementDataPrivate = NULL;
@@ -108,10 +110,12 @@ public:
delete controlElementDataPrivate;
}
#endif
+#ifdef TQT_THREAD_SUPPORT
TQThread* ownThread;
TQMutex* senderObjectListMutex;
TQMutex* childObjectListMutex;
bool disableThreadPostedEvents;
+#endif
TQStyleControlElementData* controlElementData;
TQStyleControlElementDataPrivate* controlElementDataPrivate;
};
@@ -240,7 +244,7 @@ void TQObject::disableThreadPostedEvents(bool disable) {
d->disableThreadPostedEvents = disable;
}
-#endif
+#endif // defined(TQT_THREAD_SUPPORT)
class TQSenderObjectList : public TQObjectList, public TQShared
{
@@ -250,15 +254,21 @@ class TQSenderObjectList : public TQObjectList, public TQShared
public:
TQObject *currentSender;
+#ifdef TQT_THREAD_SUPPORT
TQMutex *listMutex;
+#endif
};
TQSenderObjectList::TQSenderObjectList() : currentSender( 0 ) {
+#ifdef TQT_THREAD_SUPPORT
listMutex = new TQMutex( TRUE );
+#endif
}
TQSenderObjectList::~TQSenderObjectList() {
+#ifdef TQT_THREAD_SUPPORT
delete listMutex;
+#endif
}
class TQ_EXPORT TQMetaCallEvent : public TQEvent
@@ -667,10 +677,11 @@ TQObject::TQObject( TQObject *parent, const char *name )
d = new TQObjectPrivate(0);
}
+#ifdef TQT_THREAD_SUPPORT
d->ownThread = TQThread::currentThreadObject();
d->senderObjectListMutex = new TQMutex( TRUE );
d->childObjectListMutex = new TQMutex( TRUE );
-
+#endif
if ( !metaObj ) { // will create object dict
(void) staticMetaObject();
}
@@ -1075,7 +1086,11 @@ bool TQObject::event( TQEvent *e )
{
TQMetaCallEvent* metaEvent = dynamic_cast<TQMetaCallEvent*>(e);
if (metaEvent) {
- if ((d->disableThreadPostedEvents) || (d->ownThread == TQThread::currentThreadObject())) {
+#ifdef TQT_THREAD_SUPPORT
+ if ((d->disableThreadPostedEvents)
+ || (d->ownThread == TQThread::currentThreadObject()))
+#endif // TQT_THREAD_SUPPORT
+ {
TQSenderObjectList* sol;
TQObject* oldSender = 0;
sol = senderObjects;
@@ -1103,7 +1118,9 @@ bool TQObject::event( TQEvent *e )
if (sol ) {
sol->currentSender = oldSender;
if ( sol->deref() ) {
+#ifdef TQT_THREAD_SUPPORT
sol->listMutex->unlock();
+#endif // TQT_THREAD_SUPPORT
delete sol;
sol = NULL;
}
@@ -1112,9 +1129,11 @@ bool TQObject::event( TQEvent *e )
if (sol) sol->listMutex->unlock();
#endif // TQT_THREAD_SUPPORT
}
+#ifdef TQT_THREAD_SUPPORT
else {
tqWarning("TQObject: Ignoring metacall event from non-owning thread");
}
+#endif // TQT_THREAD_SUPPORT
destroyDeepCopiedTQUObjectArray(metaEvent->data());
}
}
@@ -2761,8 +2780,10 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o )
}
#endif
+#ifdef TQT_THREAD_SUPPORT
// NOTE currentThread could be NULL if the current thread was not started using the TQThread API
const TQThread *currentThread = TQThread::currentThreadObject();
+#endif // TQT_THREAD_SUPPORT
TQObject *object;
TQSenderObjectList* sol;
@@ -2781,17 +2802,16 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o )
sol->currentSender = this;
}
if ( c->memberType() == TQ_SIGNAL_CODE ) {
+#if !defined(TQT_THREAD_SUPPORT)
+ object->tqt_emit( c->member(), o );
+#else // defined(TQT_THREAD_SUPPORT)
if ((d->disableThreadPostedEvents) ||
(object->d->disableThreadPostedEvents) ||
(currentThread && currentThread->threadPostedEventsDisabled()) ||
(currentThread && object->d->ownThread == currentThread)) {
-#ifdef TQT_THREAD_SUPPORT
sol->listMutex->unlock();
-#endif // TQT_THREAD_SUPPORT
object->tqt_emit( c->member(), o );
-#ifdef TQT_THREAD_SUPPORT
sol->listMutex->lock();
-#endif // TQT_THREAD_SUPPORT
}
else {
if (object->d->ownThread && !object->d->ownThread->finished()) {
@@ -2801,19 +2821,19 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o )
TQApplication::postEvent(object, new TQMetaCallEvent(c->member(), this, deepCopyTQUObjectArray(o), TQMetaCallEvent::MetaCallEmit));
}
}
+#endif // !defined(TQT_THREAD_SUPPORT)
}
else {
+#if !defined(TQT_THREAD_SUPPORT)
+ object->tqt_invoke( c->member(), o );
+#else // defined(TQT_THREAD_SUPPORT)
if ((d->disableThreadPostedEvents) ||
(object->d->disableThreadPostedEvents) ||
(currentThread && currentThread->threadPostedEventsDisabled()) ||
(currentThread && object->d->ownThread == currentThread)) {
-#ifdef TQT_THREAD_SUPPORT
sol->listMutex->unlock();
-#endif // TQT_THREAD_SUPPORT
object->tqt_invoke( c->member(), o );
-#ifdef TQT_THREAD_SUPPORT
sol->listMutex->lock();
-#endif // TQT_THREAD_SUPPORT
}
else {
if (object->d->ownThread && !object->d->ownThread->finished()) {
@@ -2823,11 +2843,14 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o )
TQApplication::postEvent(object, new TQMetaCallEvent(c->member(), this, deepCopyTQUObjectArray(o), TQMetaCallEvent::MetaCallInvoke));
}
}
+#endif // !defined(TQT_THREAD_SUPPORT)
}
if ( sol ) {
sol->currentSender = oldSender;
if ( sol->deref() ) {
+#ifdef TQT_THREAD_SUPPORT
sol->listMutex->unlock();
+#endif // TQT_THREAD_SUPPORT
delete sol;
sol = NULL;
}
@@ -2854,17 +2877,16 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o )
sol->currentSender = this;
}
if ( c->memberType() == TQ_SIGNAL_CODE ) {
+#if !defined(TQT_THREAD_SUPPORT)
+ object->tqt_emit( c->member(), o );
+#else // defined(TQT_THREAD_SUPPORT)
if ((d->disableThreadPostedEvents) ||
(object->d->disableThreadPostedEvents) ||
(currentThread && currentThread->threadPostedEventsDisabled()) ||
(currentThread && object->d->ownThread == currentThread)) {
-#ifdef TQT_THREAD_SUPPORT
sol->listMutex->unlock();
-#endif // TQT_THREAD_SUPPORT
object->tqt_emit( c->member(), o );
-#ifdef TQT_THREAD_SUPPORT
sol->listMutex->lock();
-#endif // TQT_THREAD_SUPPORT
}
else {
if (object->d->ownThread && !object->d->ownThread->finished()) {
@@ -2874,19 +2896,19 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o )
TQApplication::postEvent(object, new TQMetaCallEvent(c->member(), this, deepCopyTQUObjectArray(o), TQMetaCallEvent::MetaCallEmit));
}
}
+#endif // !defined(TQT_THREAD_SUPPORT)
}
else {
+#if !defined(TQT_THREAD_SUPPORT)
+ object->tqt_invoke( c->member(), o );
+#else // defined(TQT_THREAD_SUPPORT)
if ((d->disableThreadPostedEvents) ||
(object->d->disableThreadPostedEvents) ||
(currentThread && currentThread->threadPostedEventsDisabled()) ||
(currentThread && object->d->ownThread == currentThread)) {
-#ifdef TQT_THREAD_SUPPORT
sol->listMutex->unlock();
-#endif // TQT_THREAD_SUPPORT
object->tqt_invoke( c->member(), o );
-#ifdef TQT_THREAD_SUPPORT
sol->listMutex->lock();
-#endif // TQT_THREAD_SUPPORT
}
else {
if (object->d->ownThread && !object->d->ownThread->finished()) {
@@ -2896,11 +2918,14 @@ void TQObject::activate_signal( TQConnectionList *clist, TQUObject *o )
TQApplication::postEvent(object, new TQMetaCallEvent(c->member(), this, deepCopyTQUObjectArray(o), TQMetaCallEvent::MetaCallInvoke));
}
}
+#endif // !defined(TQT_THREAD_SUPPORT)
}
if (sol ) {
sol->currentSender = oldSender;
if ( sol->deref() ) {
+#ifdef TQT_THREAD_SUPPORT
sol->listMutex->unlock();
+#endif // TQT_THREAD_SUPPORT
delete sol;
sol = NULL;
}