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

chore: Replace deprecated QMutex::Recursive with QRecursiveMutex

This commit is contained in:
Anthony Bilinski 2021-06-06 01:29:44 -07:00
parent 96e1ce573b
commit 992cdbd045
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
17 changed files with 108 additions and 21 deletions

View File

@ -101,7 +101,6 @@ void AlSink::kill()
AlSink::AlSink(OpenAL& al, uint sourceId)
: audio(al)
, sourceId{sourceId}
, killLock(QMutex::Recursive)
{}
AlSink::operator bool() const

View File

@ -25,6 +25,7 @@
#include "src/model/interface.h"
#include "src/audio/iaudiosink.h"
#include "src/util/compatiblerecursivemutex.h"
class OpenAL;
class QMutex;
@ -56,7 +57,7 @@ private:
OpenAL& audio;
uint sourceId;
bool killed = false;
mutable QMutex killLock;
mutable CompatibleRecursiveMutex killLock;
};
#endif // ALSINK_H

View File

@ -30,7 +30,6 @@
*/
AlSource::AlSource(OpenAL& al)
: audio(al)
, killLock(QMutex::Recursive)
{}
AlSource::~AlSource()

View File

@ -21,6 +21,7 @@
#define ALSOURCE_H
#include "src/audio/iaudiosource.h"
#include "src/util/compatiblerecursivemutex.h"
#include <QMutex>
#include <QObject>
@ -43,7 +44,7 @@ public:
private:
OpenAL& audio;
bool killed = false;
mutable QMutex killLock;
mutable CompatibleRecursiveMutex killLock;
};
#endif // ALSOURCE_H

View File

@ -24,6 +24,7 @@
#include "src/audio/iaudiocontrol.h"
#include "src/audio/backend/alsink.h"
#include "src/audio/backend/alsource.h"
#include "src/util/compatiblerecursivemutex.h"
#include <memory>
#include <unordered_set>
@ -133,7 +134,7 @@ private:
protected:
QThread* audioThread;
mutable QMutex audioLock{QMutex::Recursive};
mutable CompatibleRecursiveMutex audioLock;
QString inDev{};
QString outDev{};

View File

@ -32,6 +32,7 @@
#include "src/nexus.h"
#include "src/persistence/profile.h"
#include "src/util/strongtype.h"
#include "src/util/compatiblerecursivemutex.h"
#include <QCoreApplication>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))

View File

@ -32,6 +32,7 @@
#include "toxpk.h"
#include "src/util/strongtype.h"
#include "src/util/compatiblerecursivemutex.h"
#include "src/model/status.h"
#include <tox/tox.h>
@ -251,7 +252,7 @@ private:
std::unique_ptr<CoreAV> av;
QTimer* toxTimer = nullptr;
// recursive, since we might call our own functions
mutable QMutex coreLoopLock{QMutex::Recursive};
mutable CompatibleRecursiveMutex coreLoopLock;
std::unique_ptr<QThread> coreThread = nullptr;
};

View File

@ -25,6 +25,7 @@
#include "src/persistence/settings.h"
#include "src/video/corevideosource.h"
#include "src/video/videoframe.h"
#include "src/util/compatiblerecursivemutex.h"
#include <QCoreApplication>
#include <QDebug>
#include <QThread>
@ -68,7 +69,7 @@
* deadlock.
*/
CoreAV::CoreAV(std::unique_ptr<ToxAV, ToxAVDeleter> toxav, QMutex& toxCoreLock)
CoreAV::CoreAV(std::unique_ptr<ToxAV, ToxAVDeleter> toxav, CompatibleRecursiveMutex& toxCoreLock)
: audio{nullptr}
, toxav{std::move(toxav)}
, coreavThread{new QThread{this}}
@ -105,7 +106,7 @@ void CoreAV::connectCallbacks(ToxAV& toxav)
* @param core pointer to the Tox instance
* @return CoreAV instance on success, {} on failure
*/
CoreAV::CoreAVPtr CoreAV::makeCoreAV(Tox* core, QMutex &toxCoreLock)
CoreAV::CoreAVPtr CoreAV::makeCoreAV(Tox* core, CompatibleRecursiveMutex &toxCoreLock)
{
TOXAV_ERR_NEW err;
std::unique_ptr<ToxAV, ToxAVDeleter> toxav{toxav_new(core, &err)};

View File

@ -22,6 +22,8 @@
#define COREAV_H
#include "src/core/toxcall.h"
#include "src/util/compatiblerecursivemutex.h"
#include <QObject>
#include <QMutex>
#include <QReadWriteLock>
@ -47,7 +49,7 @@ class CoreAV : public QObject
public:
using CoreAVPtr = std::unique_ptr<CoreAV>;
static CoreAVPtr makeCoreAV(Tox* core, QMutex& coreLock);
static CoreAVPtr makeCoreAV(Tox* core, CompatibleRecursiveMutex& coreLock);
void setAudio(IAudioControl& newAudio);
IAudioControl* getAudio();
@ -113,7 +115,7 @@ private:
}
};
CoreAV(std::unique_ptr<ToxAV, ToxAVDeleter> tox, QMutex &toxCoreLock);
CoreAV(std::unique_ptr<ToxAV, ToxAVDeleter> tox, CompatibleRecursiveMutex &toxCoreLock);
void connectCallbacks(ToxAV& toxav);
void process();
@ -156,7 +158,7 @@ private:
* must not execute at the same time as tox_iterate()
* @note This must be a recursive mutex as we're going to lock it in callbacks
*/
QMutex& coreLock;
CompatibleRecursiveMutex& coreLock;
};
#endif // COREAV_H

