summaryrefslogtreecommitdiffstats
path: root/src/tsthread
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-05-26 21:04:57 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-05-26 21:04:57 +0000
commitbf7f88413be3831a9372d323d02fc0335b9f9188 (patch)
tree516fdef9206245b40a14f99b4e3d9ef9289196e0 /src/tsthread
parente238aa77b1fb3c2f55aef2ef2c91ce52166d2cc8 (diff)
downloadgwenview-bf7f88413be3831a9372d323d02fc0335b9f9188.tar.gz
gwenview-bf7f88413be3831a9372d323d02fc0335b9f9188.zip
TQt4 port Gwenview
This enables compilation under both Qt3 and Qt4 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/gwenview@1233720 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/tsthread')
-rw-r--r--src/tsthread/tsthread.cpp52
-rw-r--r--src/tsthread/tsthread.h169
-rw-r--r--src/tsthread/tswaitcondition.cpp8
-rw-r--r--src/tsthread/tswaitcondition.h20
4 files changed, 125 insertions, 124 deletions
diff --git a/src/tsthread/tsthread.cpp b/src/tsthread/tsthread.cpp
index 16b4538..43b902c 100644
--- a/src/tsthread/tsthread.cpp
+++ b/src/tsthread/tsthread.cpp
@@ -24,15 +24,15 @@ DEALINGS IN THE SOFTWARE.
#include "tsthread.h"
-#include <qapplication.h>
-#include <qmetaobject.h>
+#include <tqapplication.h>
+#include <tqmetaobject.h>
#include <kdebug.h>
-#include <qguardedptr.h>
+#include <tqguardedptr.h>
#include <assert.h>
-#ifdef TS_QTHREADSTORAGE
-QThreadStorage< TSThread** >* TSThread::current_thread;
+#ifdef TS_TQTHREADSTORAGE
+TQThreadStorage< TSThread** >* TSThread::current_thread;
#else
TSCurrentThread* TSThread::current_thread;
#endif
@@ -45,10 +45,10 @@ class TSMainThread
virtual void run() { assert( false ); }
};
-TSThread::Helper::Helper( TSThread* parent )
- : thread( parent )
+TSThread::Helper::Helper( TSThread* tqparent )
+ : thread( tqparent )
{
- assert( parent );
+ assert( tqparent );
}
void TSThread::Helper::run()
@@ -82,11 +82,11 @@ void TSThread::start()
void TSThread::cancel()
{
- QMutexLocker lock( &mutex );
+ TQMutexLocker lock( &mutex );
cancelling = true;
if( cancel_mutex != NULL )
{
- QMutexLocker lock( cancel_mutex );
+ TQMutexLocker lock( cancel_mutex );
cancel_cond->wakeAll();
}
}
@@ -108,8 +108,8 @@ bool TSThread::running() const
void TSThread::initCurrentThread()
{
-#ifdef TS_QTHREADSTORAGE
- current_thread = new QThreadStorage< TSThread** >();
+#ifdef TS_TQTHREADSTORAGE
+ current_thread = new TQThreadStorage< TSThread** >();
typedef TSThread* TSThreadPtr;
// set pointer for main thread (this must be main thread)
current_thread->setLocalData( new TSThreadPtr( NULL )); // TODO NULL ?
@@ -123,9 +123,9 @@ void TSThread::initCurrentThread()
void TSThread::executeThread()
{
-#ifdef TS_QTHREADSTORAGE
+#ifdef TS_TQTHREADSTORAGE
// store dynamically allocated pointer, so that
- // QThreadStorage deletes the pointer and not TSThread
+ // TQThreadStorage deletes the pointer and not TSThread
typedef TSThread* TSThreadPtr;
current_thread->setLocalData( new TSThreadPtr( this ));
#else
@@ -135,35 +135,35 @@ void TSThread::executeThread()
postSignal( this, NULL ); // = terminated()
}
-void TSThread::postSignal( QObject* obj, const char* signal )
+void TSThread::postSignal( TQObject* obj, const char* signal )
{
assert( currentThread() == this );
- qApp->postEvent( this, new SignalEvent( signal, obj, NULL ));
+ tqApp->postEvent( this, new SignalEvent( signal, obj, NULL ));
}
-void TSThread::emitSignalInternal( QObject* obj, const char* signal, QUObject* o )
+void TSThread::emitSignalInternal( TQObject* obj, const char* signal, TQUObject* o )
{
assert( currentThread() == this );
- QMutexLocker locker( &signal_mutex );
+ TQMutexLocker locker( &signal_mutex );
emit_pending = true;
- qApp->postEvent( this, new SignalEvent( signal, obj, o ));
+ tqApp->postEvent( this, new SignalEvent( signal, obj, o ));
while( emit_pending )
signal_cond.wait( &signal_mutex );
}
-void TSThread::emitCancellableSignalInternal( QObject* obj, const char* signal, QUObject* o )
+void TSThread::emitCancellableSignalInternal( TQObject* obj, const char* signal, TQUObject* o )
{
assert( currentThread() == this );
// can't use this->mutex, because its locking will be triggered by TSWaitCondition
- QMutexLocker locker( &signal_mutex );
+ TQMutexLocker locker( &signal_mutex );
emit_pending = true;
- qApp->postEvent( this, new SignalEvent( signal, obj, o ));
+ tqApp->postEvent( this, new SignalEvent( signal, obj, o ));
while( emit_pending && !testCancel())
signal_cond.cancellableWait( &signal_mutex );
emit_pending = false; // in case of cancel
}
-void TSThread::customEvent( QCustomEvent* ev )
+void TSThread::customEvent( TQCustomEvent* ev )
{
SignalEvent* e = static_cast< SignalEvent* >( ev );
if( e->signal.isEmpty()) // = terminated()
@@ -174,8 +174,8 @@ void TSThread::customEvent( QCustomEvent* ev )
return;
}
bool deleted = false;
- deleted_flag = &deleted; // this is like QGuardedPtr for self, but faster
- int signal_id = e->object->metaObject()->findSignal( normalizeSignalSlot( e->signal ).data() + 1, true );
+ deleted_flag = &deleted; // this is like TQGuardedPtr for self, but faster
+ int signal_id = e->object->tqmetaObject()->tqfindSignal( normalizeSignalSlot( e->signal ).data() + 1, true );
if( signal_id >= 0 )
e->object->qt_emit( signal_id, e->args );
else
@@ -183,7 +183,7 @@ void TSThread::customEvent( QCustomEvent* ev )
if( deleted ) // some slot deleted 'this'
return;
deleted_flag = NULL;
- QMutexLocker locker( &signal_mutex );
+ TQMutexLocker locker( &signal_mutex );
if( emit_pending )
{
emit_pending = false;
diff --git a/src/tsthread/tsthread.h b/src/tsthread/tsthread.h
index 5b98890..91b64e6 100644
--- a/src/tsthread/tsthread.h
+++ b/src/tsthread/tsthread.h
@@ -25,15 +25,15 @@ DEALINGS IN THE SOFTWARE.
#ifndef TSTHREAD_H
#define TSTHREAD_H
-#include <qobject.h>
-#include <qthread.h>
-#include <qwaitcondition.h>
-#include <qdeepcopy.h>
-#include <qmutex.h>
-#include <private/qucomextra_p.h>
-
-#ifdef TS_QTHREADSTORAGE
-#include <qthreadstorage.h>
+#include <tqobject.h>
+#include <tqthread.h>
+#include <tqwaitcondition.h>
+#include <tqdeepcopy.h>
+#include <tqmutex.h>
+#include <tqucomextra_p.h>
+
+#ifdef TS_TQTHREADSTORAGE
+#include <tqthreadstorage.h>
#else
#include <pthread.h>
#endif
@@ -44,42 +44,43 @@ DEALINGS IN THE SOFTWARE.
template< typename T >
T TSDeepCopy( const T& t )
{
- return QDeepCopy< T >( t );
+ return TQDeepCopy< T >( t );
}
class TSCurrentThread;
/**
- Thread class, internally based on QThread, which intentionally doesn't have
- dangerous crap like QThread::terminate() and intentionally has useful features
+ Thread class, internally based on TQThread, which intentionally doesn't have
+ dangerous crap like TQThread::terminate() and intentionally has useful features
like emitting signals to the main thread, currentThread() or support
for cancelling.
*/
class TSThread
- : public QObject
+ : public TQObject
{
Q_OBJECT
+ TQ_OBJECT
public:
TSThread();
virtual ~TSThread();
/**
* Starts the thread.
- * @see QThread::start()
+ * @see TQThread::start()
*/
void start();
/**
* Waits for the thread to finish.
- * @see QThread::wait()
+ * @see TQThread::wait()
*/
void wait( unsigned long time = ULONG_MAX );
/**
* Returns true if the thread has finished.
- * @see QThread::finished()
+ * @see TQThread::finished()
*/
bool finished() const;
/**
* Returns true if the thread is running.
- * @see QThread::running()
+ * @see TQThread::running()
*/
bool running() const;
/**
@@ -108,44 +109,44 @@ class TSThread
* Emits the specified signal in the main thread. This function returns
* only after all slots connected to the signal have been executed (i.e.
* it works like normal signal). The signal can have one pointer argument,
- * which can be used for communication in either direction. QObject::sender()
+ * which can be used for communication in either direction. TQObject::sender()
* in slots is valid.
* Example:
* \code
- * emitSignal( this, SIGNAL( result( int* )), &result_data );
+ * emitSignal( this, TQT_SIGNAL( result( int* )), &result_data );
* \endcode
* @see postSignal
* @see emitCancellableSignal
*/
- void emitSignal( QObject* obj, const char* signal );
+ void emitSignal( TQObject* obj, const char* signal );
template< typename T1 >
- void emitSignal( QObject* obj, const char* signal, const T1& p1 );
+ void emitSignal( TQObject* obj, const char* signal, const T1& p1 );
template< typename T1, typename T2 >
- void emitSignal( QObject* obj, const char* signal, const T1& p1, const T2& p2 );
+ void emitSignal( TQObject* obj, const char* signal, const T1& p1, const T2& p2 );
/**
* This function works like emitSignal(), but additionally acts as a cancellation
* point, i.e. calling cancel() on the thread causes premature return.
* @see emitSignal
* @see postSignal
*/
- void emitCancellableSignal( QObject* obj, const char* signal );
+ void emitCancellableSignal( TQObject* obj, const char* signal );
template< typename T1 >
- void emitCancellableSignal( QObject* obj, const char* signal, const T1& p1 );
+ void emitCancellableSignal( TQObject* obj, const char* signal, const T1& p1 );
template< typename T1, typename T2 >
- void emitCancellableSignal( QObject* obj, const char* signal, const T1& p1, const T2& p2 );
+ void emitCancellableSignal( TQObject* obj, const char* signal, const T1& p1, const T2& p2 );
/**
* Posts (i.e. it is not executed immediatelly like normal signals)
* a signal to be emitted in the main thread. The signal cannot
* have any parameters, use your TSThread derived class instance
- * data members instead. QObject::sender() in slots is valid, unless
+ * data members instead. TQObject::sender() in slots is valid, unless
* the thread instance is destroyed before the signal is processed.
* @see emitSignal
*/
- void postSignal( QObject* obj, const char* signal ); // is emitted _always_ in main thread
+ void postSignal( TQObject* obj, const char* signal ); // is emitted _always_ in main thread
protected:
/**
* The code to be executed in the started thread.
- * @see QThread::run()
+ * @see TQThread::run()
*/
virtual void run() = 0;
signals:
@@ -157,25 +158,25 @@ class TSThread
/**
* @internal
*/
- void customEvent( QCustomEvent* e );
+ void customEvent( TQCustomEvent* e );
private:
class SignalEvent
- : public QCustomEvent
+ : public TQCustomEvent
{
public:
- SignalEvent( const char* sig, QObject* obj, QUObject* o )
- : QCustomEvent( QEvent::User ), signal( sig ), object( obj ), args( o )
+ SignalEvent( const char* sig, TQObject* obj, TQUObject* o )
+ : TQCustomEvent( TQEvent::User ), signal( sig ), object( obj ), args( o )
{
}
- const QCString signal;
- QObject* object;
- QUObject* args;
+ const TQCString signal;
+ TQObject* object;
+ TQUObject* args;
};
class Helper
- : public QThread
+ : public TQThread
{
public:
- Helper( TSThread* parent );
+ Helper( TSThread* tqparent );
protected:
virtual void run();
private:
@@ -183,29 +184,29 @@ class TSThread
};
void executeThread();
static void initCurrentThread();
- bool setCancelData( QMutex*m, QWaitCondition* c );
- void setSignalData( QUObject* o, int i );
- void setSignalData( QUObject* o, const QImage& i );
- void setSignalData( QUObject* o, const QString& s );
- void setSignalData( QUObject* o, bool b );
- void setSignalData( QUObject* o, const QColor& c );
- void setSignalData( QUObject* o, const char* s );
- void setSignalData( QUObject* o, const QSize& );
- void emitSignalInternal( QObject* obj, const char* signal, QUObject* o );
- void emitCancellableSignalInternal( QObject* obj, const char* signal, QUObject* o );
+ bool setCancelData( TQMutex*m, TQWaitCondition* c );
+ void setSignalData( TQUObject* o, int i );
+ void setSignalData( TQUObject* o, const TQImage& i );
+ void setSignalData( TQUObject* o, const TQString& s );
+ void setSignalData( TQUObject* o, bool b );
+ void setSignalData( TQUObject* o, const TQColor& c );
+ void setSignalData( TQUObject* o, const char* s );
+ void setSignalData( TQUObject* o, const TQSize& );
+ void emitSignalInternal( TQObject* obj, const char* signal, TQUObject* o );
+ void emitCancellableSignalInternal( TQObject* obj, const char* signal, TQUObject* o );
friend class Helper;
friend class TSWaitCondition;
Helper thread;
bool cancelling;
bool emit_pending;
- mutable QMutex mutex;
- QMutex signal_mutex;
+ mutable TQMutex mutex;
+ TQMutex signal_mutex;
TSWaitCondition signal_cond;
- QMutex* cancel_mutex;
- QWaitCondition* cancel_cond;
+ TQMutex* cancel_mutex;
+ TQWaitCondition* cancel_cond;
bool* deleted_flag;
-#ifdef TS_QTHREADSTORAGE
- static QThreadStorage< TSThread** >* current_thread;
+#ifdef TS_TQTHREADSTORAGE
+ static TQThreadStorage< TSThread** >* current_thread;
#else
static TSCurrentThread* current_thread;
#endif
@@ -215,7 +216,7 @@ class TSThread
TSThread& operator=( const TSThread& );
};
-#ifndef TS_QTHREADSTORAGE
+#ifndef TS_TQTHREADSTORAGE
/**
* @internal
*/
@@ -255,15 +256,15 @@ inline TSThread* TSCurrentThread::localData() const
inline
bool TSThread::testCancel() const
{
- QMutexLocker lock( &mutex );
+ TQMutexLocker lock( &mutex );
return cancelling;
}
#include <kdebug.h>
inline
-bool TSThread::setCancelData( QMutex* m, QWaitCondition* c )
+bool TSThread::setCancelData( TQMutex* m, TQWaitCondition* c )
{
- QMutexLocker lock( &mutex );
+ TQMutexLocker lock( &mutex );
if( cancelling && m != NULL )
return false;
cancel_mutex = m;
@@ -276,7 +277,7 @@ TSThread* TSThread::currentThread()
{
if( current_thread == NULL )
initCurrentThread();
-#ifdef TS_QTHREADSTORAGE
+#ifdef TS_TQTHREADSTORAGE
return *current_thread->localData();
#else
return current_thread->localData();
@@ -290,94 +291,94 @@ TSThread* TSThread::mainThread()
}
inline
-void TSThread::setSignalData( QUObject* o, int i )
+void TSThread::setSignalData( TQUObject* o, int i )
{
- static_QUType_int.set( o, i );
+ static_TQUType_int.set( o, i );
}
inline
-void TSThread::setSignalData( QUObject* o, const QImage& i )
+void TSThread::setSignalData( TQUObject* o, const TQImage& i )
{
- static_QUType_varptr.set( o, &i );
+ static_TQUType_varptr.set( o, &i );
}
inline
-void TSThread::setSignalData( QUObject* o, const QString& s )
+void TSThread::setSignalData( TQUObject* o, const TQString& s )
{
- static_QUType_QString.set( o, s );
+ static_TQUType_TQString.set( o, s );
}
inline
-void TSThread::setSignalData( QUObject* o, bool b )
+void TSThread::setSignalData( TQUObject* o, bool b )
{
- static_QUType_bool.set( o, b );
+ static_TQUType_bool.set( o, b );
}
inline
-void TSThread::setSignalData( QUObject* o, const QColor& c )
+void TSThread::setSignalData( TQUObject* o, const TQColor& c )
{
- static_QUType_varptr.set( o, &c );
+ static_TQUType_varptr.set( o, &c );
}
inline
-void TSThread::setSignalData( QUObject* o, const char* s )
+void TSThread::setSignalData( TQUObject* o, const char* s )
{
- static_QUType_charstar.set( o, s );
+ static_TQUType_charstar.set( o, s );
}
inline
-void TSThread::setSignalData( QUObject* o, const QSize& s )
+void TSThread::setSignalData( TQUObject* o, const TQSize& s )
{
- static_QUType_varptr.set( o, &s );
+ static_TQUType_varptr.set( o, &s );
}
inline
-void TSThread::emitSignal( QObject* obj, const char* signal )
+void TSThread::emitSignal( TQObject* obj, const char* signal )
{
- QUObject o[ 1 ];
+ TQUObject o[ 1 ];
emitSignalInternal( obj, signal, o );
}
template< typename T1 >
inline
-void TSThread::emitSignal( QObject* obj, const char* signal, const T1& p1 )
+void TSThread::emitSignal( TQObject* obj, const char* signal, const T1& p1 )
{
- QUObject o[ 2 ];
+ TQUObject o[ 2 ];
setSignalData( o + 1, p1 );
emitSignalInternal( obj, signal, o );
}
template< typename T1, typename T2 >
inline
-void TSThread::emitSignal( QObject* obj, const char* signal, const T1& p1, const T2& p2 )
+void TSThread::emitSignal( TQObject* obj, const char* signal, const T1& p1, const T2& p2 )
{
- QUObject o[ 3 ];
+ TQUObject o[ 3 ];
setSignalData( o + 1, p1 );
setSignalData( o + 2, p2 );
emitSignalInternal( obj, signal, o );
}
inline
-void TSThread::emitCancellableSignal( QObject* obj, const char* signal )
+void TSThread::emitCancellableSignal( TQObject* obj, const char* signal )
{
- QUObject o[ 1 ];
+ TQUObject o[ 1 ];
emitCancellableSignalInternal( obj, signal, o );
}
template< typename T1 >
inline
-void TSThread::emitCancellableSignal( QObject* obj, const char* signal, const T1& p1 )
+void TSThread::emitCancellableSignal( TQObject* obj, const char* signal, const T1& p1 )
{
- QUObject o[ 2 ];
+ TQUObject o[ 2 ];
setSignalData( o + 1, p1 );
emitCancellableSignalInternal( obj, signal, o );
}
template< typename T1, typename T2 >
inline
-void TSThread::emitCancellableSignal( QObject* obj, const char* signal, const T1& p1, const T2& p2 )
+void TSThread::emitCancellableSignal( TQObject* obj, const char* signal, const T1& p1, const T2& p2 )
{
- QUObject o[ 3 ];
+ TQUObject o[ 3 ];
setSignalData( o + 1, p1 );
setSignalData( o + 2, p2 );
emitCancellableSignalInternal( obj, signal, o );
diff --git a/src/tsthread/tswaitcondition.cpp b/src/tsthread/tswaitcondition.cpp
index e11e989..fb038ff 100644
--- a/src/tsthread/tswaitcondition.cpp
+++ b/src/tsthread/tswaitcondition.cpp
@@ -26,12 +26,12 @@ DEALINGS IN THE SOFTWARE.
#include "tsthread.h"
-bool TSWaitCondition::wait( QMutex* m, unsigned long time )
+bool TSWaitCondition::wait( TQMutex* m, unsigned long time )
{
return cond.wait( m, time ); // TODO?
}
-bool TSWaitCondition::cancellableWait( QMutex* m, unsigned long time )
+bool TSWaitCondition::cancellableWait( TQMutex* m, unsigned long time )
{
mutex.lock();
if( !TSThread::currentThread()->setCancelData( &mutex, &cond ))
@@ -49,12 +49,12 @@ bool TSWaitCondition::cancellableWait( QMutex* m, unsigned long time )
void TSWaitCondition::wakeOne()
{
- QMutexLocker locker( &mutex );
+ TQMutexLocker locker( &mutex );
cond.wakeOne();
}
void TSWaitCondition::wakeAll()
{
- QMutexLocker locker( &mutex );
+ TQMutexLocker locker( &mutex );
cond.wakeAll();
}
diff --git a/src/tsthread/tswaitcondition.h b/src/tsthread/tswaitcondition.h
index 09f9cab..b13695f 100644
--- a/src/tsthread/tswaitcondition.h
+++ b/src/tsthread/tswaitcondition.h
@@ -25,23 +25,23 @@ DEALINGS IN THE SOFTWARE.
#ifndef TSWAITCONDITION_H
#define TSWAITCONDITION_H
-#include <qmutex.h>
-#include <qwaitcondition.h>
+#include <tqmutex.h>
+#include <tqwaitcondition.h>
class TSWaitCondition
{
public:
TSWaitCondition();
~TSWaitCondition();
- bool wait( QMutex* mutex, unsigned long time = ULONG_MAX );
- bool wait( QMutex& mutex, unsigned long time = ULONG_MAX );
- bool cancellableWait( QMutex* mutex, unsigned long time = ULONG_MAX );
- bool cancellableWait( QMutex& mutex, unsigned long time = ULONG_MAX );
+ bool wait( TQMutex* mutex, unsigned long time = ULONG_MAX );
+ bool wait( TQMutex& mutex, unsigned long time = ULONG_MAX );
+ bool cancellableWait( TQMutex* mutex, unsigned long time = ULONG_MAX );
+ bool cancellableWait( TQMutex& mutex, unsigned long time = ULONG_MAX );
void wakeOne();
void wakeAll();
private:
- QMutex mutex;
- QWaitCondition cond;
+ TQMutex mutex;
+ TQWaitCondition cond;
private:
TSWaitCondition( const TSWaitCondition& );
TSWaitCondition& operator=( const TSWaitCondition& );
@@ -58,13 +58,13 @@ TSWaitCondition::~TSWaitCondition()
}
inline
-bool TSWaitCondition::wait( QMutex& mutex, unsigned long time )
+bool TSWaitCondition::wait( TQMutex& mutex, unsigned long time )
{
return wait( &mutex, time );
}
inline
-bool TSWaitCondition::cancellableWait( QMutex& mutex, unsigned long time )
+bool TSWaitCondition::cancellableWait( TQMutex& mutex, unsigned long time )
{
return cancellableWait( &mutex, time );
}