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)
return false;
waitingReaders++;
readerCond.wait(&mutex, timeout - elapsed);
readerCond.wait(&mutex, QDeadlineTimer(timeout - elapsed));
} else {
waitingReaders++;
readerCond.wait(&mutex);
@ -511,7 +511,7 @@ bool QReadWriteLockPrivate::lockForWrite(int timeout)
return false;
}
waitingWriters++;
writerCond.wait(&mutex, timeout - elapsed);
writerCond.wait(&mutex, QDeadlineTimer(timeout - elapsed));
} else {
waitingWriters++;
writerCond.wait(&mutex);

View File

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

View File

@ -136,7 +136,7 @@ void QThreadPoolThread::run()
manager->waitingThreads.enqueue(this);
registerThreadInactive();
// 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;
if (manager->waitingThreads.removeOne(this))
expired = true;

View File

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

View File

@ -119,10 +119,22 @@
\sa wakeOne()
*/
#if QT_DEPRECATED_SINCE(5, 15)
/*!
\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
lockedMutex is not in a locked state, the behavior is undefined. If
\a lockedMutex is a recursive mutex, this function
@ -132,10 +144,10 @@
\list
\li Another thread signals it using wakeOne() or wakeAll(). This
function will return true in this case.
\li \a time milliseconds has elapsed. If \a time is \c ULONG_MAX
(the default), then the wait will never timeout (the event
must be signalled). This function will return false if the
wait timed out.
\li the deadline given by \a deadline is reached. If \a deadline is
\c QDeadlineTimer::Forever (the default), then the wait will never
timeout (the event must be signalled). This function will return
false if the wait timed out.
\endlist
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)
\since 4.4
\fn bool QWaitCondition::wait(QReadWriteLock *lockedReadWriteLock, QDeadlineTimer deadline)
\since 5.12
Releases the \a lockedReadWriteLock and waits on the wait
condition. The \a lockedReadWriteLock must be initially locked by the
@ -160,10 +172,10 @@
\list
\li Another thread signals it using wakeOne() or wakeAll(). This
function will return true in this case.
\li \a time milliseconds has elapsed. If \a time is \c ULONG_MAX
(the default), then the wait will never timeout (the event
must be signalled). This function will return false if the
wait timed out.
\li the deadline given by \a deadline is reached. If \a deadline is
\c QDeadlineTimer::Forever (the default), then the wait will never
timeout (the event must be signalled). This function will return
false if the wait timed out.
\endlist
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");
}
#if QT_DEPRECATED_SINCE(5, 15)
bool QWaitCondition::wait(QMutex *mutex, unsigned long time)
{
if (time == std::numeric_limits<unsigned long>::max())
return wait(mutex, QDeadlineTimer(QDeadlineTimer::Forever));
return wait(mutex, QDeadlineTimer(time));
}
#endif
bool QWaitCondition::wait(QMutex *mutex, QDeadlineTimer deadline)
{
@ -229,12 +231,14 @@ bool QWaitCondition::wait(QMutex *mutex, QDeadlineTimer deadline)
return returnValue;
}
#if QT_DEPRECATED_SINCE(5, 15)
bool QWaitCondition::wait(QReadWriteLock *readWriteLock, unsigned long time)
{
if (time == std::numeric_limits<unsigned long>::max())
return wait(readWriteLock, QDeadlineTimer(QDeadlineTimer::Forever));
return wait(readWriteLock, QDeadlineTimer(time));
}
#endif
bool QWaitCondition::wait(QReadWriteLock *readWriteLock, QDeadlineTimer deadline)
{