From f5a0e3f1f4787b6a48880e42463ae38dce336a8f Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Mon, 1 Dec 2014 11:36:31 +0100 Subject: [PATCH 15/30] Use QMutexLocker instead of manual lock/unlock calls. Just a minor cleanup patch, no change of behavior. --- server/src/storage/entities-source.xsl | 17 +++++------------ server/src/storage/entities.xsl | 4 +--- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/server/src/storage/entities-source.xsl b/server/src/storage/entities-source.xsl index 7090c31..05a8cb1 100644 --- a/server/src/storage/entities-source.xsl +++ b/server/src/storage/entities-source.xsl @@ -125,14 +125,13 @@ void ::Private::addToCache( const - cacheMutex.lock(); + QMutexLocker lock(&cacheMutex); idCache.insert( entry.id(), entry ); nameCache.insert( entry.name(), entry ); - cacheMutex.unlock(); } @@ -264,12 +263,10 @@ int ::count( const QString &column, const bool ::exists( qint64 id ) { if ( Private::cacheEnabled ) { - Private::cacheMutex.lock(); + QMutexLocker lock(&Private::cacheMutex); if ( Private::idCache.contains( id ) ) { - Private::cacheMutex.unlock(); return true; } - Private::cacheMutex.unlock(); } return count( idColumn(), id ) > 0; } @@ -278,12 +275,10 @@ bool ::exists( qint64 id ) bool ::exists( const &name ) { if ( Private::cacheEnabled ) { - Private::cacheMutex.lock(); + QMutexLocker lock(&Private::cacheMutex); if ( Private::nameCache.contains( name ) ) { - Private::cacheMutex.unlock(); return true; } - Private::cacheMutex.unlock(); } return count( nameColumn(), name ) > 0; } @@ -588,28 +583,26 @@ bool ::remove( qint64 id ) void ::invalidateCache() const { if ( Private::cacheEnabled ) { - Private::cacheMutex.lock(); + QMutexLocker lock(&Private::cacheMutex); Private::idCache.remove( id() ); Private::nameCache.remove( name() ); - Private::cacheMutex.unlock(); } } void ::invalidateCompleteCache() { if ( Private::cacheEnabled ) { - Private::cacheMutex.lock(); + QMutexLocker lock(&Private::cacheMutex); Private::idCache.clear(); Private::nameCache.clear(); - Private::cacheMutex.unlock(); } } diff --git a/server/src/storage/entities.xsl b/server/src/storage/entities.xsl index 8b0ed03..a397544 100644 --- a/server/src/storage/entities.xsl +++ b/server/src/storage/entities.xsl @@ -167,13 +167,11 @@ set( ) if ( Private::cacheEnabled ) { - Private::cacheMutex.lock(); + QMutexLocker lock(&Private::cacheMutex); if ( Private::.contains( ) ) { const tmp = Private::.value( ); - Private::cacheMutex.unlock(); return tmp; } - Private::cacheMutex.unlock(); } QSqlDatabase db = DataStore::self()->database(); -- 2.1.0