diff options
Diffstat (limited to 'src/kernel/qeventloop_unix_glib.cpp')
| -rw-r--r-- | src/kernel/qeventloop_unix_glib.cpp | 74 |
1 files changed, 34 insertions, 40 deletions
diff --git a/src/kernel/qeventloop_unix_glib.cpp b/src/kernel/qeventloop_unix_glib.cpp index f84339651..e4490f388 100644 --- a/src/kernel/qeventloop_unix_glib.cpp +++ b/src/kernel/qeventloop_unix_glib.cpp @@ -45,21 +45,18 @@ #include "ntqapplication.h" #include "ntqbitarray.h" #include "ntqmutex.h" - -#if defined(TQT_THREAD_SUPPORT) - #include "ntqthread.h" -#endif +#include "ntqthread.h" #include <stdlib.h> #include <sys/types.h> #include <glib.h> -#ifdef TQT_THREAD_SUPPORT +#ifndef TQT_NO_THREAD #ifdef QT_USE_GLIBMAINLOOP extern TQMutex *tqt_timerListMutex; #endif // QT_USE_GLIBMAINLOOP -#endif // TQT_THREAD_SUPPORT +#endif // TQT_NO_THREAD /***************************************************************************** Timer handling; UNIX has no application timer support so we'll have to @@ -186,7 +183,7 @@ static int allocTimerId() // find avail timer identifier static void insertTimer( const TimerInfo *ti ) // insert timer info into list { -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD tqt_timerListMutex->lock(); #endif TimerInfo *t = timerList->first(); @@ -209,7 +206,7 @@ static void insertTimer( const TimerInfo *ti ) // insert timer info into list tqDebug( "TQObject: %d timers now exist for object %s::%s", dangerCount, ti->obj->className(), ti->obj->name() ); } #endif -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD tqt_timerListMutex->unlock(); #endif } @@ -235,7 +232,7 @@ static inline void getTime( timeval &t ) // get time of day static void repairTimer( const timeval &time ) // repair broken timer { -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD tqt_timerListMutex->lock(); #endif timeval diff = watchtime - time; @@ -244,7 +241,7 @@ static void repairTimer( const timeval &time ) // repair broken timer t->timeout = t->timeout - diff; t = timerList->next(); } -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD tqt_timerListMutex->unlock(); #endif } @@ -262,7 +259,7 @@ static void repairTimer( const timeval &time ) // repair broken timer timeval *qt_wait_timer() { -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD tqt_timerListMutex->lock(); #endif static timeval tm; @@ -288,19 +285,19 @@ timeval *qt_wait_timer() if ( qt_wait_timer_max && *qt_wait_timer_max < tm ) { tm = *qt_wait_timer_max; } -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD tqt_timerListMutex->unlock(); #endif return &tm; } if ( qt_wait_timer_max ) { tm = *qt_wait_timer_max; -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD tqt_timerListMutex->unlock(); #endif return &tm; } -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD tqt_timerListMutex->unlock(); #endif return 0; // no timers @@ -316,7 +313,7 @@ static void initTimers() // initialize timers timerBitVec->clearBit( i ); } timerList = new TimerList; -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD tqt_timerListMutex = new TQMutex(true); #endif TQ_CHECK_PTR( timerList ); @@ -336,18 +333,18 @@ void cleanupTimers() // Main timer functions for starting and killing timers int qStartTimer( int interval, TQObject *obj ) { -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD if (tqt_timerListMutex) tqt_timerListMutex->lock(); #endif if ( !timerList ) { // initialize timer data initTimers(); -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD if (tqt_timerListMutex) tqt_timerListMutex->lock(); #endif } int id = allocTimerId(); // get free timer id if ( (id <= 0) || (id > (int)timerBitVec->size()) || (!obj) ) { // cannot create timer -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD if (tqt_timerListMutex) tqt_timerListMutex->unlock(); #endif return 0; @@ -363,7 +360,7 @@ int qStartTimer( int interval, TQObject *obj ) t->timeout = currentTime + t->interval; t->obj = obj; insertTimer( t ); // put timer in list -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD if (tqt_timerListMutex) tqt_timerListMutex->unlock(); #endif return id; @@ -371,12 +368,12 @@ int qStartTimer( int interval, TQObject *obj ) bool qKillTimer( int id ) { -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD if (tqt_timerListMutex) tqt_timerListMutex->lock(); #endif TimerInfo *t; if ( (!timerList) || (id <= 0) || (id > (int)timerBitVec->size()) || (!timerBitVec->testBit( id-1 )) ) { -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD if (tqt_timerListMutex) tqt_timerListMutex->unlock(); #endif return FALSE; // not init'd or invalid timer @@ -389,13 +386,13 @@ bool qKillTimer( int id ) bool ret; timerBitVec->clearBit( id-1 ); // set timer inactive ret = timerList->remove(); -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD if (tqt_timerListMutex) tqt_timerListMutex->unlock(); #endif return ret; } else { // id not found -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD if (tqt_timerListMutex) tqt_timerListMutex->unlock(); #endif return FALSE; @@ -404,12 +401,12 @@ bool qKillTimer( int id ) bool qKillTimer( TQObject *obj ) { -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD if (tqt_timerListMutex) tqt_timerListMutex->lock(); #endif TimerInfo *t; if ( !timerList ) { // not initialized -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD if (tqt_timerListMutex) tqt_timerListMutex->unlock(); #endif return FALSE; @@ -425,7 +422,7 @@ bool qKillTimer( TQObject *obj ) t = timerList->next(); } } -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD if (tqt_timerListMutex) tqt_timerListMutex->unlock(); #endif return TRUE; @@ -632,11 +629,11 @@ int TQEventLoop::timeToWait() const int TQEventLoop::activateTimers() { -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD if (tqt_timerListMutex) tqt_timerListMutex->lock(); #endif if ( !timerList || !timerList->count() ) { // no timers -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD if (tqt_timerListMutex) tqt_timerListMutex->unlock(); #endif return 0; @@ -682,11 +679,10 @@ int TQEventLoop::activateTimers() if ( t->interval.tv_usec > 0 || t->interval.tv_sec > 0 ) { n_act++; } -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD if (tqt_timerListMutex) tqt_timerListMutex->unlock(); -#endif + TQTimerEvent e( t->id ); -#if defined(TQT_THREAD_SUPPORT) // Be careful...the current thread may not be the target object's thread! if ((!t->obj) || (TQThread::currentThreadObject() && TQThread::currentThreadObject()->threadPostedEventsDisabled()) || @@ -696,17 +692,15 @@ int TQEventLoop::activateTimers() else { TQApplication::postEvent( t->obj, new TQTimerEvent(e) ); // post event to correct thread } -#else // defined(TQT_THREAD_SUPPORT) - TQApplication::sendEvent( t->obj, &e ); // send event -#endif // defined(TQT_THREAD_SUPPORT) -#if defined(TQT_THREAD_SUPPORT) if (tqt_timerListMutex) tqt_timerListMutex->lock(); -#endif +#else // !TQT_NO_THREAD + TQApplication::sendEvent( t->obj, &e ); // send event +#endif // TQT_NO_THREAD if ( timerList->findRef( begin ) == -1 ) { begin = 0; } } -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD if (tqt_timerListMutex) tqt_timerListMutex->unlock(); #endif return n_act; @@ -731,7 +725,7 @@ int TQEventLoop::activateSocketNotifiers() printf("activate sn : send event fd=%d\n", sn->gPollFD.fd ); #endif sn->pending = FALSE; -#if defined(TQT_THREAD_SUPPORT) +#ifndef TQT_NO_THREAD // Be careful...the current thread may not be the target object's thread! if ((!sn->obj) || (TQThread::currentThreadObject() && TQThread::currentThreadObject()->threadPostedEventsDisabled()) || @@ -741,9 +735,9 @@ int TQEventLoop::activateSocketNotifiers() else { TQApplication::postEvent( sn->obj, new TQEvent(event) ); // post event to correct thread } -#else // defined(TQT_THREAD_SUPPORT) +#else // !TQT_NO_THREAD TQApplication::sendEvent( sn->obj, &event ); // send event -#endif // defined(TQT_THREAD_SUPPORT) +#endif // TQT_NO_THREAD n_act++; } } |