View File

@ -25,6 +25,7 @@
#include "src/persistence/settings.h"
#include "src/model/status.h"
#include "src/model/toxclientstandards.h"
#include "src/util/compatiblerecursivemutex.h"
#include <QDebug>
#include <QDir>
#include <QFile>
@ -38,7 +39,7 @@
* @brief Manages the file transfer service of toxcore
*/
CoreFilePtr CoreFile::makeCoreFile(Core *core, Tox *tox, QMutex &coreLoopLock)
CoreFilePtr CoreFile::makeCoreFile(Core *core, Tox *tox, CompatibleRecursiveMutex &coreLoopLock)
{
assert(core != nullptr);
assert(tox != nullptr);
@ -49,7 +50,7 @@ CoreFilePtr CoreFile::makeCoreFile(Core *core, Tox *tox, QMutex &coreLoopLock)
return result;
}
CoreFile::CoreFile(Tox *core, QMutex &coreLoopLock)
CoreFile::CoreFile(Tox *core, CompatibleRecursiveMutex &coreLoopLock)
: tox{core}
, coreLoopLock{&coreLoopLock}
{

View File

@ -28,6 +28,8 @@
#include "src/core/toxpk.h"
#include "src/model/status.h"
#include "src/util/compatiblerecursivemutex.h"
#include <QHash>
#include <QMutex>
#include <QObject>
@ -48,7 +50,7 @@ class CoreFile : public QObject
public:
void handleAvatarOffer(uint32_t friendId, uint32_t fileId, bool accept);
static CoreFilePtr makeCoreFile(Core* core, Tox* tox, QMutex& coreLoopLock);
static CoreFilePtr makeCoreFile(Core* core, Tox* tox, CompatibleRecursiveMutex& coreLoopLock);
void sendFile(uint32_t friendId, QString filename, QString filePath,
long long filesize);
@ -78,7 +80,7 @@ signals:
void fileSendFailed(uint32_t friendId, const QString& fname);
private:
CoreFile(Tox* core, QMutex& coreLoopLock);
CoreFile(Tox* core, CompatibleRecursiveMutex& coreLoopLock);
ToxFile* findFile(uint32_t friendId, uint32_t fileId);
void addFile(uint32_t friendId, uint32_t fileId, const ToxFile& file);
@ -107,7 +109,7 @@ private slots:
private:
QHash<uint64_t, ToxFile> fileMap;
Tox* tox;
QMutex* coreLoopLock = nullptr;
CompatibleRecursiveMutex* coreLoopLock = nullptr;
};
#endif // COREFILE_H

View File

@ -30,8 +30,7 @@
#include <chrono>
OfflineMsgEngine::OfflineMsgEngine(Friend* frnd, ICoreFriendMessageSender* messageSender)
: mutex(QMutex::Recursive)
, f(frnd)
: f(frnd)
, messageSender(messageSender)
{}

View File

@ -24,6 +24,9 @@
#include "src/core/core.h"
#include "src/model/message.h"
#include "src/persistence/db/rawdatabase.h"
#include "src/util/compatiblerecursivemutex.h"
#include <QDateTime>
#include <QMap>
#include <QMutex>
@ -63,7 +66,7 @@ private slots:
private:
void checkForCompleteMessages(ReceiptNum receipt);
QMutex mutex;
CompatibleRecursiveMutex mutex;
const Friend* f;
ICoreFriendMessageSender* messageSender;
QVector<ReceiptNum> receivedReceipts;

View File

@ -33,6 +33,8 @@
#endif
#include "src/ipc.h"
#include "src/util/compatiblerecursivemutex.h"
#include <QApplication>
#include <QCryptographicHash>
#include <QDebug>
@ -57,7 +59,7 @@
const QString Settings::globalSettingsFile = "qtox.ini";
Settings* Settings::settings{nullptr};
QMutex Settings::bigLock{QMutex::Recursive};
CompatibleRecursiveMutex Settings::bigLock;
QThread* Settings::settingsThread{nullptr};
Settings::Settings()

View File

@ -29,6 +29,8 @@
#include "src/persistence/igroupsettings.h"
#include "src/video/ivideosettings.h"
#include "src/util/compatiblerecursivemutex.h"
#include <QDateTime>
#include <QFlags>
#include <QFont>
@ -703,7 +705,7 @@ private:
int themeColor;
static QMutex bigLock;
static CompatibleRecursiveMutex bigLock;
static Settings* settings;
static const QString globalSettingsFile;
static QThread* settingsThread;

View File

@ -0,0 +1,36 @@
/*
Copyright © 2021 by The qTox Project Contributors
This file is part of qTox, a Qt-based graphical interface for Tox.
qTox is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
qTox is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with qTox. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <QtGlobal>
#include <QMutex>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
class CompatibleRecursiveMutex : public QRecursiveMutex
{};
#else
class CompatibleRecursiveMutex : public QMutex
{
public:
CompatibleRecursiveMutex()
: QMutex(QMutex::Recursive)
{}
};
#endif

View File

@ -0,0 +1,36 @@
/*
Copyright © 2021 by The qTox Project Contributors
This file is part of qTox, a Qt-based graphical interface for Tox.
qTox is libre software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
qTox is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with qTox. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <QtGlobal>
#include <QMutex>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
class CompatibleRecursiveMutex : public QRecursiveMutex
{};
#else
class CompatibleRecursiveMutex : public QMutex
{
public:
CompatibleRecursiveMutex()
: QMutex(QMutex::Recursive)
{}
};
#endif