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

fix: Replace deprecated QMutex::Recursive with QRecursiveMutex

This commit is contained in:
Anthony Bilinski 2021-06-06 01:29:44 -07:00
parent 8c34fa8f7d
commit 8276141ef9
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
17 changed files with 74 additions and 26 deletions

View File

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

View File

@ -23,6 +23,7 @@
#include <QObject> #include <QObject>
#include "util/interface.h" #include "util/interface.h"
#include "util/compatiblerecursivemutex.h"
#include "audio/iaudiosink.h" #include "audio/iaudiosink.h"
class OpenAL; class OpenAL;
@ -55,5 +56,5 @@ private:
OpenAL& audio; OpenAL& audio;
uint sourceId; uint sourceId;
bool killed = false; bool killed = false;
mutable QMutex killLock; mutable CompatibleRecursiveMutex killLock;
}; };

View File

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

View File

@ -20,6 +20,7 @@
#pragma once #pragma once
#include "audio/iaudiosource.h" #include "audio/iaudiosource.h"
#include "util/compatiblerecursivemutex.h"
#include <QMutex> #include <QMutex>
#include <QObject> #include <QObject>
@ -42,5 +43,5 @@ public:
private: private:
OpenAL& audio; OpenAL& audio;
bool killed = false; bool killed = false;
mutable QMutex killLock; mutable CompatibleRecursiveMutex killLock;
}; };

View File

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

View File

@ -33,6 +33,7 @@
#include "src/model/ibootstraplistgenerator.h" #include "src/model/ibootstraplistgenerator.h"
#include "src/persistence/profile.h" #include "src/persistence/profile.h"
#include "util/strongtype.h" #include "util/strongtype.h"
#include "util/compatiblerecursivemutex.h"
#include <QCoreApplication> #include <QCoreApplication>
#include <QDateTime> #include <QDateTime>
@ -715,7 +716,7 @@ Tox* Core::getTox() const
return tox.get(); return tox.get();
} }
QMutex &Core::getCoreLoopLock() const CompatibleRecursiveMutex &Core::getCoreLoopLock() const
{ {
return coreLoopLock; return coreLoopLock;
} }

View File

@ -31,6 +31,7 @@
#include "toxpk.h" #include "toxpk.h"
#include "util/strongtype.h" #include "util/strongtype.h"
#include "util/compatiblerecursivemutex.h"
#include "src/model/status.h" #include "src/model/status.h"
#include <tox/tox.h> #include <tox/tox.h>
@ -78,7 +79,7 @@ public:
CoreFile* getCoreFile() const; CoreFile* getCoreFile() const;
Tox* getTox() const; Tox* getTox() const;
QMutex& getCoreLoopLock() const; CompatibleRecursiveMutex& getCoreLoopLock() const;
const CoreExt* getExt() const; const CoreExt* getExt() const;
CoreExt* getExt(); CoreExt* getExt();
@ -258,7 +259,7 @@ private:
std::unique_ptr<CoreExt> ext; std::unique_ptr<CoreExt> ext;
QTimer* toxTimer = nullptr; QTimer* toxTimer = nullptr;
// recursive, since we might call our own functions // recursive, since we might call our own functions
mutable QMutex coreLoopLock{QMutex::Recursive}; mutable CompatibleRecursiveMutex coreLoopLock;
std::unique_ptr<QThread> coreThread; std::unique_ptr<QThread> coreThread;
IBootstrapListGenerator& bootstrapNodes; IBootstrapListGenerator& bootstrapNodes;

View File

@ -26,6 +26,7 @@
#include "src/persistence/igroupsettings.h" #include "src/persistence/igroupsettings.h"
#include "src/video/corevideosource.h" #include "src/video/corevideosource.h"
#include "src/video/videoframe.h" #include "src/video/videoframe.h"
#include "util/compatiblerecursivemutex.h"
#include <QCoreApplication> #include <QCoreApplication>
#include <QDebug> #include <QDebug>
#include <QThread> #include <QThread>
@ -69,7 +70,7 @@
* deadlock. * deadlock.
*/ */
CoreAV::CoreAV(std::unique_ptr<ToxAV, ToxAVDeleter> toxav, QMutex& toxCoreLock, CoreAV::CoreAV(std::unique_ptr<ToxAV, ToxAVDeleter> toxav, CompatibleRecursiveMutex& toxCoreLock,
IAudioSettings& _audioSettings, IGroupSettings& _groupSettings) IAudioSettings& _audioSettings, IGroupSettings& _groupSettings)
: audio{nullptr} : audio{nullptr}
, toxav{std::move(toxav)} , toxav{std::move(toxav)}
@ -109,7 +110,7 @@ void CoreAV::connectCallbacks(ToxAV& toxav)
* @param core pointer to the Tox instance * @param core pointer to the Tox instance
* @return CoreAV instance on success, {} on failure * @return CoreAV instance on success, {} on failure
*/ */
CoreAV::CoreAVPtr CoreAV::makeCoreAV(Tox* core, QMutex& toxCoreLock, CoreAV::CoreAVPtr CoreAV::makeCoreAV(Tox* core, CompatibleRecursiveMutex& toxCoreLock,
IAudioSettings& audioSettings, IGroupSettings& groupSettings) IAudioSettings& audioSettings, IGroupSettings& groupSettings)
{ {
Toxav_Err_New err; Toxav_Err_New err;

View File

@ -21,6 +21,7 @@
#pragma once #pragma once
#include "src/core/toxcall.h" #include "src/core/toxcall.h"
#include "util/compatiblerecursivemutex.h"
#include <QObject> #include <QObject>
#include <QMutex> #include <QMutex>
@ -49,7 +50,7 @@ class CoreAV : public QObject
public: public:
using CoreAVPtr = std::unique_ptr<CoreAV>; using CoreAVPtr = std::unique_ptr<CoreAV>;
static CoreAVPtr makeCoreAV(Tox* core, QMutex& toxCoreLock, static CoreAVPtr makeCoreAV(Tox* core, CompatibleRecursiveMutex& toxCoreLock,
IAudioSettings& audioSettings, IGroupSettings& groupSettings); IAudioSettings& audioSettings, IGroupSettings& groupSettings);
void setAudio(IAudioControl& newAudio); void setAudio(IAudioControl& newAudio);
@ -116,7 +117,7 @@ private:
} }
}; };
CoreAV(std::unique_ptr<ToxAV, ToxAVDeleter> tox, QMutex &toxCoreLock, CoreAV(std::unique_ptr<ToxAV, ToxAVDeleter> tox, CompatibleRecursiveMutex &toxCoreLock,
IAudioSettings& _audioSettings, IGroupSettings& _groupSettings); IAudioSettings& _audioSettings, IGroupSettings& _groupSettings);
void connectCallbacks(ToxAV& toxav); void connectCallbacks(ToxAV& toxav);
@ -160,7 +161,7 @@ private:
* must not execute at the same time as tox_iterate() * 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 * @note This must be a recursive mutex as we're going to lock it in callbacks
*/ */
QMutex& coreLock; CompatibleRecursiveMutex& coreLock;
IAudioSettings& audioSettings; IAudioSettings& audioSettings;
IGroupSettings& groupSettings; IGroupSettings& groupSettings;

