1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

add multithreaded

This commit is contained in:
PKEv 2015-10-18 20:04:37 +03:00
parent ec5e9c7350
commit 20d0eb06f6
3 changed files with 7 additions and 0 deletions

View File

@ -26,12 +26,14 @@ PlainDb::PlainDb(const QString &db_name, QList<QString> initList)
{ {
db = new QSqlDatabase(); db = new QSqlDatabase();
*db = QSqlDatabase::addDatabase("QSQLITE"); *db = QSqlDatabase::addDatabase("QSQLITE");
db->setConnectOptions("QSQLITE_ENABLE_SHARED_CACHE=1");
db->setDatabaseName(db_name); db->setDatabaseName(db_name);
if (!db->open()) if (!db->open())
{ {
qWarning() << QString("Can't open file: %1, history will not be saved!").arg(db_name); qWarning() << QString("Can't open file: %1, history will not be saved!").arg(db_name);
db->setDatabaseName(":memory:"); db->setDatabaseName(":memory:");
db->setConnectOptions();
db->open(); db->open();
} }

View File

@ -36,9 +36,11 @@
#include "src/persistence/db/encrypteddb.h" #include "src/persistence/db/encrypteddb.h"
static HistoryKeeper *historyInstance = nullptr; static HistoryKeeper *historyInstance = nullptr;
QMutex HistoryKeeper::historyMutex;
HistoryKeeper *HistoryKeeper::getInstance() HistoryKeeper *HistoryKeeper::getInstance()
{ {
historyMutex.lock();
if (historyInstance == nullptr) if (historyInstance == nullptr)
{ {
QList<QString> initLst; QList<QString> initLst;
@ -67,6 +69,7 @@ HistoryKeeper *HistoryKeeper::getInstance()
dbIntf = new PlainDb(path, initLst); dbIntf = new PlainDb(path, initLst);
historyInstance = new HistoryKeeper(dbIntf); historyInstance = new HistoryKeeper(dbIntf);
} }
historyMutex.unlock();
return historyInstance; return historyInstance;
} }

View File

@ -24,6 +24,7 @@
#include <QList> #include <QList>
#include <QDateTime> #include <QDateTime>
#include <QPixmap> #include <QPixmap>
#include <QMutex>
#include <tox/toxencryptsave.h> #include <tox/toxencryptsave.h>
class GenericDdInterface; class GenericDdInterface;
@ -33,6 +34,7 @@ class HistoryKeeper
{ {
public: public:
enum ChatType {ctSingle = 0, ctGroup}; enum ChatType {ctSingle = 0, ctGroup};
static QMutex historyMutex;
struct HistMessage struct HistMessage
{ {