summaryrefslogtreecommitdiffstats
path: root/src/corelib/thread/qthread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/thread/qthread.cpp')
-rw-r--r--src/corelib/thread/qthread.cpp129
1 files changed, 116 insertions, 13 deletions
diff --git a/src/corelib/thread/qthread.cpp b/src/corelib/thread/qthread.cpp
index 23606411ff..5df0508829 100644
--- a/src/corelib/thread/qthread.cpp
+++ b/src/corelib/thread/qthread.cpp
@@ -103,7 +103,7 @@ QThreadData::~QThreadData()
void QThreadData::ref()
{
-#ifndef QT_NO_THREAD
+#if QT_CONFIG(thread)
(void) _ref.ref();
Q_ASSERT(_ref.load() != 0);
#endif
@@ -111,12 +111,20 @@ void QThreadData::ref()
void QThreadData::deref()
{
-#ifndef QT_NO_THREAD
+#if QT_CONFIG(thread)
if (!_ref.deref())
delete this;
#endif
}
+QAbstractEventDispatcher *QThreadData::createEventDispatcher()
+{
+ QAbstractEventDispatcher *ed = QThreadPrivate::createEventDispatcher(this);
+ eventDispatcher.storeRelease(ed);
+ ed->startingUp();
+ return ed;
+}
+
/*
QAdoptedThread
*/
@@ -126,7 +134,7 @@ QAdoptedThread::QAdoptedThread(QThreadData *data)
{
// thread should be running and not finished for the lifetime
// of the application (even if QCoreApplication goes away)
-#ifndef QT_NO_THREAD
+#if QT_CONFIG(thread)
d_func()->running = true;
d_func()->finished = false;
init();
@@ -140,12 +148,13 @@ QAdoptedThread::~QAdoptedThread()
// fprintf(stderr, "~QAdoptedThread = %p\n", this);
}
+#if QT_CONFIG(thread)
void QAdoptedThread::run()
{
// this function should never be called
qFatal("QAdoptedThread::run(): Internal error, this implementation should never be called.");
}
-#ifndef QT_NO_THREAD
+
/*
QThreadPrivate
*/
@@ -747,31 +756,112 @@ int QThread::loopLevel() const
return d->data->eventLoops.size();
}
-#else // QT_NO_THREAD
+#else // QT_CONFIG(thread)
QThread::QThread(QObject *parent)
- : QObject(*(new QThreadPrivate), (QObject*)0){
+ : QObject(*(new QThreadPrivate), parent)
+{
Q_D(QThread);
d->data->thread = this;
}
+QThread::~QThread()
+{
+
+}
+
+void QThread::run()
+{
+
+}
+
+int QThread::exec()
+{
+ return 0;
+}
+
+void QThread::start(Priority priority)
+{
+ Q_D(QThread);
+ Q_UNUSED(priority);
+ d->running = true;
+}
+
+void QThread::terminate()
+{
+
+}
+
+void QThread::quit()
+{
+
+}
+
+bool QThread::wait(unsigned long time)
+{
+ Q_UNUSED(time);
+ return false;
+}
+
+bool QThread::event(QEvent* event)
+{
+ return QObject::event(event);
+}
+
+Qt::HANDLE QThread::currentThreadId() Q_DECL_NOTHROW
+{
+ return Qt::HANDLE(currentThread());
+}
+
QThread *QThread::currentThread()
{
return QThreadData::current()->thread;
}
-QThreadData* QThreadData::current()
+int QThread::idealThreadCount() Q_DECL_NOTHROW
+{
+ return 1;
+}
+
+void QThread::yieldCurrentThread()
+{
+
+}
+
+bool QThread::isFinished() const
+{
+ return false;
+}
+
+bool QThread::isRunning() const
+{
+ Q_D(const QThread);
+ return d->running;
+}
+
+// No threads: so we can just use static variables
+static QThreadData *data = 0;
+
+QThreadData *QThreadData::current(bool createIfNecessary)
{
- static QThreadData *data = 0; // reinterpret_cast<QThreadData *>(pthread_getspecific(current_thread_data_key));
- if (!data) {
- QScopedPointer<QThreadData> newdata(new QThreadData);
- newdata->thread = new QAdoptedThread(newdata.data());
- data = newdata.take();
+ if (!data && createIfNecessary) {
+ data = new QThreadData;
+ data->thread = new QAdoptedThread(data);
+ data->threadId.store(Qt::HANDLE(data->thread));
data->deref();
+ data->isAdopted = true;
+ if (!QCoreApplicationPrivate::theMainThread)
+ QCoreApplicationPrivate::theMainThread = data->thread.load();
}
return data;
}
+void QThreadData::clearCurrentThreadData()
+{
+ delete data;
+ data = 0;
+}
+
/*!
\internal
*/
@@ -783,7 +873,16 @@ QThread::QThread(QThreadPrivate &dd, QObject *parent)
d->data->thread = this;
}
-#endif // QT_NO_THREAD
+QThreadPrivate::QThreadPrivate(QThreadData *d) : data(d ? d : new QThreadData)
+{
+}
+
+QThreadPrivate::~QThreadPrivate()
+{
+ delete data;
+}
+
+#endif // QT_CONFIG(thread)
/*!
\since 5.0
@@ -820,6 +919,8 @@ void QThread::setEventDispatcher(QAbstractEventDispatcher *eventDispatcher)
}
}
+#if QT_CONFIG(thread)
+
/*!
\reimp
*/
@@ -983,6 +1084,8 @@ QDaemonThread::~QDaemonThread()
{
}
+#endif // QT_CONFIG(thread)
+
QT_END_NAMESPACE
#include "moc_qthread.cpp"