View File

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

View File

@ -27,6 +27,8 @@
#include "src/core/toxpk.h" #include "src/core/toxpk.h"
#include "src/model/status.h" #include "src/model/status.h"
#include "util/compatiblerecursivemutex.h"
#include <QHash> #include <QHash>
#include <QMutex> #include <QMutex>
#include <QObject> #include <QObject>
@ -47,7 +49,7 @@ class CoreFile : public QObject
public: public:
void handleAvatarOffer(uint32_t friendId, uint32_t fileId, bool accept); 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, void sendFile(uint32_t friendId, QString filename, QString filePath,
long long filesize); long long filesize);
@ -77,7 +79,7 @@ signals:
void fileSendFailed(uint32_t friendId, const QString& fname); void fileSendFailed(uint32_t friendId, const QString& fname);
private: private:
CoreFile(Tox* core, QMutex& coreLoopLock); CoreFile(Tox* core, CompatibleRecursiveMutex& coreLoopLock);
ToxFile* findFile(uint32_t friendId, uint32_t fileId); ToxFile* findFile(uint32_t friendId, uint32_t fileId);
void addFile(uint32_t friendId, uint32_t fileId, const ToxFile& file); void addFile(uint32_t friendId, uint32_t fileId, const ToxFile& file);
@ -106,5 +108,5 @@ private slots:
private: private:
QHash<uint64_t, ToxFile> fileMap; QHash<uint64_t, ToxFile> fileMap;
Tox* tox; Tox* tox;
QMutex* coreLoopLock = nullptr; CompatibleRecursiveMutex* coreLoopLock = nullptr;
}; };

View File

@ -29,10 +29,6 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <chrono> #include <chrono>
OfflineMsgEngine::OfflineMsgEngine()
: mutex(QMutex::Recursive)
{}
/** /**
* @brief Notification that the message is now delivered. * @brief Notification that the message is now delivered.
* *

View File

@ -23,6 +23,9 @@
#include "src/core/core.h" #include "src/core/core.h"
#include "src/model/message.h" #include "src/model/message.h"
#include "src/persistence/db/rawdatabase.h" #include "src/persistence/db/rawdatabase.h"
#include "util/compatiblerecursivemutex.h"
#include <QDateTime> #include <QDateTime>
#include <QMap> #include <QMap>
#include <QMutex> #include <QMutex>
@ -36,7 +39,7 @@ class OfflineMsgEngine : public QObject
Q_OBJECT Q_OBJECT
public: public:
using CompletionFn = std::function<void(bool)>; using CompletionFn = std::function<void(bool)>;
OfflineMsgEngine(); OfflineMsgEngine() = default;
void addUnsentMessage(Message const& message, CompletionFn completionCallback); void addUnsentMessage(Message const& message, CompletionFn completionCallback);
void addSentCoreMessage(ReceiptNum receipt, Message const& message, CompletionFn completionCallback); void addSentCoreMessage(ReceiptNum receipt, Message const& message, CompletionFn completionCallback);
void addSentExtendedMessage(ExtendedReceiptNum receipt, Message const& message, CompletionFn completionCallback); void addSentExtendedMessage(ExtendedReceiptNum receipt, Message const& message, CompletionFn completionCallback);
@ -60,7 +63,7 @@ private:
CompletionFn completionFn; CompletionFn completionFn;
}; };
QMutex mutex; CompatibleRecursiveMutex mutex;
template <class ReceiptT> template <class ReceiptT>
class ReceiptResolver class ReceiptResolver

View File

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

View File

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

View File

@ -15,6 +15,7 @@
# along with qTox. If not, see <http://www.gnu.org/licenses/> # along with qTox. If not, see <http://www.gnu.org/licenses/>
set(HEADER_LIST set(HEADER_LIST
"include/util/compatiblerecursivemutex.h"
"include/util/interface.h" "include/util/interface.h"
"include/util/strongtype.h") "include/util/strongtype.h")

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