diff --git a/audio/src/backend/alsink.cpp b/audio/src/backend/alsink.cpp index 040c1c616..c5d695e9e 100644 --- a/audio/src/backend/alsink.cpp +++ b/audio/src/backend/alsink.cpp @@ -101,7 +101,6 @@ void AlSink::kill() AlSink::AlSink(OpenAL& al, uint sourceId) : audio(al) , sourceId{sourceId} - , killLock(QMutex::Recursive) {} AlSink::operator bool() const diff --git a/audio/src/backend/alsink.h b/audio/src/backend/alsink.h index 8ada275b9..549a7e2a6 100644 --- a/audio/src/backend/alsink.h +++ b/audio/src/backend/alsink.h @@ -23,6 +23,7 @@ #include #include "util/interface.h" +#include "util/compatiblerecursivemutex.h" #include "audio/iaudiosink.h" class OpenAL; @@ -55,5 +56,5 @@ private: OpenAL& audio; uint sourceId; bool killed = false; - mutable QMutex killLock; + mutable CompatibleRecursiveMutex killLock; }; diff --git a/audio/src/backend/alsource.cpp b/audio/src/backend/alsource.cpp index 847da866c..e3cae8080 100644 --- a/audio/src/backend/alsource.cpp +++ b/audio/src/backend/alsource.cpp @@ -30,7 +30,6 @@ */ AlSource::AlSource(OpenAL& al) : audio(al) - , killLock(QMutex::Recursive) {} AlSource::~AlSource() diff --git a/audio/src/backend/alsource.h b/audio/src/backend/alsource.h index eb402324c..294733594 100644 --- a/audio/src/backend/alsource.h +++ b/audio/src/backend/alsource.h @@ -20,6 +20,7 @@ #pragma once #include "audio/iaudiosource.h" +#include "util/compatiblerecursivemutex.h" #include #include @@ -42,5 +43,5 @@ public: private: OpenAL& audio; bool killed = false; - mutable QMutex killLock; + mutable CompatibleRecursiveMutex killLock; }; diff --git a/audio/src/backend/openal.h b/audio/src/backend/openal.h index 8fcc3ef78..8a356574c 100644 --- a/audio/src/backend/openal.h +++ b/audio/src/backend/openal.h @@ -23,6 +23,7 @@ #include "audio/iaudiocontrol.h" #include "alsink.h" #include "alsource.h" +#include "util/compatiblerecursivemutex.h" #include #include @@ -132,7 +133,7 @@ private: protected: IAudioSettings& settings; QThread* audioThread; - mutable QMutex audioLock{QMutex::Recursive}; + mutable CompatibleRecursiveMutex audioLock; QString inDev{}; QString outDev{}; diff --git a/src/core/core.cpp b/src/core/core.cpp index 317103aa1..23935cc4c 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -33,6 +33,7 @@ #include "src/model/ibootstraplistgenerator.h" #include "src/persistence/profile.h" #include "util/strongtype.h" +#include "util/compatiblerecursivemutex.h" #include #include @@ -715,7 +716,7 @@ Tox* Core::getTox() const return tox.get(); } -QMutex &Core::getCoreLoopLock() const +CompatibleRecursiveMutex &Core::getCoreLoopLock() const { return coreLoopLock; } diff --git a/src/core/core.h b/src/core/core.h index c13379419..dce897727 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -31,6 +31,7 @@ #include "toxpk.h" #include "util/strongtype.h" +#include "util/compatiblerecursivemutex.h" #include "src/model/status.h" #include @@ -78,7 +79,7 @@ public: CoreFile* getCoreFile() const; Tox* getTox() const; - QMutex& getCoreLoopLock() const; + CompatibleRecursiveMutex& getCoreLoopLock() const; const CoreExt* getExt() const; CoreExt* getExt(); @@ -258,7 +259,7 @@ private: std::unique_ptr ext; QTimer* toxTimer = nullptr; // recursive, since we might call our own functions - mutable QMutex coreLoopLock{QMutex::Recursive}; + mutable CompatibleRecursiveMutex coreLoopLock; std::unique_ptr coreThread; IBootstrapListGenerator& bootstrapNodes; diff --git a/src/core/coreav.cpp b/src/core/coreav.cpp index 2b5c1196d..a6b7b766d 100644 --- a/src/core/coreav.cpp +++ b/src/core/coreav.cpp @@ -26,6 +26,7 @@ #include "src/persistence/igroupsettings.h" #include "src/video/corevideosource.h" #include "src/video/videoframe.h" +#include "util/compatiblerecursivemutex.h" #include #include #include @@ -69,7 +70,7 @@ * deadlock. */ -CoreAV::CoreAV(std::unique_ptr toxav, QMutex& toxCoreLock, +CoreAV::CoreAV(std::unique_ptr toxav, CompatibleRecursiveMutex& toxCoreLock, IAudioSettings& _audioSettings, IGroupSettings& _groupSettings) : audio{nullptr} , toxav{std::move(toxav)} @@ -109,7 +110,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, IAudioSettings& audioSettings, IGroupSettings& groupSettings) { Toxav_Err_New err; diff --git a/src/core/coreav.h b/src/core/coreav.h index eb494a899..4a31898b2 100644 --- a/src/core/coreav.h +++ b/src/core/coreav.h @@ -21,6 +21,7 @@ #pragma once #include "src/core/toxcall.h" +#include "util/compatiblerecursivemutex.h" #include #include @@ -49,7 +50,7 @@ class CoreAV : public QObject public: using CoreAVPtr = std::unique_ptr; - static CoreAVPtr makeCoreAV(Tox* core, QMutex& toxCoreLock, + static CoreAVPtr makeCoreAV(Tox* core, CompatibleRecursiveMutex& toxCoreLock, IAudioSettings& audioSettings, IGroupSettings& groupSettings); void setAudio(IAudioControl& newAudio); @@ -116,7 +117,7 @@ private: } }; - CoreAV(std::unique_ptr tox, QMutex &toxCoreLock, + CoreAV(std::unique_ptr tox, CompatibleRecursiveMutex &toxCoreLock, IAudioSettings& _audioSettings, IGroupSettings& _groupSettings); void connectCallbacks(ToxAV& toxav); @@ -160,7 +161,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; IAudioSettings& audioSettings; IGroupSettings& groupSettings; diff --git a/src/core/corefile.cpp b/src/core/corefile.cpp index 3800c3cfe..8cd6f7c3d 100644 --- a/src/core/corefile.cpp +++ b/src/core/corefile.cpp @@ -25,6 +25,7 @@ #include "src/persistence/settings.h" #include "src/model/status.h" #include "src/model/toxclientstandards.h" +#include "util/compatiblerecursivemutex.h" #include #include #include @@ -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} { diff --git a/src/core/corefile.h b/src/core/corefile.h index d6e32a787..062eba913 100644 --- a/src/core/corefile.h +++ b/src/core/corefile.h @@ -27,6 +27,8 @@ #include "src/core/toxpk.h" #include "src/model/status.h" +#include "util/compatiblerecursivemutex.h" + #include #include #include @@ -47,7 +49,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); @@ -77,7 +79,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); @@ -106,5 +108,5 @@ private slots: private: QHash fileMap; Tox* tox; - QMutex* coreLoopLock = nullptr; + CompatibleRecursiveMutex* coreLoopLock = nullptr; }; diff --git a/src/persistence/offlinemsgengine.cpp b/src/persistence/offlinemsgengine.cpp index 86622329b..f118561c4 100644 --- a/src/persistence/offlinemsgengine.cpp +++ b/src/persistence/offlinemsgengine.cpp @@ -29,10 +29,6 @@ #include #include -OfflineMsgEngine::OfflineMsgEngine() - : mutex(QMutex::Recursive) -{} - /** * @brief Notification that the message is now delivered. * diff --git a/src/persistence/offlinemsgengine.h b/src/persistence/offlinemsgengine.h index 7e65bd94a..dbaef79f4 100644 --- a/src/persistence/offlinemsgengine.h +++ b/src/persistence/offlinemsgengine.h @@ -23,6 +23,9 @@ #include "src/core/core.h" #include "src/model/message.h" #include "src/persistence/db/rawdatabase.h" + +#include "util/compatiblerecursivemutex.h" + #include #include #include @@ -36,7 +39,7 @@ class OfflineMsgEngine : public QObject Q_OBJECT public: using CompletionFn = std::function; - OfflineMsgEngine(); + OfflineMsgEngine() = default; void addUnsentMessage(Message const& message, CompletionFn completionCallback); void addSentCoreMessage(ReceiptNum receipt, Message const& message, CompletionFn completionCallback); void addSentExtendedMessage(ExtendedReceiptNum receipt, Message const& message, CompletionFn completionCallback); @@ -60,7 +63,7 @@ private: CompletionFn completionFn; }; - QMutex mutex; + CompatibleRecursiveMutex mutex; template class ReceiptResolver diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 8866d5a38..c59a3a0b5 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -33,6 +33,8 @@ #endif #include "src/ipc.h" +#include "util/compatiblerecursivemutex.h" + #include #include #include @@ -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() diff --git a/src/persistence/settings.h b/src/persistence/settings.h index a4fcbc5de..3ec496285 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -30,6 +30,8 @@ #include "src/persistence/inotificationsettings.h" #include "src/video/ivideosettings.h" +#include "util/compatiblerecursivemutex.h" + #include #include #include @@ -706,7 +708,7 @@ private: int themeColor; - static QMutex bigLock; + static CompatibleRecursiveMutex bigLock; static Settings* settings; static const QString globalSettingsFile; static QThread* settingsThread; diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 05570e774..945b8b438 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -15,6 +15,7 @@ # along with qTox. If not, see set(HEADER_LIST + "include/util/compatiblerecursivemutex.h" "include/util/interface.h" "include/util/strongtype.h") diff --git a/util/include/util/compatiblerecursivemutex.h b/util/include/util/compatiblerecursivemutex.h new file mode 100644 index 000000000..755cf3d01 --- /dev/null +++ b/util/include/util/compatiblerecursivemutex.h @@ -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 . +*/ + +#pragma once + +#include +#include + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) +class CompatibleRecursiveMutex : public QRecursiveMutex +{}; +#else +class CompatibleRecursiveMutex : public QMutex +{ +public: + CompatibleRecursiveMutex() + : QMutex(QMutex::Recursive) + {} +}; +#endif