Make the stub implementation of QThread compile again
We cannot inline methods of QThreadPrivate because QThreadData has to be declared before. The global QThreadData needs to be accessible to QThreadData::clearCurrentThreadData(), and QAdoptedThread::run() has to be moved inside the #ifndef QT_NO_THREAD block as run() doesn't exist in the stub and Q_DECL_OVERRIDE would be wrong. We also fix the QThreadData::current() method to take and use the same parameters as in the non-stub case. Change-Id: Id29ca44b11fa95ed2df7cc39243a07ce7d3c455e Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
parent
31023ef553
commit
99d4f0026f
@ -140,12 +140,13 @@ QAdoptedThread::~QAdoptedThread()
|
||||
// fprintf(stderr, "~QAdoptedThread = %p\n", this);
|
||||
}
|
||||
|
||||
#ifndef QT_NO_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
|
||||
*/
|
||||
@ -750,7 +751,8 @@ int QThread::loopLevel() const
|
||||
#else // QT_NO_THREAD
|
||||
|
||||
QThread::QThread(QObject *parent)
|
||||
: QObject(*(new QThreadPrivate), (QObject*)0){
|
||||
: QObject(*(new QThreadPrivate), parent)
|
||||
{
|
||||
Q_D(QThread);
|
||||
d->data->thread = this;
|
||||
}
|
||||
@ -760,18 +762,27 @@ QThread *QThread::currentThread()
|
||||
return QThreadData::current()->thread;
|
||||
}
|
||||
|
||||
QThreadData* QThreadData::current()
|
||||
// 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->deref();
|
||||
if (!QCoreApplicationPrivate::theMainThread)
|
||||
QCoreApplicationPrivate::theMainThread = data->thread.load();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
void QThreadData::clearCurrentThreadData()
|
||||
{
|
||||
delete data;
|
||||
data = 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
*/
|
||||
@ -783,6 +794,15 @@ QThread::QThread(QThreadPrivate &dd, QObject *parent)
|
||||
d->data->thread = this;
|
||||
}
|
||||
|
||||
QThreadPrivate::QThreadPrivate(QThreadData *d) : data(d ? d : new QThreadData)
|
||||
{
|
||||
}
|
||||
|
||||
QThreadPrivate::~QThreadPrivate()
|
||||
{
|
||||
delete data;
|
||||
}
|
||||
|
||||
#endif // QT_NO_THREAD
|
||||
|
||||
/*!
|
||||
@ -820,6 +840,8 @@ void QThread::setEventDispatcher(QAbstractEventDispatcher *eventDispatcher)
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef QT_NO_THREAD
|
||||
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
@ -983,6 +1005,8 @@ QDaemonThread::~QDaemonThread()
|
||||
{
|
||||
}
|
||||
|
||||
#endif // QT_NO_THREAD
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "moc_qthread.cpp"
|
||||
|
@ -251,6 +251,9 @@ public:
|
||||
static void msleep(unsigned long);
|
||||
static void usleep(unsigned long);
|
||||
|
||||
QAbstractEventDispatcher *eventDispatcher() const;
|
||||
void setEventDispatcher(QAbstractEventDispatcher *eventDispatcher);
|
||||
|
||||
protected:
|
||||
QThread(QThreadPrivate &dd, QObject *parent = nullptr);
|
||||
|
||||
|
@ -215,9 +215,10 @@ public:
|
||||
class QThreadPrivate : public QObjectPrivate
|
||||
{
|
||||
public:
|
||||
QThreadPrivate(QThreadData *d = 0) : data(d ? d : new QThreadData) {}
|
||||
~QThreadPrivate() { delete data; }
|
||||
QThreadPrivate(QThreadData *d = 0);
|
||||
~QThreadPrivate();
|
||||
|
||||
mutable QMutex mutex;
|
||||
QThreadData *data;
|
||||
|
||||
static void setCurrentThread(QThread*) {}
|
||||
@ -318,7 +319,9 @@ public:
|
||||
void init();
|
||||
|
||||
private:
|
||||
#ifndef QT_NO_THREAD
|
||||
void run() override;
|
||||
#endif
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
Loading…
Reference in New Issue
Block a user