summaryrefslogtreecommitdiffstats
path: root/src/kernel/qthread_unix.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-12-06 16:48:15 -0600
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-12-06 16:48:15 -0600
commit3f5dc49edf41359f18e7c94c28a345a9600eb44f (patch)
tree9377a62fd7701d20da0f08cc391035d8d072e8bf /src/kernel/qthread_unix.cpp
parent6955a7ebe3c3a0ae2af416fc57ca1f3e9af0ecc3 (diff)
downloadtqt3-3f5dc49edf41359f18e7c94c28a345a9600eb44f.tar.gz
tqt3-3f5dc49edf41359f18e7c94c28a345a9600eb44f.zip
Automated update from Qt3
Diffstat (limited to 'src/kernel/qthread_unix.cpp')
-rw-r--r--src/kernel/qthread_unix.cpp46
1 files changed, 30 insertions, 16 deletions
diff --git a/src/kernel/qthread_unix.cpp b/src/kernel/qthread_unix.cpp
index 73319b64a..8cb39a7fc 100644
--- a/src/kernel/qthread_unix.cpp
+++ b/src/kernel/qthread_unix.cpp
@@ -52,11 +52,6 @@ typedef pthread_mutex_t Q_MUTEX_T;
#include <sched.h>
-static TQThreadInstance main_instance = {
- 0, { 0, &main_instance }, 0, 0, 1, 0, PTHREAD_COND_INITIALIZER, 0
-};
-
-
static TQMutexPool *qt_thread_mutexpool = 0;
@@ -82,10 +77,20 @@ static void create_storage_key()
** TQThreadInstance
*************************************************************************/
+void TQThreadInstance::setCurrentThread(TQThread *thread)
+{
+ pthread_once(&storage_key_once, create_storage_key);
+ pthread_setspecific(storage_key, thread);
+}
+
TQThreadInstance *TQThreadInstance::current()
{
+ TQThreadInstance *ret = NULL;
pthread_once( &storage_key_once, create_storage_key );
- TQThreadInstance *ret = (TQThreadInstance *) pthread_getspecific( storage_key );
+ TQThread *thread = (TQThread *) pthread_getspecific( storage_key );
+ if (thread) {
+ ret = thread->d;
+ }
return ret;
}
@@ -101,6 +106,8 @@ void TQThreadInstance::init(unsigned int stackSize)
pthread_cond_init(&thread_done, NULL);
thread_id = 0;
+ eventLoop = 0;
+
// threads have not been initialized yet, do it now
if (! qt_thread_mutexpool) TQThread::initialize();
}
@@ -114,8 +121,8 @@ void *TQThreadInstance::start( void *_arg )
{
void **arg = (void **) _arg;
- pthread_once( &storage_key_once, create_storage_key );
- pthread_setspecific( storage_key, arg[1] );
+ setCurrentThread( (TQThread *) arg[0] );
+
pthread_cleanup_push( TQThreadInstance::finish, arg[1] );
pthread_testcancel();
@@ -192,9 +199,6 @@ void TQThread::initialize()
tqt_global_mutexpool = new TQMutexPool( TRUE, 73 );
if ( ! qt_thread_mutexpool )
qt_thread_mutexpool = new TQMutexPool( FALSE, 127 );
-
- pthread_once( &storage_key_once, create_storage_key );
- pthread_setspecific( storage_key, &main_instance );
}
/*! \internal
@@ -206,11 +210,6 @@ void TQThread::cleanup()
delete qt_thread_mutexpool;
tqt_global_mutexpool = 0;
qt_thread_mutexpool = 0;
-
- TQThreadInstance::finish(&main_instance);
-
- pthread_once( &storage_key_once, create_storage_key );
- pthread_setspecific( storage_key, 0 );
}
/*!
@@ -470,5 +469,20 @@ bool TQThread::wait( unsigned long time )
return (ret == 0);
}
+/*!
+ Returns a pointer to the currently executing TQThread. If the
+ current thread was not started using the TQThread API, this
+ function returns zero.
+
+ Note that TQApplication creates a TQThread object to represent the
+ main thread; calling this function from main() after creating
+ TQApplication will return a valid pointer.
+*/
+TQThread *TQThread::currentThreadObject()
+{
+ pthread_once(&storage_key_once, create_storage_key);
+ return reinterpret_cast<TQThread *>(pthread_getspecific(storage_key));
+}
+
#endif // QT_THREAD_SUPPORT