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/qthread_unix.cpp | 46 +++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'src/kernel/qthread_unix.cpp') 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 -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(pthread_getspecific(storage_key)); +} + #endif // QT_THREAD_SUPPORT -- cgit v1.2.1