QWaitCondition: mark obsolete functions as deprecated

Mark QWaitCondition:wait(..., ulong) as deprecated so they can be
removed in Qt6. Also replace the usages of this deprecated functions
inside QtCore.

Change-Id: I77313255fa05f5c112b0b40d4c55339cc4f85346
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Christian Ehrlicher 2019-11-06 17:59:49 +01:00
parent fa2c9a27e2
commit 72f57cc842
6 changed files with 42 additions and 24 deletions

View File

@ -477,7 +477,7 @@ bool QReadWriteLockPrivate::lockForRead(int timeout)
if (elapsed > timeout) if (elapsed > timeout)
return false; return false;
waitingReaders++; waitingReaders++;
readerCond.wait(&mutex, timeout - elapsed); readerCond.wait(&mutex, QDeadlineTimer(timeout - elapsed));
} else { } else {
waitingReaders++; waitingReaders++;
readerCond.wait(&mutex); readerCond.wait(&mutex);
@ -511,7 +511,7 @@ bool QReadWriteLockPrivate::lockForWrite(int timeout)
return false; return false;
} }
waitingWriters++; waitingWriters++;
writerCond.wait(&mutex, timeout - elapsed); writerCond.wait(&mutex, QDeadlineTimer(timeout - elapsed));
} else { } else {
waitingWriters++; waitingWriters++;
writerCond.wait(&mutex); writerCond.wait(&mutex);

View File

@ -765,7 +765,7 @@ bool QThread::wait(unsigned long time)
return true; return true;
while (d->running) { while (d->running) {
if (!d->thread_done.wait(locker.mutex(), time)) if (!d->thread_done.wait(locker.mutex(), QDeadlineTimer(time)))
return false; return false;
} }
return true; return true;

View File

@ -136,7 +136,7 @@ void QThreadPoolThread::run()
manager->waitingThreads.enqueue(this); manager->waitingThreads.enqueue(this);
registerThreadInactive(); registerThreadInactive();
// wait for work, exiting after the expiry timeout is reached // wait for work, exiting after the expiry timeout is reached
runnableReady.wait(locker.mutex(), manager->expiryTimeout); runnableReady.wait(locker.mutex(), QDeadlineTimer(manager->expiryTimeout));
++manager->activeThreads; ++manager->activeThreads;
if (manager->waitingThreads.removeOne(this)) if (manager->waitingThreads.removeOne(this))
expired = true; expired = true;

View File

@ -40,15 +40,12 @@
#ifndef QWAITCONDITION_H #ifndef QWAITCONDITION_H
#define QWAITCONDITION_H #define QWAITCONDITION_H
#include <QtCore/qglobal.h> #include <QDeadlineTimer>
#include <limits.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
#if QT_CONFIG(thread) #if QT_CONFIG(thread)
class QDeadlineTimer;
class QWaitConditionPrivate; class QWaitConditionPrivate;
class QMutex; class QMutex;
class QReadWriteLock; class QReadWriteLock;
@ -59,11 +56,16 @@ public:
QWaitCondition(); QWaitCondition();
~QWaitCondition(); ~QWaitCondition();
// ### Qt 6: remove unsigned long overloads bool wait(QMutex *lockedMutex,
bool wait(QMutex *lockedMutex, unsigned long time = ULONG_MAX); QDeadlineTimer deadline = QDeadlineTimer(QDeadlineTimer::Forever));
bool wait(QMutex *lockedMutex, QDeadlineTimer deadline); bool wait(QReadWriteLock *lockedReadWriteLock,
bool wait(QReadWriteLock *lockedReadWriteLock, unsigned long time = ULONG_MAX); QDeadlineTimer deadline = QDeadlineTimer(QDeadlineTimer::Forever));
bool wait(QReadWriteLock *lockedReadWriteLock, QDeadlineTimer deadline); #if QT_DEPRECATED_SINCE(5, 15)
QT_DEPRECATED_VERSION_X_5_15("Use wait(QMutex *lockedMutex, QDeadlineTimer deadline) instead")
bool wait(QMutex *lockedMutex, unsigned long time);
QT_DEPRECATED_VERSION_X_5_15("Use wait(QReadWriteLock *lockedReadWriteLock, QDeadlineTimer deadline) instead")
bool wait(QReadWriteLock *lockedReadWriteLock, unsigned long time);
#endif
void wakeOne(); void wakeOne();
void wakeAll(); void wakeAll();

View File

