Make the sleep methods available in QThread even if QT_NO_THREAD

sleep, msleep, and usleep are not actually related to threading and
serve a purpose also in a single threaded application.

Change-Id: Iba2e343d48a9c09e60125bc1b589047e0241608a
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Ulf Hermann 2017-01-02 17:23:14 +01:00
parent 47aebe3587
commit 31023ef553
3 changed files with 16 additions and 2 deletions

View File

@ -247,6 +247,10 @@ public:
static Qt::HANDLE currentThreadId() { return Qt::HANDLE(currentThread()); }
static QThread* currentThread();
static void sleep(unsigned long);
static void msleep(unsigned long);
static void usleep(unsigned long);
protected:
QThread(QThreadPrivate &dd, QObject *parent = nullptr);

View File

@ -519,6 +519,8 @@ void QThread::yieldCurrentThread()
sched_yield();
}
#endif // QT_NO_THREAD
static timespec makeTimespec(time_t secs, long nsecs)
{
struct timespec ts;
@ -542,6 +544,8 @@ void QThread::usleep(unsigned long usecs)
qt_nanosleep(makeTimespec(usecs / 1000 / 1000, usecs % (1000*1000) * 1000));
}
#ifndef QT_NO_THREAD
#ifdef QT_HAS_THREAD_PRIORITY_SCHEDULING
#if defined(Q_OS_QNX)
static bool calculateUnixPriority(int priority, int *sched_policy, int *sched_priority)

View File

@ -61,9 +61,10 @@
# include <process.h>
#endif // Q_OS_WINRT
#ifndef QT_NO_THREAD
QT_BEGIN_NAMESPACE
#ifndef QT_NO_THREAD
#ifdef Q_OS_WINRT
inline DWORD qWinRTTlsAlloc() {
return FlsAlloc(0);
@ -449,6 +450,8 @@ void QThread::yieldCurrentThread()
#endif
}
#endif // QT_NO_THREAD
void QThread::sleep(unsigned long secs)
{
::Sleep(secs * 1000);
@ -464,6 +467,8 @@ void QThread::usleep(unsigned long usecs)
::Sleep((usecs / 1000) + 1);
}
#ifndef QT_NO_THREAD
void QThread::start(Priority priority)
{
Q_D(QThread);
@ -700,5 +705,6 @@ void QThreadPrivate::setPriority(QThread::Priority threadPriority)
}
}
QT_END_NAMESPACE
#endif // QT_NO_THREAD
QT_END_NAMESPACE