void QThreadPrivate::finish(void *arg) { QThread *thr = reinterpret_cast<QThread *>(arg); QThreadPrivate *d = thr->d_func(); QMutexLocker locker(&d->mutex); d->priority = QThread::InheritPriority; d->running = false; d->finished = true; if (d->terminated) emit thr->terminated(); d->terminated = false; emit thr->finished(); if (d->data->eventDispatcher) { d->data->eventDispatcher->closingDown(); QAbstractEventDispatcher *eventDispatcher = d->data->eventDispatcher; d->data->eventDispatcher = 0; delete eventDispatcher; } void *data = &d->data->tls; QThreadStorageData::finish((void **)data); d->thread_id = 0; d->thread_done.wakeAll(); }
QThreadData *QThreadData::current() { QThreadData *data = get_thread_data(); if (!data) { void *a; if (QInternal::activateCallbacks(QInternal::AdoptCurrentThread, &a)) { QThread *adopted = static_cast<QThread*>(a); Q_ASSERT(adopted); data = QThreadData::get2(adopted); set_thread_data(data); adopted->d_func()->running = true; adopted->d_func()->finished = false; static_cast<QAdoptedThread *>(adopted)->init(); } else { data = new QThreadData; QT_TRY { set_thread_data(data); data->thread = new QAdoptedThread(data); } QT_CATCH(...) { clear_thread_data(); data->deref(); data = 0; QT_RETHROW; } data->deref(); }
QThreadData *QThreadData::current() { pthread_once(¤t_thread_data_once, create_current_thread_data_key); QThreadData *data = reinterpret_cast<QThreadData *>(pthread_getspecific(current_thread_data_key)); if (!data) { void *a; if (QInternal::activateCallbacks(QInternal::AdoptCurrentThread, &a)) { QThread *adopted = static_cast<QThread*>(a); Q_ASSERT(adopted); data = QThreadData::get2(adopted); pthread_setspecific(current_thread_data_key, data); adopted->d_func()->running = true; adopted->d_func()->finished = false; static_cast<QAdoptedThread *>(adopted)->init(); } else { data = new QThreadData; pthread_setspecific(current_thread_data_key, data); data->thread = new QAdoptedThread(data); data->deref(); } (void) q_atomic_test_and_set_ptr(&QCoreApplicationPrivate::theMainThread, 0, data->thread); } return data; }
/* QThreadData */ QThreadData *QThreadData::current() { qt_create_tls(); QThreadData *threadData = reinterpret_cast<QThreadData *>(TlsGetValue(qt_current_thread_data_tls_index)); if (!threadData) { QThread *adopted = 0; if (QInternal::activateCallbacks(QInternal::AdoptCurrentThread, (void **) &adopted)) { Q_ASSERT(adopted); threadData = QThreadData::get2(adopted); TlsSetValue(qt_current_thread_data_tls_index, threadData); adopted->d_func()->running = true; adopted->d_func()->finished = false; static_cast<QAdoptedThread *>(adopted)->init(); } else { threadData = new QThreadData; // This needs to be called prior to new AdoptedThread() to // avoid recursion. TlsSetValue(qt_current_thread_data_tls_index, threadData); QT_TRY { threadData->thread = new QAdoptedThread(threadData); } QT_CATCH(...) { TlsSetValue(qt_current_thread_data_tls_index, 0); threadData->deref(); threadData = 0; QT_RETHROW; } threadData->deref(); }
QThreadData *QThreadData::current() { pthread_once(¤t_thread_data_once, create_current_thread_data_key); QThreadData *data = reinterpret_cast<QThreadData *>(pthread_getspecific(current_thread_data_key)); if (!data) { void *a; if (QInternal::activateCallbacks(QInternal::AdoptCurrentThread, &a)) { QThread *adopted = static_cast<QThread*>(a); Q_ASSERT(adopted); data = QThreadData::get2(adopted); pthread_setspecific(current_thread_data_key, data); adopted->d_func()->running = true; adopted->d_func()->finished = false; static_cast<QAdoptedThread *>(adopted)->init(); } else { data = new QThreadData; pthread_setspecific(current_thread_data_key, data); QT_TRY { data->thread = new QAdoptedThread(data); } QT_CATCH(...) { pthread_setspecific(current_thread_data_key, 0); data->deref(); data = 0; QT_RETHROW; } data->deref(); }
/* QThreadData */ QThreadData *QThreadData::current() { qt_create_tls(); QThreadData *threadData = *qt_tls; if (!threadData) { QThread *adopted = 0; if (QInternal::activateCallbacks(QInternal::AdoptCurrentThread, (void **) &adopted)) { Q_ASSERT(adopted); threadData = QThreadData::get2(adopted); *qt_tls = threadData; adopted->d_func()->running = true; adopted->d_func()->finished = false; static_cast<QAdoptedThread *>(adopted)->init(); } else { threadData = new QThreadData; // This needs to be called prior to new AdoptedThread() to // avoid recursion. *qt_tls = threadData; threadData->thread = new QAdoptedThread(threadData); threadData->deref(); } if (!QCoreApplicationPrivate::theMainThread) { QCoreApplicationPrivate::theMainThread = threadData->thread; } else { PTIB ptib; DosGetInfoBlocks(&ptib, NULL); qt_watch_adopted_thread(ptib->tib_ptib2->tib2_ultid, threadData->thread); } } return threadData; }
/* QThreadData */ QThreadData *QThreadData::current() { qt_create_tls(); QThreadData *threadData = reinterpret_cast<QThreadData *>(TlsGetValue(qt_current_thread_data_tls_index)); if (!threadData) { QThread *adopted = 0; if (QInternal::activateCallbacks(QInternal::AdoptCurrentThread, (void **) &adopted)) { Q_ASSERT(adopted); threadData = QThreadData::get2(adopted); TlsSetValue(qt_current_thread_data_tls_index, threadData); adopted->d_func()->running = true; adopted->d_func()->finished = false; static_cast<QAdoptedThread *>(adopted)->init(); } else { threadData = new QThreadData; // This needs to be called prior to new AdoptedThread() to // avoid recursion. TlsSetValue(qt_current_thread_data_tls_index, threadData); threadData->thread = new QAdoptedThread(threadData); threadData->deref(); } if (!QCoreApplicationPrivate::theMainThread) { QCoreApplicationPrivate::theMainThread = threadData->thread; } else { HANDLE realHandle = INVALID_HANDLE_VALUE; #if !defined(Q_OS_WINCE) || (defined(_WIN32_WCE) && (_WIN32_WCE>=0x600)) DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &realHandle, 0, FALSE, DUPLICATE_SAME_ACCESS); #else realHandle = (HANDLE)GetCurrentThreadId(); #endif qt_watch_adopted_thread(realHandle, threadData->thread); } } return threadData; }
/* QThreadData */ QThreadData *QThreadData::current() { qt_create_tls(); QThreadData *threadData = reinterpret_cast<QThreadData *>(TlsGetValue(qt_current_thread_data_tls_index)); if (!threadData) { QThread *adopted = 0; if (QInternal::activateCallbacks(QInternal::AdoptCurrentThread, (void **) &adopted)) { Q_ASSERT(adopted); threadData = QThreadData::get2(adopted); TlsSetValue(qt_current_thread_data_tls_index, threadData); adopted->d_func()->running = true; adopted->d_func()->finished = false; static_cast<QAdoptedThread *>(adopted)->init(); } else { threadData = new QThreadData; // This needs to be called prior to new AdoptedThread() to // avoid recursion. TlsSetValue(qt_current_thread_data_tls_index, threadData); threadData->thread = new QAdoptedThread(threadData); threadData->deref(); } const bool isMainThread = q_atomic_test_and_set_ptr(&QCoreApplicationPrivate::theMainThread, 0, threadData->thread); if (!isMainThread) { HANDLE realHandle; DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &realHandle, 0, FALSE, DUPLICATE_SAME_ACCESS); qt_watch_adopted_thread(realHandle, threadData->thread); } } return threadData; }