mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-24 19:02:59 +00:00
assume const methods are thread-safe and avoid locking where possible
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
parent
d63af47325
commit
2afcd5ba4d
10 changed files with 56 additions and 50 deletions
|
@ -175,19 +175,16 @@ int QFutureInterfaceBase::progressMaximum() const
|
|||
|
||||
int QFutureInterfaceBase::resultCount() const
|
||||
{
|
||||
QMutexLocker lock(&d->m_mutex);
|
||||
return d->internal_resultCount();
|
||||
}
|
||||
|
||||
QString QFutureInterfaceBase::progressText() const
|
||||
{
|
||||
QMutexLocker locker(&d->m_mutex);
|
||||
return d->m_progressText;
|
||||
}
|
||||
|
||||
bool QFutureInterfaceBase::isProgressUpdateNeeded() const
|
||||
{
|
||||
QMutexLocker locker(&d->m_mutex);
|
||||
return !d->progressTime.isValid() || (d->progressTime.elapsed() > (1000 / MaxProgressEmitsPerSecond));
|
||||
}
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ public:
|
|||
QFutureInterfaceBasePrivate(QFutureInterfaceBase::State initialState);
|
||||
|
||||
QAtomicInt refCount;
|
||||
mutable QMutex m_mutex;
|
||||
QMutex m_mutex;
|
||||
QWaitCondition waitCondition;
|
||||
QList<QFutureCallOutInterface *> outputConnections;
|
||||
int m_progressValue;
|
||||
|
|
|
@ -579,7 +579,6 @@ void QThreadPool::setMaxThreadCount(int maxThreadCount)
|
|||
int QThreadPool::activeThreadCount() const
|
||||
{
|
||||
Q_D(const QThreadPool);
|
||||
QMutexLocker locker(&d->mutex);
|
||||
return d->activeThreadCount();
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ public:
|
|||
bool startFrontRunnable();
|
||||
void stealRunnable(QRunnable *);
|
||||
|
||||
mutable QMutex mutex;
|
||||
QMutex mutex;
|
||||
QSet<QThreadPoolThread *> allThreads;
|
||||
QQueue<QThreadPoolThread *> waitingThreads;
|
||||
QQueue<QThreadPoolThread *> expiredThreads;
|
||||
|
|
|
@ -4281,7 +4281,6 @@ bool QUrl::isEmpty() const
|
|||
{
|
||||
if (!d) return true;
|
||||
|
||||
QMutexLocker lock(&d->mutex);
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed))
|
||||
return d->encodedOriginal.isEmpty();
|
||||
else
|
||||
|
@ -4953,8 +4952,10 @@ QByteArray QUrl::encodedPath() const
|
|||
bool QUrl::hasQuery() const
|
||||
{
|
||||
if (!d) return false;
|
||||
QMutexLocker lock(&d->mutex);
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) {
|
||||
QMutexLocker lock(&d->mutex);
|
||||
d->parse();
|
||||
}
|
||||
|
||||
return d->hasQuery;
|
||||
}
|
||||
|
@ -5194,8 +5195,10 @@ void QUrl::addEncodedQueryItem(const QByteArray &key, const QByteArray &value)
|
|||
QList<QPair<QString, QString> > QUrl::queryItems() const
|
||||
{
|
||||
if (!d) return QList<QPair<QString, QString> >();
|
||||
QMutexLocker lock(&d->mutex);
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) {
|
||||
QMutexLocker lock(&d->mutex);
|
||||
d->parse();
|
||||
}
|
||||
|
||||
QList<QPair<QString, QString> > itemMap;
|
||||
|
||||
|
@ -5228,8 +5231,10 @@ QList<QPair<QString, QString> > QUrl::queryItems() const
|
|||
QList<QPair<QByteArray, QByteArray> > QUrl::encodedQueryItems() const
|
||||
{
|
||||
if (!d) return QList<QPair<QByteArray, QByteArray> >();
|
||||
QMutexLocker lock(&d->mutex);
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) {
|
||||
QMutexLocker lock(&d->mutex);
|
||||
d->parse();
|
||||
}
|
||||
|
||||
QList<QPair<QByteArray, QByteArray> > itemMap;
|
||||
|
||||
|
@ -5277,8 +5282,10 @@ bool QUrl::hasQueryItem(const QString &key) const
|
|||
bool QUrl::hasEncodedQueryItem(const QByteArray &key) const
|
||||
{
|
||||
if (!d) return false;
|
||||
QMutexLocker lock(&d->mutex);
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) {
|
||||
QMutexLocker lock(&d->mutex);
|
||||
d->parse();
|
||||
}
|
||||
|
||||
int pos = 0;
|
||||
const char *query = d->query.constData();
|
||||
|
@ -5325,8 +5332,10 @@ QString QUrl::queryItemValue(const QString &key) const
|
|||
QByteArray QUrl::encodedQueryItemValue(const QByteArray &key) const
|
||||
{
|
||||
if (!d) return QByteArray();
|
||||
QMutexLocker lock(&d->mutex);
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) {
|
||||
QMutexLocker lock(&d->mutex);
|
||||
d->parse();
|
||||
}
|
||||
|
||||
int pos = 0;
|
||||
const char *query = d->query.constData();
|
||||
|
@ -5354,8 +5363,10 @@ QByteArray QUrl::encodedQueryItemValue(const QByteArray &key) const
|
|||
QStringList QUrl::allQueryItemValues(const QString &key) const
|
||||
{
|
||||
if (!d) return QStringList();
|
||||
QMutexLocker lock(&d->mutex);
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) {
|
||||
QMutexLocker lock(&d->mutex);
|
||||
d->parse();
|
||||
}
|
||||
|
||||
QByteArray encodedKey = toPercentEncoding(key, queryExcludeChars);
|
||||
QStringList values;
|
||||
|
@ -5393,8 +5404,10 @@ QStringList QUrl::allQueryItemValues(const QString &key) const
|
|||
QList<QByteArray> QUrl::allEncodedQueryItemValues(const QByteArray &key) const
|
||||
{
|
||||
if (!d) return QList<QByteArray>();
|
||||
QMutexLocker lock(&d->mutex);
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) {
|
||||
QMutexLocker lock(&d->mutex);
|
||||
d->parse();
|
||||
}
|
||||
|
||||
QList<QByteArray> values;
|
||||
|
||||
|
@ -5514,8 +5527,10 @@ void QUrl::removeAllEncodedQueryItems(const QByteArray &key)
|
|||
QByteArray QUrl::encodedQuery() const
|
||||
{
|
||||
if (!d) return QByteArray();
|
||||
QMutexLocker lock(&d->mutex);
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) {
|
||||
QMutexLocker lock(&d->mutex);
|
||||
d->parse();
|
||||
}
|
||||
|
||||
return d->query;
|
||||
}
|
||||
|
@ -5635,8 +5650,10 @@ QByteArray QUrl::encodedFragment() const
|
|||
bool QUrl::hasFragment() const
|
||||
{
|
||||
if (!d) return false;
|
||||
QMutexLocker lock(&d->mutex);
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) {
|
||||
QMutexLocker lock(&d->mutex);
|
||||
d->parse();
|
||||
}
|
||||
|
||||
return d->hasFragment;
|
||||
}
|
||||
|
@ -5739,8 +5756,10 @@ QUrl QUrl::resolved(const QUrl &relative) const
|
|||
bool QUrl::isRelative() const
|
||||
{
|
||||
if (!d) return true;
|
||||
QMutexLocker lock(&d->mutex);
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) {
|
||||
QMutexLocker lock(&d->mutex);
|
||||
d->parse();
|
||||
}
|
||||
|
||||
return d->scheme.isEmpty();
|
||||
}
|
||||
|
@ -6228,8 +6247,10 @@ QString QUrl::toLocalFile() const
|
|||
bool QUrl::isLocalFile() const
|
||||
{
|
||||
if (!d) return false;
|
||||
QMutexLocker lock(&d->mutex);
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) {
|
||||
QMutexLocker lock(&d->mutex);
|
||||
d->parse();
|
||||
}
|
||||
|
||||
if (d->scheme.compare(QLatin1String("file"), Qt::CaseInsensitive) != 0)
|
||||
return false; // not file
|
||||
|
@ -6250,9 +6271,10 @@ bool QUrl::isParentOf(const QUrl &childUrl) const
|
|||
&& (childUrl.authority().isEmpty())
|
||||
&& childPath.length() > 0 && childPath.at(0) == QLatin1Char('/'));
|
||||
|
||||
QMutexLocker lock(&d->mutex);
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
|
||||
lock.unlock();
|
||||
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) {
|
||||
QMutexLocker lock(&d->mutex);
|
||||
d->parse();
|
||||
}
|
||||
|
||||
QString ourPath = path();
|
||||
|
||||
|
|
|
@ -425,7 +425,6 @@ QThread::~QThread()
|
|||
bool QThread::isFinished() const
|
||||
{
|
||||
Q_D(const QThread);
|
||||
QMutexLocker locker(&d->mutex);
|
||||
return d->finished || d->isInFinish;
|
||||
}
|
||||
|
||||
|
@ -437,7 +436,6 @@ bool QThread::isFinished() const
|
|||
bool QThread::isRunning() const
|
||||
{
|
||||
Q_D(const QThread);
|
||||
QMutexLocker locker(&d->mutex);
|
||||
return d->running && !d->isInFinish;
|
||||
}
|
||||
|
||||
|
@ -471,7 +469,6 @@ void QThread::setStackSize(uint stackSize)
|
|||
uint QThread::stackSize() const
|
||||
{
|
||||
Q_D(const QThread);
|
||||
QMutexLocker locker(&d->mutex);
|
||||
return d->stackSize;
|
||||
}
|
||||
|
||||
|
@ -610,8 +607,6 @@ void QThread::run()
|
|||
QThread::Priority QThread::priority() const
|
||||
{
|
||||
Q_D(const QThread);
|
||||
QMutexLocker locker(&d->mutex);
|
||||
|
||||
// mask off the high bits that are used for flags
|
||||
return Priority(d->priority & 0xffff);
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ public:
|
|||
QThreadPrivate(QThreadData *d = Q_NULLPTR);
|
||||
~QThreadPrivate();
|
||||
|
||||
mutable QMutex mutex;
|
||||
QMutex mutex;
|
||||
|
||||
bool running;
|
||||
bool finished;
|
||||
|
|
|
@ -326,7 +326,6 @@ bool QDBusPendingCall::isFinished() const
|
|||
if (!d)
|
||||
return true; // considered finished
|
||||
|
||||
QMutexLocker locker(&d->mutex);
|
||||
return d->replyMessage.type() != QDBusMessage::InvalidMessage;
|
||||
}
|
||||
|
||||
|
@ -348,7 +347,6 @@ bool QDBusPendingCall::isValid() const
|
|||
{
|
||||
if (!d)
|
||||
return false;
|
||||
QMutexLocker locker(&d->mutex);
|
||||
return d->replyMessage.type() == QDBusMessage::ReplyMessage;
|
||||
}
|
||||
|
||||
|
@ -365,7 +363,6 @@ bool QDBusPendingCall::isError() const
|
|||
{
|
||||
if (!d)
|
||||
return true; // considered finished and an error
|
||||
QMutexLocker locker(&d->mutex);
|
||||
return d->replyMessage.type() == QDBusMessage::ErrorMessage;
|
||||
}
|
||||
|
||||
|
@ -380,14 +377,12 @@ bool QDBusPendingCall::isError() const
|
|||
QDBusError QDBusPendingCall::error() const
|
||||
{
|
||||
if (d) {
|
||||
QMutexLocker locker(&d->mutex);
|
||||
return d->replyMessage;
|
||||
}
|
||||
|
||||
// not connected, return an error
|
||||
QDBusError err = QDBusError(QDBusError::Disconnected,
|
||||
QLatin1String("Not connected to D-Bus server"));
|
||||
return err;
|
||||
return QDBusError(QDBusError::Disconnected,
|
||||
QLatin1String("Not connected to D-Bus server"));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -405,7 +400,6 @@ QDBusMessage QDBusPendingCall::reply() const
|
|||
{
|
||||
if (!d)
|
||||
return QDBusMessage::createError(error());
|
||||
QMutexLocker locker(&d->mutex);
|
||||
return d->replyMessage;
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ public:
|
|||
|
||||
// }
|
||||
|
||||
mutable QMutex mutex;
|
||||
QMutex mutex;
|
||||
QWaitCondition waitForFinishedCondition;
|
||||
|
||||
// {
|
||||
|
|
|
@ -207,8 +207,7 @@ class QGraphicsWidgetStyles
|
|||
public:
|
||||
QStyle *styleForWidget(const QGraphicsWidget *widget) const
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
return styles.value(widget, 0);
|
||||
return styles.value(widget, Q_NULLPTR);
|
||||
}
|
||||
|
||||
void setStyleForWidget(QGraphicsWidget *widget, QStyle *style)
|
||||
|
@ -222,7 +221,7 @@ public:
|
|||
|
||||
private:
|
||||
QMap<const QGraphicsWidget *, QStyle *> styles;
|
||||
mutable QMutex mutex;
|
||||
QMutex mutex;
|
||||
};
|
||||
Q_GLOBAL_STATIC(QGraphicsWidgetStyles, widgetStyles)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue