本文整理汇总了C++中QThreadData类的典型用法代码示例。如果您正苦于以下问题:C++ QThreadData类的具体用法?C++ QThreadData怎么用?C++ QThreadData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QThreadData类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qt_create_tls
QThreadData *QThreadData::current(bool createIfNecessary)
{
qt_create_tls();
QThreadData *threadData = reinterpret_cast<QThreadData *>(TlsGetValue(qt_current_thread_data_tls_index));
if (!threadData && createIfNecessary) {
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;
}
示例2: setThreadData_helper
void QObject::setThreadData_helper(QThreadData *currentData, QThreadData *targetData)
{
// move posted events
int eventsMoved = 0;
for (int i = 0; i < currentData->postEventList.size(); ++i) {
const QPostEvent &postedEvent = currentData->postEventList.at(i);
if (! postedEvent.event) {
continue;
}
if (postedEvent.receiver == this) {
// move this post event to the targetList
targetData->postEventList.addEvent(postedEvent);
const_cast<QPostEvent &>(postedEvent).event = 0;
++eventsMoved;
}
}
if (eventsMoved > 0 && targetData->eventDispatcher) {
targetData->canWait = false;
targetData->eventDispatcher->wakeUp();
}
// the current emitting thread shouldn't restore currentSender after calling moveToThread()
if (m_currentSender) {
m_currentSender->ref = 0;
}
m_currentSender = 0;
// set new thread data
targetData->ref();
QThreadData *threadData = m_threadData.exchange(targetData);
threadData->deref();
for (int k = 0; k < m_children.size(); ++k) {
QObject *child = m_children.at(k);
child->setThreadData_helper(currentData, targetData);
}
}
示例3: qt_create_tls
/*
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;
}
示例4: qt_create_tls
/*
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;
}
示例5: destroyed
//.........这里部分代码省略.........
for(auto index = this->m_connectList_ToReceiver.begin(); index != this->m_connectList_ToReceiver.end(); ++index) {
const ConnectStruct &temp = *index;
if (temp.sender == 0) {
// connection is marked for deletion
continue;
}
if (! temp.receiver) {
continue;
}
std::unique_lock<std::mutex> tempReceiverLock{temp.receiver->m_mutex_FromSender, std::defer_lock};
if (this != temp.receiver) {
tempReceiverLock.lock();
}
for (int x = 0; x < temp.receiver->m_connectList_FromSender.count(); ++x) {
if (this == temp.receiver->m_connectList_FromSender[x].sender) {
temp.receiver->m_connectList_FromSender.removeAt(x);
// yes, this is required
x = x - 1;
}
}
}
// disconnect all senders from receiver
bool isDone = false;
for(auto index = this->m_connectList_FromSender.begin(); index != this->m_connectList_FromSender.end(); ++index) {
ConnectStruct &temp = *index;
std::unique_lock<std::mutex> tempSenderLock{temp.sender->m_mutex_ToReceiver, std::defer_lock};
if (this != temp.sender) {
tempSenderLock.lock();
}
for (int x = 0; x < temp.sender->m_connectList_ToReceiver.count(); ++x) {
// connection is in another object to one of our slots
ConnectStruct &connection = temp.sender->m_connectList_ToReceiver[x];
if (connection.sender == 0) {
// connection is marked for deletion
continue;
}
if (this == connection.receiver) {
if (temp.sender->m_activateBusy) {
if (! isDone) {
// warns activate the connectList has changed
temp.sender->m_raceCount++;
isDone = true;
}
// mark connection for deletion, activate() will finish
connection.sender = 0;
} else {
temp.sender->m_connectList_ToReceiver.removeAt(x);
// yes, this is required
x = x - 1;
}
}
}
}
if (! this->m_children.isEmpty()) {
this->deleteChildren();
}
this->removeObject();
if (this->m_parent) {
// remove 'this' from parent object
this->setParent(0);
}
QThreadData *threadData = m_threadData.load();
if (m_pendTimer) {
// unregister pending timers
if (threadData && threadData->eventDispatcher) {
threadData->eventDispatcher->unregisterTimers(this);
}
}
if (m_postedEvents) {
QCoreApplication::removePostedEvents(this, 0);
}
if (threadData) {
threadData->deref();
}
}