diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2013-11-25 18:11:37 +0400 |
---|---|---|
committer | Olivier Goffart <ogoffart@woboq.com> | 2013-11-25 18:11:37 +0400 |
commit | 6f17131e3c9241eaaa3c616f3b446894f4581a2c (patch) | |
tree | f9c17eced86478e76c2c05ff194a9b7efd23c8ec /src | |
parent | ca3885de2a2dde8965a5df670e360bce2d887bc0 (diff) |
Fix mutex usage in the journal
All public function must lock the mutex. And therefore none of the journal
function may call public function because the mutex is already locked.
So have a public commit that lock the mutex, and a private commitInternal
that assume the mutex is locked
Diffstat (limited to 'src')
-rw-r--r-- | src/mirall/syncjournaldb.cpp | 14 | ||||
-rw-r--r-- | src/mirall/syncjournaldb.h | 7 |
2 files changed, 15 insertions, 6 deletions
diff --git a/src/mirall/syncjournaldb.cpp b/src/mirall/syncjournaldb.cpp index dff57ec80..ca88b8ce7 100644 --- a/src/mirall/syncjournaldb.cpp +++ b/src/mirall/syncjournaldb.cpp @@ -189,7 +189,7 @@ bool SyncJournalDb::checkConnect() return sqlFail("Create table blacklist", createQuery); } - commit("checkConnect"); + commitInternal("checkConnect"); bool rc = updateDatabaseStructure(); if( rc ) { @@ -282,7 +282,7 @@ bool SyncJournalDb::updateDatabaseStructure() query.prepare("CREATE INDEX metadata_file_id ON metadata(fileid);"); re = re && query.exec(); - commit("update database structure"); + commitInternal("update database structure"); } return re; @@ -735,9 +735,17 @@ void SyncJournalDb::updateBlacklistEntry( const SyncJournalBlacklistRecord& item if( !iQuery.exec() ) { qDebug() << "SQL exec blacklistitem insert/update failed: "<< iQuery.lastError().text(); } + } -void SyncJournalDb::commit(const QString& context, bool startTrans ) +void SyncJournalDb::commit(const QString& context, bool startTrans) +{ + QMutexLocker lock(&_mutex); + commitInternal(context, startTrans); +} + + +void SyncJournalDb::commitInternal(const QString& context, bool startTrans ) { qDebug() << "Transaction Start " << context; commitTransaction(); diff --git a/src/mirall/syncjournaldb.h b/src/mirall/syncjournaldb.h index e6f0b4b2a..fbc3f6221 100644 --- a/src/mirall/syncjournaldb.h +++ b/src/mirall/syncjournaldb.h @@ -36,7 +36,6 @@ public: bool deleteFileRecord( const QString& filename, bool recursively = false ); int getFileRecordCount(); bool exists(); - QStringList tableColumns( const QString& table ); void updateBlacklistEntry( const SyncJournalBlacklistRecord& item ); void wipeBlacklistEntry(const QString& file); @@ -72,8 +71,6 @@ public: void close(); - void startTransaction(); - void commitTransaction(); signals: @@ -83,6 +80,10 @@ private: qint64 getPHash(const QString& ) const; bool updateDatabaseStructure(); bool sqlFail(const QString& log, const QSqlQuery &query ); + void commitInternal(const QString &context, bool startTrans = true); + void startTransaction(); + void commitTransaction(); + QStringList tableColumns( const QString& table ); bool checkConnect(); QSqlDatabase _db; |