From 3f5dc49edf41359f18e7c94c28a345a9600eb44f Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 6 Dec 2012 16:48:15 -0600 Subject: Automated update from Qt3 --- src/kernel/qapplication.cpp | 124 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 110 insertions(+), 14 deletions(-) (limited to 'src/kernel/qapplication.cpp') diff --git a/src/kernel/qapplication.cpp b/src/kernel/qapplication.cpp index a552c236c..5b57bd249 100644 --- a/src/kernel/qapplication.cpp +++ b/src/kernel/qapplication.cpp @@ -68,6 +68,7 @@ #if defined(QT_THREAD_SUPPORT) # include "ntqmutex.h" # include "ntqthread.h" +# include #endif // QT_THREAD_SUPPORT #include @@ -383,7 +384,25 @@ Q_EXPORT TQt::HANDLE tqt_get_application_thread_id() } #endif // QT_THREAD_SUPPORT +#ifndef QT_THREAD_SUPPORT TQEventLoop *TQApplication::eventloop = 0; // application event loop +#endif + +#ifdef QT_THREAD_SUPPORT +TQEventLoop* TQApplication::currentEventLoop() { + TQThread* thread = TQThread::currentThreadObject(); + if (thread) { + if (thread->d) { + return thread->d->eventLoop; + } + } + return NULL; +} +#else +TQEventLoop* TQApplication::currentEventLoop() { + return TQApplication::eventloop; +} +#endif #ifndef QT_NO_ACCEL extern bool tqt_dispatchAccelEvent( TQWidget*, TQKeyEvent* ); // def in qaccel.cpp @@ -516,6 +535,41 @@ TQClipboard *tqt_clipboard = 0; // global clipboard object #endif TQWidgetList * tqt_modal_stack=0; // stack of modal widgets +#ifdef QT_THREAD_SUPPORT +// thread wrapper for the main() thread +class TQCoreApplicationThread : public TQThread +{ +public: + inline TQCoreApplicationThread() + { + TQThreadInstance::setCurrentThread(this); + + // thread should be running and not finished for the lifetime + // of the application (even if QCoreApplication goes away) + d->running = true; + d->finished = false; + d->eventLoop = NULL; + } + inline ~TQCoreApplicationThread() + { + // avoid warning from TQThread + d->running = false; + } +private: + inline void run() + { + // this function should never be called, it is implemented + // only so that we can instantiate the object + tqFatal("TQCoreApplicationThread: internal error"); + } +}; + +static TQCoreApplicationThread tqt_main_thread; +static TQThread *mainThread() { return &tqt_main_thread; } +#else +static TQThread* mainThread() { return TQThread::currentThread(); } +#endif + // Definitions for posted events struct TQPostEvent { TQPostEvent( TQObject *r, TQEvent *e ): receiver( r ), event( e ) {} @@ -818,8 +872,8 @@ void TQApplication::construct( int &argc, char **argv, Type type ) initialize( argc, argv ); if ( tqt_is_gui_used ) tqt_maxWindowRect = desktop()->rect(); - if ( eventloop ) - eventloop->appStartingUp(); + if ( currentEventLoop() ) + currentEventLoop()->appStartingUp(); } /*! @@ -874,8 +928,8 @@ TQApplication::TQApplication( Display* dpy, HANDLE visual, HANDLE colormap ) if ( tqt_is_gui_used ) tqt_maxWindowRect = desktop()->rect(); - if ( eventloop ) - eventloop->appStartingUp(); + if ( currentEventLoop() ) + currentEventLoop()->appStartingUp(); } /*! @@ -916,13 +970,26 @@ TQApplication::TQApplication(Display *dpy, int argc, char **argv, if ( tqt_is_gui_used ) tqt_maxWindowRect = desktop()->rect(); - if ( eventloop ) - eventloop->appStartingUp(); + if ( currentEventLoop() ) + currentEventLoop()->appStartingUp(); } #endif // Q_WS_X11 +#ifdef QT_THREAD_SUPPORT +TQThread* TQApplication::guiThread() { + return mainThread(); +} + +bool TQApplication::isGuiThread() { + return (TQThread::currentThreadObject() == guiThread()); +} +#else +bool TQApplication::isGuiThread() { + return true; +} +#endif void TQApplication::init_precmdline() { @@ -1030,8 +1097,8 @@ TQApplication::~TQApplication() } #endif - if ( eventloop ) - eventloop->appClosingDown(); + if ( currentEventLoop() ) + currentEventLoop()->appClosingDown(); if ( postRList ) { TQVFuncList::Iterator it = postRList->begin(); while ( it != postRList->end() ) { // call post routines @@ -2698,8 +2765,20 @@ bool TQApplication::internalNotify( TQObject *receiver, TQEvent * e) } - if (!handled) + if (!handled) { +#if defined(QT_THREAD_SUPPORT) + bool locked = TQApplication::tqt_mutex->locked(); + if (locked) { + TQApplication::tqt_mutex->unlock(); + } +#endif consumed = receiver->event( e ); +#if defined(QT_THREAD_SUPPORT) + if (locked) { + TQApplication::tqt_mutex->lock(); + } +#endif + } e->spont = FALSE; return consumed; } @@ -2793,9 +2872,10 @@ void TQApplication::processOneEvent() */ TQEventLoop *TQApplication::eventLoop() { - if ( !eventloop && !is_app_closing ) + if ( !currentEventLoop() && !is_app_closing ) { (void) new TQEventLoop( tqApp, "default event loop" ); - return eventloop; + } + return currentEventLoop(); } @@ -3263,8 +3343,23 @@ void TQApplication::postEvent( TQObject *receiver, TQEvent *event ) l->append( pe ); globalPostedEvents->append( pe ); - if (eventloop) - eventloop->wakeUp(); +#ifdef QT_THREAD_SUPPORT + if ( event->type() == TQEvent::MetaCall ) { + // Wake up the receiver thread event loop + TQThread* thread = receiver->contextThreadObject(); + if (thread) { + if (thread->d) { + if (thread->d->eventLoop) { + thread->d->eventLoop->wakeUp(); + } + } + } + return; + } +#endif + + if (currentEventLoop()) + currentEventLoop()->wakeUp(); } @@ -3326,7 +3421,8 @@ void TQApplication::sendPostedEvents( TQObject *receiver, int event_type ) && ( 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 + || event_type == pe->event->type() ) // we send THAT type + && ( (!pe->receiver) || (pe->receiver->contextThreadObject() == TQThread::currentThreadObject()) ) ) { // only send if active thread is receiver object owning thread // first, we diddle the event so that we can deliver // it, and that noone will try to touch it later. pe->event->posted = FALSE; -- cgit v1.2.3 From f1f1d2243299cd1115002e5b5047e9c3a0a73134 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 6 Dec 2012 18:30:05 -0600 Subject: Automated update from Qt3 --- src/kernel/qapplication.cpp | 9 ++- src/kernel/qeventloop_unix.cpp | 2 + src/kernel/qeventloop_x11.cpp | 6 +- tutorial/t15/main.cpp | 173 +++++++++++++++++++++++++++++++++++++++++ tutorial/t15/main.h | 45 +++++++++++ tutorial/t15/t15.pro | 5 ++ tutorial/tutorial.pro | 2 +- 7 files changed, 237 insertions(+), 5 deletions(-) create mode 100644 tutorial/t15/main.cpp create mode 100644 tutorial/t15/main.h create mode 100644 tutorial/t15/t15.pro (limited to 'src/kernel/qapplication.cpp') diff --git a/src/kernel/qapplication.cpp b/src/kernel/qapplication.cpp index 5b57bd249..6fade0228 100644 --- a/src/kernel/qapplication.cpp +++ b/src/kernel/qapplication.cpp @@ -2767,7 +2767,10 @@ bool TQApplication::internalNotify( TQObject *receiver, TQEvent * e) if (!handled) { #if defined(QT_THREAD_SUPPORT) - bool locked = TQApplication::tqt_mutex->locked(); + bool locked = false; + if (TQApplication::tqt_mutex) { + locked = TQApplication::tqt_mutex->locked(); + } if (locked) { TQApplication::tqt_mutex->unlock(); } @@ -2775,7 +2778,9 @@ bool TQApplication::internalNotify( TQObject *receiver, TQEvent * e) consumed = receiver->event( e ); #if defined(QT_THREAD_SUPPORT) if (locked) { - TQApplication::tqt_mutex->lock(); + if (TQApplication::tqt_mutex) { + TQApplication::tqt_mutex->lock(); + } } #endif } diff --git a/src/kernel/qeventloop_unix.cpp b/src/kernel/qeventloop_unix.cpp index ccdbb4b8d..1c391f413 100644 --- a/src/kernel/qeventloop_unix.cpp +++ b/src/kernel/qeventloop_unix.cpp @@ -562,6 +562,8 @@ int TQEventLoop::activateTimers() n_act++; TQTimerEvent e( t->id ); TQApplication::sendEvent( t->obj, &e ); // send event + if ( !timerList ) // sendEvent allows other threads to execute, therefore we must check for list existence when it returns! + return 0; if ( timerList->findRef( begin ) == -1 ) begin = 0; } diff --git a/src/kernel/qeventloop_x11.cpp b/src/kernel/qeventloop_x11.cpp index a2d8590f6..a733c115d 100644 --- a/src/kernel/qeventloop_x11.cpp +++ b/src/kernel/qeventloop_x11.cpp @@ -284,7 +284,8 @@ bool TQEventLoop::processEvents( ProcessEventsFlags flags ) // unlock the GUI mutex and select. when we return from this function, there is // something for us to do #if defined(QT_THREAD_SUPPORT) - locker.mutex()->unlock(); + if ( locker.mutex() ) locker.mutex()->unlock(); + else return false; #endif int nsel; @@ -298,7 +299,8 @@ bool TQEventLoop::processEvents( ProcessEventsFlags flags ) // relock the GUI mutex before processing any pending events #if defined(QT_THREAD_SUPPORT) - locker.mutex()->lock(); + if ( locker.mutex() ) locker.mutex()->lock(); + else return false; #endif // we are awake, broadcast it diff --git a/tutorial/t15/main.cpp b/tutorial/t15/main.cpp new file mode 100644 index 000000000..b20262bff --- /dev/null +++ b/tutorial/t15/main.cpp @@ -0,0 +1,173 @@ +/**************************************************************** +** +** TQt threading tutorial +** (c) 2012 Timothy Pearson +** +** This tutorial is released into the Public Domain and +** can therefore be modified and/or used for any purpose +** +****************************************************************/ + +#include "main.h" + +#include + +#include +#include + +void WorkerObject::run() +{ + tqDebug( "[%s] thread: %p event loop: %p", threadFriendlyName.ascii(), TQThread::currentThreadObject(), TQApplication::eventLoop() ); + + TQEventLoop* eventLoop = TQApplication::eventLoop(); + if (!eventLoop) return; + + TQTimer *t = new TQTimer(this); + connect( t, SIGNAL(timeout()), SLOT(timerHandler()) ); + t->start( 1000, FALSE ); + + for( int count = 0; count < 5; count++ ) { + sleep( 1 ); + tqDebug( "[%s] Ping!", threadFriendlyName.ascii() ); + displayMessage("Hi", "There!"); + eventLoop->processEvents(TQEventLoop::AllEvents); + } + + eventLoop->exit(0); +} + +void WorkerObject::timerHandler() +{ + tqDebug( "[%s] Timer fired!", threadFriendlyName.ascii() ); +} + +void MainObject::emitMessage(TQString str1, TQString str2) +{ + tqDebug( "%s", ("[MainObject] emitMessage: " + str1 + " " + str2).ascii() ); +} + +void MainObject::buttonClicked() +{ + tqDebug( "[MainObject] Button clicked!" ); + + TQEventLoop* eventLoop = TQApplication::eventLoop(); + if (!eventLoop) return; + eventLoop->exit(0); +} + +#define SET_UP_WORKER(x, y, z) \ + WorkerObject x; \ + x.threadFriendlyName = y; \ + x.moveToThread(&z); \ + TQObject::connect(&x, SIGNAL(displayMessage(TQString,TQString)), &mainobject, SLOT(emitMessage(TQString,TQString))); \ + TQTimer::singleShot(0, &x, SLOT(run())); + +int main( int argc, char **argv ) +{ + TQApplication a( argc, argv ); + + tqDebug( "[MainObject] thread: %p event loop: %p", TQThread::currentThreadObject(), TQApplication::eventLoop() ); + + TQPushButton hello( "Exit", 0 ); + hello.resize( 100, 30 ); + + MainObject mainobject; + + TQEventLoopThread workerthread0; + TQEventLoopThread workerthread1; + TQEventLoopThread workerthread2; + TQEventLoopThread workerthread3; + TQEventLoopThread workerthread4; + TQEventLoopThread workerthread5; + TQEventLoopThread workerthread6; + TQEventLoopThread workerthread7; + TQEventLoopThread workerthread8; + TQEventLoopThread workerthread9; + + TQEventLoopThread workerthread10; + TQEventLoopThread workerthread11; + TQEventLoopThread workerthread12; + TQEventLoopThread workerthread13; + TQEventLoopThread workerthread14; + TQEventLoopThread workerthread15; + TQEventLoopThread workerthread16; + TQEventLoopThread workerthread17; + TQEventLoopThread workerthread18; + TQEventLoopThread workerthread19; + + SET_UP_WORKER(workerobject0, "WorkerObject0", workerthread0) + SET_UP_WORKER(workerobject1, "WorkerObject1", workerthread1) + SET_UP_WORKER(workerobject2, "WorkerObject2", workerthread2) + SET_UP_WORKER(workerobject3, "WorkerObject3", workerthread3) + SET_UP_WORKER(workerobject4, "WorkerObject4", workerthread4) + SET_UP_WORKER(workerobject5, "WorkerObject5", workerthread5) + SET_UP_WORKER(workerobject6, "WorkerObject6", workerthread6) + SET_UP_WORKER(workerobject7, "WorkerObject7", workerthread7) + SET_UP_WORKER(workerobject8, "WorkerObject8", workerthread8) + SET_UP_WORKER(workerobject9, "WorkerObject9", workerthread9) + + SET_UP_WORKER(workerobject10, "WorkerObjec10", workerthread10) + SET_UP_WORKER(workerobject11, "WorkerObjec11", workerthread11) + SET_UP_WORKER(workerobject12, "WorkerObjec12", workerthread12) + SET_UP_WORKER(workerobject13, "WorkerObjec13", workerthread13) + SET_UP_WORKER(workerobject14, "WorkerObjec14", workerthread14) + SET_UP_WORKER(workerobject15, "WorkerObjec15", workerthread15) + SET_UP_WORKER(workerobject16, "WorkerObjec16", workerthread16) + SET_UP_WORKER(workerobject17, "WorkerObjec17", workerthread17) + SET_UP_WORKER(workerobject18, "WorkerObjec18", workerthread18) + SET_UP_WORKER(workerobject19, "WorkerObjec19", workerthread19) + + workerthread0.start(); + workerthread1.start(); + workerthread2.start(); + workerthread3.start(); + workerthread4.start(); + workerthread5.start(); + workerthread6.start(); + workerthread7.start(); + workerthread8.start(); + workerthread9.start(); + + workerthread10.start(); + workerthread11.start(); + workerthread12.start(); + workerthread13.start(); + workerthread14.start(); + workerthread15.start(); + workerthread16.start(); + workerthread17.start(); + workerthread18.start(); + workerthread19.start(); + + a.setMainWidget( &hello ); + TQObject::connect(&hello, SIGNAL(clicked()), &mainobject, SLOT(buttonClicked())); + hello.show(); + a.exec(); + hello.hide(); + + tqDebug( "[MainObject] Waiting for thread completion..." ); + + workerthread0.wait(); + workerthread1.wait(); + workerthread2.wait(); + workerthread3.wait(); + workerthread4.wait(); + workerthread5.wait(); + workerthread6.wait(); + workerthread7.wait(); + workerthread8.wait(); + workerthread9.wait(); + + workerthread10.wait(); + workerthread11.wait(); + workerthread12.wait(); + workerthread13.wait(); + workerthread14.wait(); + workerthread15.wait(); + workerthread16.wait(); + workerthread17.wait(); + workerthread18.wait(); + workerthread19.wait(); + + tqDebug( "[MainObject] Finished!" ); +} diff --git a/tutorial/t15/main.h b/tutorial/t15/main.h new file mode 100644 index 000000000..6cb8ee8ea --- /dev/null +++ b/tutorial/t15/main.h @@ -0,0 +1,45 @@ +/**************************************************************** +** +** TQt threading tutorial +** (c) 2012 Timothy Pearson +** +** This tutorial is released into the Public Domain and +** can therefore be modified and/or used for any purpose +** +****************************************************************/ + +#ifndef _MAIN_H_ +#define _MAIN_H_ + +#include +#include +#include +#include + +class MainObject; + +class WorkerObject : public TQObject +{ + TQ_OBJECT + + public slots: + void run(); + void timerHandler(); + + signals: + void displayMessage(TQString, TQString); + + public: + TQString threadFriendlyName; +}; + +class MainObject : public TQObject +{ + TQ_OBJECT + + public slots: + void emitMessage(TQString, TQString); + void buttonClicked(); +}; + +#endif // _MAIN_H_ diff --git a/tutorial/t15/t15.pro b/tutorial/t15/t15.pro new file mode 100644 index 000000000..ff0f08d93 --- /dev/null +++ b/tutorial/t15/t15.pro @@ -0,0 +1,5 @@ +TEMPLATE = app +CONFIG += qt warn_on release +HEADERS = main.h +SOURCES = main.cpp +TARGET = t15 diff --git a/tutorial/tutorial.pro b/tutorial/tutorial.pro index 32b31d7b6..90e37f780 100644 --- a/tutorial/tutorial.pro +++ b/tutorial/tutorial.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS = t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 +SUBDIRS = t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 -- cgit v1.2.3 From eb47d241d0212278f54d6f0defdd0ee4d0e4cf63 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 7 Dec 2012 15:02:42 -0600 Subject: Automated update from Qt3 --- configure | 3 ++ src/kernel/qapplication.cpp | 17 +++++---- src/kernel/qeventloop_unix_glib.cpp | 18 ++++----- src/kernel/qeventloop_x11_glib.cpp | 74 ++++++++++++++++++++----------------- src/tools/ntqmutex.h | 3 ++ src/tools/qmutex_p.h | 1 + src/tools/qmutex_unix.cpp | 28 ++++++++++++++ 7 files changed, 94 insertions(+), 50 deletions(-) (limited to 'src/kernel/qapplication.cpp') diff --git a/configure b/configure index b3aeebe51..469b920d8 100755 --- a/configure +++ b/configure @@ -734,6 +734,9 @@ while [ "$#" -gt 0 ]; do glibmainloop) if [ "$VAL" = "yes" ] || [ "$VAL" = "no" ]; then CFG_GLIBMAINLOOP="$VAL" + if [ "$VAL" = "yes" ]; then + echo "WARNING: glib main loop support is ***incomplete*** and will cause problems with threaded applications and/or those using non-standard event loops!" + fi else UNKNOWN_OPT=yes fi diff --git a/src/kernel/qapplication.cpp b/src/kernel/qapplication.cpp index 6fade0228..7aefd35b8 100644 --- a/src/kernel/qapplication.cpp +++ b/src/kernel/qapplication.cpp @@ -2767,18 +2767,21 @@ bool TQApplication::internalNotify( TQObject *receiver, TQEvent * e) if (!handled) { #if defined(QT_THREAD_SUPPORT) - bool locked = false; + int locklevel = 0; + int llcount; if (TQApplication::tqt_mutex) { - locked = TQApplication::tqt_mutex->locked(); - } - if (locked) { - TQApplication::tqt_mutex->unlock(); + TQApplication::tqt_mutex->lock(); // 1 of 2 + locklevel = tqt_mutex->level() - 1; + for (llcount=0; llcountunlock(); + } + TQApplication::tqt_mutex->unlock(); // 2 of 2 } #endif consumed = receiver->event( e ); #if defined(QT_THREAD_SUPPORT) - if (locked) { - if (TQApplication::tqt_mutex) { + if (TQApplication::tqt_mutex) { + for (llcount=0; llcountlock(); } } diff --git a/src/kernel/qeventloop_unix_glib.cpp b/src/kernel/qeventloop_unix_glib.cpp index 9f89332e0..7f1035fdf 100644 --- a/src/kernel/qeventloop_unix_glib.cpp +++ b/src/kernel/qeventloop_unix_glib.cpp @@ -370,9 +370,9 @@ void TQEventLoop::registerSocketNotifier( TQSocketNotifier *notifier ) return; } - #ifdef DEBUG_QT_GLIBMAINLOOP - printf("register socket notifier %d\n", sockfd); - #endif +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("register socket notifier %d\n", sockfd); +#endif TQPtrList *list = &d->sn_list; TQSockNotGPollFD *sn; @@ -425,9 +425,9 @@ void TQEventLoop::unregisterSocketNotifier( TQSocketNotifier *notifier ) return; } - #ifdef DEBUG_QT_GLIBMAINLOOP - printf("unregister socket notifier %d\n", sockfd); - #endif +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("unregister socket notifier %d\n", sockfd); +#endif TQPtrList *list = &d->sn_list; TQSockNotGPollFD *sn; @@ -458,9 +458,9 @@ void TQEventLoop::setSocketNotifierPending( TQSocketNotifier *notifier ) return; } - #ifdef DEBUG_QT_GLIBMAINLOOP - printf("set socket notifier pending %d\n", sockfd); - #endif +#ifdef DEBUG_QT_GLIBMAINLOOP + printf("set socket notifier pending %d\n", sockfd); +#endif TQPtrList *list = &d->sn_list; TQSockNotGPollFD *sn; diff --git a/src/kernel/qeventloop_x11_glib.cpp b/src/kernel/qeventloop_x11_glib.cpp index bb702b821..1e457b51f 100644 --- a/src/kernel/qeventloop_x11_glib.cpp +++ b/src/kernel/qeventloop_x11_glib.cpp @@ -54,6 +54,8 @@ #include +// #define DEBUG_QT_GLIBMAINLOOP 1 + // TQt-GSource Structure and Callbacks typedef struct { @@ -249,7 +251,7 @@ bool TQEventLoop::processEvents( ProcessEventsFlags flags ) d->pev_flags = flags; - rval = g_main_context_iteration(NULL, flags & WaitForMore ? TRUE : FALSE); + rval = g_main_context_iteration(NULL, flags & WaitForMore ? TRUE : FALSE); d->pev_flags = save_flags; @@ -288,38 +290,38 @@ bool TQEventLoop::processX11Events() XNextEvent( TQPaintDevice::x11AppDisplay(), &event ); if ( flags & ExcludeUserInput ) { - switch ( event.type ) { - case ButtonPress: - case ButtonRelease: - case MotionNotify: - case XKeyPress: - case XKeyRelease: - case EnterNotify: - case LeaveNotify: - continue; - - case ClientMessage: - { - // from qapplication_x11.cpp - extern Atom tqt_wm_protocols; - extern Atom tqt_wm_take_focus; - extern Atom qt_qt_scrolldone; - - // only keep the wm_take_focus and - // qt_qt_scrolldone protocols, discard all - // other client messages - if ( event.xclient.format != 32 ) + switch ( event.type ) { + case ButtonPress: + case ButtonRelease: + case MotionNotify: + case XKeyPress: + case XKeyRelease: + case EnterNotify: + case LeaveNotify: continue; - - if ( event.xclient.message_type == tqt_wm_protocols || - (Atom) event.xclient.data.l[0] == tqt_wm_take_focus ) - break; - if ( event.xclient.message_type == qt_qt_scrolldone ) - break; + + case ClientMessage: + { + // from qapplication_x11.cpp + extern Atom tqt_wm_protocols; + extern Atom tqt_wm_take_focus; + extern Atom qt_qt_scrolldone; + + // only keep the wm_take_focus and + // qt_qt_scrolldone protocols, discard all + // other client messages + if ( event.xclient.format != 32 ) + continue; + + if ( event.xclient.message_type == tqt_wm_protocols || + (Atom) event.xclient.data.l[0] == tqt_wm_take_focus ) + break; + if ( event.xclient.message_type == qt_qt_scrolldone ) + break; + } + + default: break; } - - default: break; - } } nevents++; @@ -333,7 +335,7 @@ bool TQEventLoop::processX11Events() if ( d->shortcut ) { return FALSE; } - + TQApplication::sendPostedEvents(); const uint exclude_all = ExcludeSocketNotifiers | 0x08; @@ -595,12 +597,16 @@ bool TQEventLoop::gsourceDispatch(GSource *gs) { // color approx. optimization - only on X11 qt_reset_color_avail(); +#if defined(QT_THREAD_SUPPORT) + locker.mutex()->unlock(); +#endif processX11Events(); } - + else { #if defined(QT_THREAD_SUPPORT) - locker.mutex()->unlock(); + locker.mutex()->unlock(); #endif + } if (d->singletoolkit) { return TRUE; // Eat the event diff --git a/src/tools/ntqmutex.h b/src/tools/ntqmutex.h index 2a9afb1d2..7b73514da 100644 --- a/src/tools/ntqmutex.h +++ b/src/tools/ntqmutex.h @@ -74,6 +74,9 @@ private: TQMutex( const TQMutex & ); TQMutex &operator=( const TQMutex & ); #endif + +public: + int level(); }; class Q_EXPORT TQMutexLocker diff --git a/src/tools/qmutex_p.h b/src/tools/qmutex_p.h index 7650cee8b..3e9de8e5c 100644 --- a/src/tools/qmutex_p.h +++ b/src/tools/qmutex_p.h @@ -67,6 +67,7 @@ public: virtual bool locked() = 0; virtual bool trylock() = 0; virtual int type() const = 0; + virtual int level() = 0; }; diff --git a/src/tools/qmutex_unix.cpp b/src/tools/qmutex_unix.cpp index 7d22798cc..3fff83366 100644 --- a/src/tools/qmutex_unix.cpp +++ b/src/tools/qmutex_unix.cpp @@ -85,6 +85,7 @@ public: bool locked(); bool trylock(); int type() const; + int level(); bool recursive; }; @@ -101,6 +102,7 @@ public: bool locked(); bool trylock(); int type() const; + int level(); int count; unsigned long owner; @@ -196,6 +198,11 @@ int TQRealMutexPrivate::type() const return recursive ? Q_MUTEX_RECURSIVE : Q_MUTEX_NORMAL; } +int TQRealMutexPrivate::level() +{ + return locked(); +} + #ifndef Q_RECURSIVE_MUTEX_TYPE TQRecursiveMutexPrivate::TQRecursiveMutexPrivate() @@ -329,6 +336,11 @@ int TQRecursiveMutexPrivate::type() const return Q_MUTEX_RECURSIVE; } +int TQRecursiveMutexPrivate::level() +{ + return count; +} + #endif // !Q_RECURSIVE_MUTEX_TYPE @@ -510,6 +522,22 @@ bool TQMutex::tryLock() return d->trylock(); } +/*! + Returns the current lock level of the mutex. + 0 means the mutex is unlocked + This method should only be called when the mutex has already been locked + by lock(), otherwise the lock level could change before the next line + of code is executed. + + WARNING: Non-recursive mutexes will never exceed a lock level of 1! + + \sa lock(), unlock(), locked() +*/ +int TQMutex::level() +{ + return d->level(); +} + /*! \class TQMutexLocker ntqmutex.h \brief The TQMutexLocker class simplifies locking and unlocking TQMutexes. -- cgit v1.2.3