50 #include "private/qcoreapplication_p.h"
61 : _ref(initialRefCount), loopLevel(0), scopeLevel(0),
99 --pe.
receiver->d_func()->postedEvents;
100 pe.
event->m_posted =
false;
110 #if QT_CONFIG(thread)
118 #if QT_CONFIG(thread)
140 #if QT_CONFIG(thread)
141 d_func()->running =
true;
154 #if QT_CONFIG(thread)
158 qFatal(
"QAdoptedThread::run(): Internal error, this implementation should never be called.");
167 isInFinish(
false), interruptionRequested(
false),
168 exited(
false), returnCode(-1),
169 stackSize(0), priority(
QThread::InheritPriority),
data(
d)
175 #ifdef Q_OS_INTEGRITY
177 #elif defined(Q_OS_RTEMS)
178 static bool envStackSizeOk =
false;
179 static const int envStackSize = qEnvironmentVariableIntValue(
"QT_DEFAULT_THREAD_STACK_SIZE", &envStackSizeOk);
184 #if defined (Q_OS_WIN)
188 terminationEnabled =
true;
189 terminatePending =
false;
404 return data->thread.loadAcquire();
419 d->data->thread.storeRelaxed(
this);
430 d->data->thread.storeRelaxed(
this);
461 if (
d->running && !
d->finished && !
d->data->isAdopted)
462 qFatal(
"QThread: Destroyed while thread is still running");
464 d->data->thread.storeRelease(
nullptr);
478 return d->finished ||
d->isInFinish;
491 return d->running && !
d->isInFinish;
511 "cannot change stack size while the thread is running");
545 d->data->quitNow =
false;
548 return d->returnCode;
553 int returnCode = eventLoop.
exec();
588 d->returnCode = returnCode;
589 d->data->quitNow =
true;
590 for (
int i = 0;
i <
d->data->eventLoops.size(); ++
i) {
592 eventLoop->
exit(returnCode);
647 qWarning(
"QThread::setPriority: Argument cannot be InheritPriority");
653 qWarning(
"QThread::setPriority: Cannot set priority, thread is not running");
809 return d->data->eventLoops.size();
818 d->data->thread.storeRelaxed(
this);
856 d->data->quitNow =
true;
857 for (
int i = 0;
i <
d->data->eventLoops.size(); ++
i) {
859 eventLoop->
exit(returnCode);
874 Qt::HANDLE QThread::currentThreadIdImpl() noexcept
910 if (!
data && createIfNecessary) {
915 data->isAdopted =
true;
936 d->data->thread.storeRelaxed(
this);
945 data->thread.storeRelease(
nullptr);
970 return d->data->eventDispatcher.loadRelaxed();
988 if (
d->data->hasEventDispatcher()) {
989 qWarning(
"QThread::setEventDispatcher: An event dispatcher has already been created for this thread");
995 qWarning(
"QThread::setEventDispatcher: Could not move event dispatcher to target thread");
1007 #if QT_CONFIG(thread)
1038 qWarning(
"QThread::requestInterruption has no effect on the main thread");
1043 if (!
d->running ||
d->finished ||
d->isInFinish)
1045 d->interruptionRequested.store(
true, std::memory_order_relaxed);
1078 if (!
d->interruptionRequested.load(std::memory_order_relaxed))
1082 return d->running && !
d->finished && !
d->isInFinish;
1107 #if QT_CONFIG(cxx11_future)
1108 class QThreadCreateThread :
public QThread
1111 explicit QThreadCreateThread(std::future<void> &&
future)
1116 ~QThreadCreateThread()
1129 std::future<void> m_future;
1132 QThread *QThread::createThreadImpl(std::future<void> &&
future)
1134 return new QThreadCreateThread(std::move(
future));
1154 QDaemonThread::~QDaemonThread()
1162 #include "moc_qthread.cpp"
small capitals from c petite p scientific i
[1]
The QAbstractEventDispatcher class provides an interface to manage Qt's event queue.
QAdoptedThread(QThreadData *data=nullptr)
T loadRelaxed() const noexcept
Type loadAcquire() const noexcept
void storeRelease(Type newValue) noexcept
static QBasicAtomicPointer< QThread > theMainThread
The QDeadlineTimer class marks a deadline in the future.
The QEvent class is the base class of all event classes. Event objects contain event parameters.
The QEventLoop class provides a means of entering and leaving an event loop.
int exec(ProcessEventsFlags flags=AllEvents)
void exit(int returnCode=0)
qsizetype size() const noexcept
const_reference at(qsizetype i) const noexcept
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes.
The QObject class is the base class of all Qt objects.
void moveToThread(QThread *thread)
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
virtual bool event(QEvent *event)
static Q_AUTOTEST_EXPORT QThreadData * current(bool createIfNecessary=true)
QAtomicPointer< QAbstractEventDispatcher > eventDispatcher
bool requiresCoreApplication
QThreadData(int initialRefCount=1)
static void clearCurrentThreadData()
QPostEventList postEventList
QAtomicPointer< QThread > thread
QAbstractEventDispatcher * createEventDispatcher()
bool isInterruptionRequested() const
void start(Priority=InheritPriority)
QAbstractEventDispatcher * eventDispatcher() const
static int idealThreadCount() noexcept
bool event(QEvent *event) override
static QThread * currentThread()
static void yieldCurrentThread()
bool wait(QDeadlineTimer deadline=QDeadlineTimer(QDeadlineTimer::Forever))
QThread(QObject *parent=nullptr)
Priority priority() const
void finished(QPrivateSignal)
void setPriority(Priority priority)
void requestInterruption()
void setStackSize(uint stackSize)
void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher)
void started(QPrivateSignal)
static QAbstractEventDispatcher * createEventDispatcher(QThreadData *data)
QThreadPrivate(QThreadData *d=nullptr)
GLuint64 GLenum void * handle
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
#define Q_ASSERT_X(cond, x, msg)
QFuture< void > future
[5]
QDeadlineTimer deadline(30s)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent