summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2023-04-27 20:37:18 +0200
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2023-05-23 06:20:09 +0200
commit67b8dec0d0210be43c4018e3fd1c1c7419aaaec0 (patch)
tree9aa10c8350c73a061637ecd6d27db26ab0b80029 /src
parentbc85390dccd08ec99682106b835b97928b61894f (diff)
QSqlDatabase: use a QReadWriteLock to access DriverDict
DriverDict might be accessed from different threads so we have to make sure it's thread-safe. Use the already existing QReadWriteLock from QConnectionDict for later merging of these two global instances. The two instances do not interfere each other (DriverDict is a dictionary for custom registered sql drivers, QConnectionDict contains all current active database connections) so the dual-use of the mutex is fine. Pick-to: 6.5 6.2 5.15 Change-Id: I84c77df666e72e826d0d3d291cecd5417bbd1baf Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/sql/kernel/qsqldatabase.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/sql/kernel/qsqldatabase.cpp b/src/sql/kernel/qsqldatabase.cpp
index f05d95319a..9f306748af 100644
--- a/src/sql/kernel/qsqldatabase.cpp
+++ b/src/sql/kernel/qsqldatabase.cpp
@@ -503,6 +503,7 @@ QStringList QSqlDatabase::drivers()
}
}
+ QReadLocker locker(&dbDict()->lock);
const DriverDict dict = QSqlDatabasePrivate::driverDict();
for (const auto &[k, _] : dict.asKeyValueRange()) {
if (!list.contains(k))
@@ -527,6 +528,7 @@ QStringList QSqlDatabase::drivers()
*/
void QSqlDatabase::registerSqlDriver(const QString& name, QSqlDriverCreatorBase *creator)
{
+ QWriteLocker locker(&dbDict()->lock);
delete QSqlDatabasePrivate::driverDict().take(name);
if (creator)
QSqlDatabasePrivate::driverDict().insert(name, creator);
@@ -642,6 +644,7 @@ void QSqlDatabasePrivate::init(const QString &type)
drvName = type;
if (!driver) {
+ QReadLocker locker(&dbDict()->lock);
DriverDict dict = QSqlDatabasePrivate::driverDict();
for (DriverDict::const_iterator it = dict.constBegin();
it != dict.constEnd() && !driver; ++it) {