From 3166ca21277d39b50de0271c26e9e9aea0a3569b Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Tue, 22 Sep 2020 18:58:44 +0200 Subject: [PATCH] Use QRecursiveMutex --- src/core/database.cpp | 2 ++ src/core/database.h | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/core/database.cpp b/src/core/database.cpp index 6399bcd1e..334625ac6 100644 --- a/src/core/database.cpp +++ b/src/core/database.cpp @@ -63,7 +63,9 @@ QMutex Database::sNextConnectionIdMutex; Database::Database(Application *app, QObject *parent, const QString &database_name) : QObject(parent), app_(app), +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) mutex_(QMutex::Recursive), +#endif injected_database_name_(database_name), query_hash_(0), startup_schema_version_(-1), diff --git a/src/core/database.h b/src/core/database.h index 0d0d1aa85..0ce1cc792 100644 --- a/src/core/database.h +++ b/src/core/database.h @@ -34,6 +34,9 @@ #include #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) +# include +#endif class QThread; class Application; @@ -63,7 +66,12 @@ class Database : public QObject { QSqlDatabase Connect(); void Close(); bool CheckErrors(const QSqlQuery &query); + +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + QRecursiveMutex *Mutex() { return &mutex_; } +#else QMutex *Mutex() { return &mutex_; } +#endif void RecreateAttachedDb(const QString &database_name); void ExecSchemaCommands(QSqlDatabase &db, const QString &schema, int schema_version, bool in_transaction = false); @@ -106,7 +114,11 @@ class Database : public QObject { QString directory_; QMutex connect_mutex_; +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + QRecursiveMutex mutex_; +#else QMutex mutex_; +#endif // This ID makes the QSqlDatabase name unique to the object as well as the thread int connection_id_;