@ -51,10 +51,12 @@ typedef pthread_mutex_t Q_MUTEX_T;
# include <errno.h>
# include <sched.h>
# if defined(QT_USE_GLIBMAINLOOP)
# include <glib.h>
# endif // QT_USE_GLIBMAINLOOP
static QMutexPool * qt_thread_mutexpool = 0 ;
# if defined(Q_C_CALLBACKS)
extern " C " {
# endif
@ -121,6 +123,11 @@ void *QThreadInstance::start( void *_arg )
{
void * * arg = ( void * * ) _arg ;
# if defined(QT_USE_GLIBMAINLOOP)
// This is the first time we have access to the native pthread ID of this newly created thread
( ( QThreadInstance * ) arg [ 1 ] ) - > thread_id = pthread_self ( ) ;
# endif // QT_USE_GLIBMAINLOOP
setCurrentThread ( ( QThread * ) arg [ 0 ] ) ;
pthread_cleanup_push ( QThreadInstance : : finish , arg [ 1 ] ) ;
@ -390,6 +397,20 @@ void QThread::start(Priority priority)
d - > args [ 0 ] = this ;
d - > args [ 1 ] = d ;
# if defined(QT_USE_GLIBMAINLOOP)
// Legacy glib versions require this threading system initialization call
g_thread_init ( NULL ) ;
GThread * glib_thread_handle = g_thread_create ( ( GThreadFunc ) QThreadInstance : : start , d - > args , false , NULL ) ;
if ( glib_thread_handle ) {
ret = 0 ;
}
else {
ret = - 1 ;
}
// The correct thread_id is set in QThreadInstance::start using the value of d->args[1]
d - > thread_id = NULL ;
# else // QT_USE_GLIBMAINLOOP
ret = pthread_create ( & d - > thread_id , & attr , ( QtThreadCallback ) QThreadInstance : : start , d - > args ) ;
# if defined (Q_OS_HPUX)
if ( ret = = EPERM ) {
@ -398,6 +419,7 @@ void QThread::start(Priority priority)
}
# endif
pthread_attr_destroy ( & attr ) ;
# endif // QT_USE_GLIBMAINLOOP
if ( ret ) {
# ifdef QT_CHECK_STATE
@ -444,8 +466,9 @@ bool QThread::wait( unsigned long time )
return FALSE ;
}
if ( d - > finished | | ! d - > running )
if ( d - > finished | | ! d - > running ) {
return TRUE ;
}
int ret ;
if ( time ! = ULONG_MAX ) {
@ -458,12 +481,15 @@ bool QThread::wait( unsigned long time )
ti . tv_nsec % = 1000000000 ;
ret = pthread_cond_timedwait ( & d - > thread_done , & locker . mutex ( ) - > d - > handle , & ti ) ;
} else
}
else {
ret = pthread_cond_wait ( & d - > thread_done , & locker . mutex ( ) - > d - > handle ) ;
}
# ifdef QT_CHECK_RANGE
if ( ret & & ret ! = ETIMEDOUT )
if ( ret & & ret ! = ETIMEDOUT ) {
qWarning ( " Wait condition wait failure: %s " , strerror ( ret ) ) ;
}
# endif
return ( ret = = 0 ) ;