当前位置: 首页>>代码示例>>C++>>正文


C++ QThreadData::ref方法代码示例

本文整理汇总了C++中QThreadData::ref方法的典型用法代码示例。如果您正苦于以下问题:C++ QThreadData::ref方法的具体用法?C++ QThreadData::ref怎么用?C++ QThreadData::ref使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QThreadData的用法示例。


在下文中一共展示了QThreadData::ref方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: createEventDispatcher

void *QThreadPrivate::start(void *arg)
{
    pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
    pthread_cleanup_push(QThreadPrivate::finish, arg);

    QThread *thr = reinterpret_cast<QThread *>(arg);
    QThreadData *data = QThreadData::get2(thr);

    pthread_once(&current_thread_data_once, create_current_thread_data_key);
    pthread_setspecific(current_thread_data_key, data);

    data->ref();
    data->quitNow = false;

    // ### TODO: allow the user to create a custom event dispatcher
    createEventDispatcher(data);

    emit thr->started();
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
    pthread_testcancel();
    thr->run();

    pthread_cleanup_pop(1);
    return 0;
}
开发者ID:GodFox,项目名称:qtopia-ezx,代码行数:25,代码来源:qthread_unix.cpp

示例2: moveToThread

void QObject::moveToThread(QThread *targetThread)
{
   if (m_threadData.load()->thread == targetThread) {
      // object is already in this thread
      return;
   }

   if (m_parent != 0) {
      qWarning("QObject::moveToThread() Can not move an object with a parent");
      return;
   }

   if (isWidgetType()) {
      qWarning("QObject::moveToThread() Widgets can not be moved to a new thread");
      return;
   }

   QThreadData *currentData = QThreadData::current();
   QThreadData *targetData = targetThread ? QThreadData::get2(targetThread) : new QThreadData(0);

   QThreadData *threadData = m_threadData.load();

   if (threadData->thread == 0 && currentData == targetData) {
      // exception: allow moving objects with no thread affinity to the current thread
      currentData = threadData;

   } else if (threadData != currentData) {

      qWarning("QObject::moveToThread() Current thread (%p) is not the current object's thread (%p).\n"
               "Can not move to target thread (%p)\n", currentData->thread, threadData->thread, targetData->thread);

#ifdef Q_WS_MAC

      qWarning("Multiple libraries might be loaded in the same process. Verify all plugins are "
               "linked with the correct binaries. Export DYLD_PRINT_LIBRARIES=1 and verify only one set of "
               "binaries are being loaded.");
#endif

      return;
   }

   // prepare to move
   this->moveToThread_helper();

   QOrderedMutexLocker locker(&currentData->postEventList.mutex, &targetData->postEventList.mutex);

   // keep currentData alive
   currentData->ref();

   // move the object
   this->setThreadData_helper(currentData, targetData);

   locker.unlock();
   currentData->deref();
}
开发者ID:wpbest,项目名称:copperspice,代码行数:55,代码来源:qobject.cpp


注:本文中的QThreadData::ref方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。