@ -119,10 +119,22 @@
\sa wakeOne() \sa wakeOne()
*/ */
#if QT_DEPRECATED_SINCE(5, 15)
/*! /*!
\fn bool QWaitCondition::wait(QMutex *lockedMutex, unsigned long time) \fn bool QWaitCondition::wait(QMutex *lockedMutex, unsigned long time)
\obsolete use wait(QMutex *lockedMutex, QDeadlineTimer deadline) instead
*/
/*!
\fn bool QWaitCondition::wait(QReadWriteLock *lockedReadWriteLock, unsigned long time)
\obsolete use wait(QReadWriteLock *lockedReadWriteLock, QDeadlineTimer deadline) instead
*/
#endif
Releases the \a lockedMutex and waits on the wait condition. The /*!
\fn bool QWaitCondition::wait(QMutex *lockedMutex, QDeadlineTimer deadline)
\since 5.12
Releases the \a lockedMutex and waits on the wait condition. The
\a lockedMutex must be initially locked by the calling thread. If \a \a lockedMutex must be initially locked by the calling thread. If \a
lockedMutex is not in a locked state, the behavior is undefined. If lockedMutex is not in a locked state, the behavior is undefined. If
\a lockedMutex is a recursive mutex, this function \a lockedMutex is a recursive mutex, this function
@ -132,10 +144,10 @@
\list \list
\li Another thread signals it using wakeOne() or wakeAll(). This \li Another thread signals it using wakeOne() or wakeAll(). This
function will return true in this case. function will return true in this case.
\li \a time milliseconds has elapsed. If \a time is \c ULONG_MAX \li the deadline given by \a deadline is reached. If \a deadline is
(the default), then the wait will never timeout (the event \c QDeadlineTimer::Forever (the default), then the wait will never
must be signalled). This function will return false if the timeout (the event must be signalled). This function will return
wait timed out. false if the wait timed out.
\endlist \endlist
The \a lockedMutex will be returned to the same locked state. This The \a lockedMutex will be returned to the same locked state. This
@ -146,8 +158,8 @@
*/ */
/*! /*!
\fn bool QWaitCondition::wait(QReadWriteLock *lockedReadWriteLock, unsigned long time) \fn bool QWaitCondition::wait(QReadWriteLock *lockedReadWriteLock, QDeadlineTimer deadline)
\since 4.4 \since 5.12
Releases the \a lockedReadWriteLock and waits on the wait Releases the \a lockedReadWriteLock and waits on the wait
condition. The \a lockedReadWriteLock must be initially locked by the condition. The \a lockedReadWriteLock must be initially locked by the
@ -160,10 +172,10 @@
\list \list
\li Another thread signals it using wakeOne() or wakeAll(). This \li Another thread signals it using wakeOne() or wakeAll(). This
function will return true in this case. function will return true in this case.
\li \a time milliseconds has elapsed. If \a time is \c ULONG_MAX \li the deadline given by \a deadline is reached. If \a deadline is
(the default), then the wait will never timeout (the event \c QDeadlineTimer::Forever (the default), then the wait will never
must be signalled). This function will return false if the timeout (the event must be signalled). This function will return
wait timed out. false if the wait timed out.
\endlist \endlist
The \a lockedReadWriteLock will be returned to the same locked The \a lockedReadWriteLock will be returned to the same locked

View File

@ -202,12 +202,14 @@ void QWaitCondition::wakeAll()
report_error(pthread_mutex_unlock(&d->mutex), "QWaitCondition::wakeAll()", "mutex unlock"); report_error(pthread_mutex_unlock(&d->mutex), "QWaitCondition::wakeAll()", "mutex unlock");
} }
#if QT_DEPRECATED_SINCE(5, 15)
bool QWaitCondition::wait(QMutex *mutex, unsigned long time) bool QWaitCondition::wait(QMutex *mutex, unsigned long time)
{ {
if (time == std::numeric_limits<unsigned long>::max()) if (time == std::numeric_limits<unsigned long>::max())
return wait(mutex, QDeadlineTimer(QDeadlineTimer::Forever)); return wait(mutex, QDeadlineTimer(QDeadlineTimer::Forever));
return wait(mutex, QDeadlineTimer(time)); return wait(mutex, QDeadlineTimer(time));
} }
#endif
bool QWaitCondition::wait(QMutex *mutex, QDeadlineTimer deadline) bool QWaitCondition::wait(QMutex *mutex, QDeadlineTimer deadline)
{ {
@ -229,12 +231,14 @@ bool QWaitCondition::wait(QMutex *mutex, QDeadlineTimer deadline)
return returnValue; return returnValue;
} }
#if QT_DEPRECATED_SINCE(5, 15)
bool QWaitCondition::wait(QReadWriteLock *readWriteLock, unsigned long time) bool QWaitCondition::wait(QReadWriteLock *readWriteLock, unsigned long time)
{ {
if (time == std::numeric_limits<unsigned long>::max()) if (time == std::numeric_limits<unsigned long>::max())
return wait(readWriteLock, QDeadlineTimer(QDeadlineTimer::Forever)); return wait(readWriteLock, QDeadlineTimer(QDeadlineTimer::Forever));
return wait(readWriteLock, QDeadlineTimer(time)); return wait(readWriteLock, QDeadlineTimer(time));
} }
#endif
bool QWaitCondition::wait(QReadWriteLock *readWriteLock, QDeadlineTimer deadline) bool QWaitCondition::wait(QReadWriteLock *readWriteLock, QDeadlineTimer deadline)
{ {