Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(settings): Add mutex locks for consistency
Browse files Browse the repository at this point in the history
* Risk is low here since we use a recusrive mutex
  • Loading branch information
sphaerophoria committed Oct 28, 2018
1 parent 4af88a3 commit 24f8bbf
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/persistence/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,8 @@ void Settings::setEnableLanDiscovery(bool enabled)

QNetworkProxy Settings::getProxy() const
{
QMutexLocker locker{&bigLock};

QNetworkProxy proxy;
switch (Settings::getProxyType()) {
case ProxyType::ptNone:
Expand Down Expand Up @@ -2074,6 +2076,7 @@ void Settings::setFriendAlias(const ToxPk& id, const QString& alias)

int Settings::getFriendCircleID(const ToxPk& id) const
{
QMutexLocker locker{&bigLock};
auto it = friendLst.find(id.getKey());
if (it != friendLst.end())
return it->circleID;
Expand All @@ -2083,6 +2086,7 @@ int Settings::getFriendCircleID(const ToxPk& id) const

void Settings::setFriendCircleID(const ToxPk& id, int circleID)
{
QMutexLocker locker{&bigLock};
auto& frnd = getOrInsertFriendPropRef(id);
frnd.circleID = circleID;
}
Expand All @@ -2098,6 +2102,7 @@ QDate Settings::getFriendActivity(const ToxPk& id) const

void Settings::setFriendActivity(const ToxPk& id, const QDate& activity)
{
QMutexLocker locker{&bigLock};
auto& frnd = getOrInsertFriendPropRef(id);
frnd.activity = activity;
}
Expand Down Expand Up @@ -2212,22 +2217,27 @@ void Settings::setShowIdenticons(bool value)

int Settings::getCircleCount() const
{
QMutexLocker locker{&bigLock};
return circleLst.size();
}

QString Settings::getCircleName(int id) const
{
QMutexLocker locker{&bigLock};
return circleLst[id].name;
}

void Settings::setCircleName(int id, const QString& name)
{
QMutexLocker locker{&bigLock};
circleLst[id].name = name;
savePersonal();
}

int Settings::addCircle(const QString& name)
{
QMutexLocker locker{&bigLock};

circleProp cp;
cp.expanded = false;

Expand All @@ -2243,11 +2253,13 @@ int Settings::addCircle(const QString& name)

bool Settings::getCircleExpanded(int id) const
{
QMutexLocker locker{&bigLock};
return circleLst[id].expanded;
}

void Settings::setCircleExpanded(int id, bool expanded)
{
QMutexLocker locker{&bigLock};
circleLst[id].expanded = expanded;
}

Expand Down Expand Up @@ -2365,6 +2377,8 @@ void Settings::setAutoLogin(bool state)
*/
void Settings::createPersonal(QString basename)
{
QMutexLocker locker{&bigLock};

QString path = getSettingsDirPath() + QDir::separator() + basename + ".ini";
qDebug() << "Creating new profile settings in " << path;

Expand All @@ -2384,6 +2398,8 @@ void Settings::createPersonal(QString basename)
*/
void Settings::createSettingsDir()
{
QMutexLocker locker{&bigLock};

QString dir = Settings::getSettingsDirPath();
QDir directory(dir);
if (!directory.exists() && !directory.mkpath(directory.absolutePath()))
Expand Down

0 comments on commit 24f8bbf

Please sign in to comment.