void ThreadPool::shutdown() { int n = activeThreadCount(); CommandPacket* item; if (n <= 0) return; //std::cout << "shutdown pushes " << n << " work items" << std::endl; for (int i = 0; i < n; i++) { workQue.push(item); } SDL_Delay(2000); }
int QThreadPool::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; #ifndef QT_NO_PROPERTIES if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< int*>(_v) = expiryTimeout(); break; case 1: *reinterpret_cast< int*>(_v) = maxThreadCount(); break; case 2: *reinterpret_cast< int*>(_v) = activeThreadCount(); break; } _id -= 3; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setExpiryTimeout(*reinterpret_cast< int*>(_v)); break; case 1: setMaxThreadCount(*reinterpret_cast< int*>(_v)); break; } _id -= 3; } else if (_c == QMetaObject::ResetProperty) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 3; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 3; } #endif // QT_NO_PROPERTIES return _id; }
bool QThreadPoolPrivate::tryStart(QRunnable *task) { if (allThreads.isEmpty()) { // always create at least one thread startThread(task); return true; } // can't do anything if we're over the limit if (activeThreadCount() >= maxThreadCount) return false; if (waitingThreads > 0) { // recycle an available thread --waitingThreads; enqueueTask(task); return true; } if (!expiredThreads.isEmpty()) { // restart an expired thread QThreadPoolThread *thread = expiredThreads.dequeue(); Q_ASSERT(thread->runnable == 0); ++activeThreads; if (task->autoDelete()) ++task->ref; thread->runnable = task; thread->start(); return true; } // start a new thread startThread(task); return true; }