Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
qgroundcontrol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
920dcc31
Commit
920dcc31
authored
Dec 02, 2014
by
Don Gagne
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1054 from DonLakeFlyer/ThreadSafety
QSqlDatabase::addDatabase not thread safe with plugin
parents
ec4f3ffc
b9113c56
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
0 deletions
+14
-0
pureimagecache.cpp
libs/opmapcontrol/src/core/pureimagecache.cpp
+14
-0
No files found.
libs/opmapcontrol/src/core/pureimagecache.cpp
View file @
920dcc31
...
...
@@ -29,6 +29,8 @@
#include <QSettings>
//#define DEBUG_PUREIMAGECACHE
namespace
core
{
static
QMutex
addDatabaseMutex
;
// QSqlDatabase::addDatabase is not thread safe when loadingn plugins
qlonglong
PureImageCache
::
ConnCounter
=
0
;
PureImageCache
::
PureImageCache
()
...
...
@@ -90,7 +92,9 @@ namespace core {
return
false
;
}
}
addDatabaseMutex
.
lock
();
QSqlDatabase
db
(
QSqlDatabase
::
addDatabase
(
"QSQLITE"
,
QLatin1String
(
"CreateConn"
)));
addDatabaseMutex
.
unlock
();
db
.
setDatabaseName
(
file
);
if
(
!
db
.
open
())
{
...
...
@@ -179,7 +183,9 @@ namespace core {
qlonglong
id
=++
ConnCounter
;
Mcounter
.
unlock
();
{
addDatabaseMutex
.
lock
();
QSqlDatabase
cn
(
QSqlDatabase
::
addDatabase
(
"QSQLITE"
,
QString
::
number
(
id
)));
addDatabaseMutex
.
unlock
();
QString
db
=
gtilecache
+
"Data.qmdb"
;
cn
.
setDatabaseName
(
db
);
cn
.
setConnectOptions
(
"QSQLITE_ENABLE_SHARED_CACHE"
);
...
...
@@ -225,7 +231,9 @@ namespace core {
QString
db
=
dir
+
"Data.qmdb"
;
{
addDatabaseMutex
.
lock
();
QSqlDatabase
cn
(
QSqlDatabase
::
addDatabase
(
"QSQLITE"
,
QString
::
number
(
id
)));
addDatabaseMutex
.
unlock
();
cn
.
setDatabaseName
(
db
);
cn
.
setConnectOptions
(
"QSQLITE_ENABLE_SHARED_CACHE"
);
...
...
@@ -260,7 +268,9 @@ namespace core {
Mcounter
.
lock
();
qlonglong
id
=++
ConnCounter
;
Mcounter
.
unlock
();
addDatabaseMutex
.
lock
();
QSqlDatabase
cn
(
QSqlDatabase
::
addDatabase
(
"QSQLITE"
,
QString
::
number
(
id
)));
addDatabaseMutex
.
unlock
();
cn
.
setDatabaseName
(
db
);
cn
.
setConnectOptions
(
"QSQLITE_ENABLE_SHARED_CACHE"
);
if
(
cn
.
open
())
...
...
@@ -298,12 +308,16 @@ namespace core {
ret
=
CreateEmptyDB
(
destFile
);
}
if
(
!
ret
)
return
false
;
addDatabaseMutex
.
lock
();
QSqlDatabase
ca
(
QSqlDatabase
::
addDatabase
(
"QSQLITE"
,
"ca"
));
addDatabaseMutex
.
unlock
();
ca
.
setDatabaseName
(
sourceFile
);
if
(
ca
.
open
())
{
addDatabaseMutex
.
lock
();
QSqlDatabase
cb
(
QSqlDatabase
::
addDatabase
(
"QSQLITE"
,
"cb"
));
addDatabaseMutex
.
unlock
();
cb
.
setDatabaseName
(
destFile
);
if
(
cb
.
open
())
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment