1 From f5a0e3f1f4787b6a48880e42463ae38dce336a8f Mon Sep 17 00:00:00 2001
2 From: Milian Wolff <mail@milianw.de>
3 Date: Mon, 1 Dec 2014 11:36:31 +0100
4 Subject: [PATCH 15/30] Use QMutexLocker instead of manual lock/unlock calls.
6 Just a minor cleanup patch, no change of behavior.
8 server/src/storage/entities-source.xsl | 17 +++++------------
9 server/src/storage/entities.xsl | 4 +---
10 2 files changed, 6 insertions(+), 15 deletions(-)
12 diff --git a/server/src/storage/entities-source.xsl b/server/src/storage/entities-source.xsl
13 index 7090c31..05a8cb1 100644
14 --- a/server/src/storage/entities-source.xsl
15 +++ b/server/src/storage/entities-source.xsl
16 @@ -125,14 +125,13 @@ void <xsl:value-of select="$className"/>::Private::addToCache( const <xsl:value-
18 Q_ASSERT( cacheEnabled );
19 Q_UNUSED( entry ); <!-- in case the table has neither an id nor name column -->
21 + QMutexLocker lock(&cacheMutex);
22 <xsl:if test="column[@name = 'id']">
23 idCache.insert( entry.id(), entry );
25 <xsl:if test="column[@name = 'name']">
26 nameCache.insert( entry.name(), entry );
28 - cacheMutex.unlock();
32 @@ -264,12 +263,10 @@ int <xsl:value-of select="$className"/>::count( const QString &column, const
33 bool <xsl:value-of select="$className"/>::exists( qint64 id )
35 if ( Private::cacheEnabled ) {
36 - Private::cacheMutex.lock();
37 + QMutexLocker lock(&Private::cacheMutex);
38 if ( Private::idCache.contains( id ) ) {
39 - Private::cacheMutex.unlock();
42 - Private::cacheMutex.unlock();
44 return count( idColumn(), id ) > 0;
46 @@ -278,12 +275,10 @@ bool <xsl:value-of select="$className"/>::exists( qint64 id )
47 bool <xsl:value-of select="$className"/>::exists( const <xsl:value-of select="column[@name = 'name']/@type"/> &name )
49 if ( Private::cacheEnabled ) {
50 - Private::cacheMutex.lock();
51 + QMutexLocker lock(&Private::cacheMutex);
52 if ( Private::nameCache.contains( name ) ) {
53 - Private::cacheMutex.unlock();
56 - Private::cacheMutex.unlock();
58 return count( nameColumn(), name ) > 0;
60 @@ -588,28 +583,26 @@ bool <xsl:value-of select="$className"/>::remove( qint64 id )
61 void <xsl:value-of select="$className"/>::invalidateCache() const
63 if ( Private::cacheEnabled ) {
64 - Private::cacheMutex.lock();
65 + QMutexLocker lock(&Private::cacheMutex);
66 <xsl:if test="column[@name = 'id']">
67 Private::idCache.remove( id() );
69 <xsl:if test="column[@name = 'name']">
70 Private::nameCache.remove( name() );
72 - Private::cacheMutex.unlock();
76 void <xsl:value-of select="$className"/>::invalidateCompleteCache()
78 if ( Private::cacheEnabled ) {
79 - Private::cacheMutex.lock();
80 + QMutexLocker lock(&Private::cacheMutex);
81 <xsl:if test="column[@name = 'id']">
82 Private::idCache.clear();
84 <xsl:if test="column[@name = 'name']">
85 Private::nameCache.clear();
87 - Private::cacheMutex.unlock();
91 diff --git a/server/src/storage/entities.xsl b/server/src/storage/entities.xsl
92 index 8b0ed03..a397544 100644
93 --- a/server/src/storage/entities.xsl
94 +++ b/server/src/storage/entities.xsl
95 @@ -167,13 +167,11 @@ set<xsl:value-of select="$methodName"/>( <xsl:call-template name="argument"/> )
96 <xsl:variable name="className"><xsl:value-of select="@name"/></xsl:variable>
97 <xsl:if test="$cache != ''">
98 if ( Private::cacheEnabled ) {
99 - Private::cacheMutex.lock();
100 + QMutexLocker lock(&Private::cacheMutex);
101 if ( Private::<xsl:value-of select="$cache"/>.contains( <xsl:value-of select="$key"/> ) ) {
102 const <xsl:value-of select="$className"/> tmp = Private::<xsl:value-of select="$cache"/>.value( <xsl:value-of select="$key"/> );
103 - Private::cacheMutex.unlock();
106 - Private::cacheMutex.unlock();
109 QSqlDatabase db = DataStore::self()->database();