diff --git a/src/audio/backend/alsink.cpp b/src/audio/backend/alsink.cpp index 3114443e8..33c544a0e 100644 --- a/src/audio/backend/alsink.cpp +++ b/src/audio/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/src/audio/backend/alsink.h b/src/audio/backend/alsink.h index b742bba13..2c1682adf 100644 --- a/src/audio/backend/alsink.h +++ b/src/audio/backend/alsink.h @@ -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 diff --git a/src/audio/backend/alsource.cpp b/src/audio/backend/alsource.cpp index c29c579ad..0eb6c2b4e 100644 --- a/src/audio/backend/alsource.cpp +++ b/src/audio/backend/alsource.cpp @@ -30,7 +30,6 @@ */ AlSource::AlSource(OpenAL& al) : audio(al) - , killLock(QMutex::Recursive) {} AlSource::~AlSource() diff --git a/src/audio/backend/alsource.h b/src/audio/backend/alsource.h index 64e2191f5..3d525787e 100644 --- a/src/audio/backend/alsource.h +++ b/src/audio/backend/alsource.h @@ -21,6 +21,7 @@ #define ALSOURCE_H #include "src/audio/iaudiosource.h" +#include "src/util/compatiblerecursivemutex.h" #include #include @@ -43,7 +44,7 @@ public: private: OpenAL& audio; bool killed = false; - mutable QMutex killLock; + mutable CompatibleRecursiveMutex killLock; }; #endif // ALSOURCE_H diff --git a/src/audio/backend/openal.h b/src/audio/backend/openal.h index 64b4470ec..669bc3c6c 100644 --- a/src/audio/backend/openal.h +++ b/src/audio/backend/openal.h @@ -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 #include @@ -133,7 +134,7 @@ private: protected: 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 f19956ead..1db522dac 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -32,6 +32,7 @@ #include "src/nexus.h" #include "src/persistence/profile.h" #include "src/util/strongtype.h" +#include "src/util/compatiblerecursivemutex.h" #include #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)) diff --git a/src/core/core.h b/src/core/core.h index 4863f51bc..b09e4fe14 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -32,6 +32,7 @@ #include "toxpk.h" #include "src/util/strongtype.h" +#include "src/util/compatiblerecursivemutex.h" #include "src/model/status.h" #include @@ -251,7 +252,7 @@ private: std::unique_ptr av; QTimer* toxTimer = nullptr; // recursive, since we might call our own functions - mutable QMutex coreLoopLock{QMutex::Recursive}; + mutable CompatibleRecursiveMutex coreLoopLock; std::unique_ptr coreThread = nullptr; }; diff --git a/src/core/coreav.cpp b/src/core/coreav.cpp index b0f67548c..1ea796931 100644 --- a/src/core/coreav.cpp +++ b/src/core/coreav.cpp @@ -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 #include #include @@ -68,7 +69,7 @@ * deadlock. */ -CoreAV::CoreAV(std::unique_ptr toxav, QMutex& toxCoreLock) +CoreAV::CoreAV(std::unique_ptr 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{toxav_new(core, &err)}; diff --git a/src/core/coreav.h b/src/core/coreav.h index 3b312e47d..dd18576d5 100644 --- a/src/core/coreav.h +++ b/src/core/coreav.h @@ -22,6 +22,8 @@ #define COREAV_H #include "src/core/toxcall.h" +#include "src/util/compatiblerecursivemutex.h" + #include #include #include @@ -47,7 +49,7 @@ class CoreAV : public QObject public: using CoreAVPtr = std::unique_ptr; - 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 tox, QMutex &toxCoreLock); + CoreAV(std::unique_ptr 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 diff --git a/src/core/corefile.cpp b/src/core/corefile.cpp index f31a6b7f9..3dcd47712 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 "src/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 429e7579a..08041979d 100644 --- a/src/core/corefile.h +++ b/src/core/corefile.h @@ -28,6 +28,8 @@ #include "src/core/toxpk.h" #include "src/model/status.h" +#include "src/util/compatiblerecursivemutex.h" + #include #include #include @@ -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 fileMap; Tox* tox; - QMutex* coreLoopLock = nullptr; + CompatibleRecursiveMutex* coreLoopLock = nullptr; }; #endif // COREFILE_H diff --git a/src/persistence/offlinemsgengine.cpp b/src/persistence/offlinemsgengine.cpp index 6026145bf..eb6a2fde3 100644 --- a/src/persistence/offlinemsgengine.cpp +++ b/src/persistence/offlinemsgengine.cpp @@ -30,8 +30,7 @@ #include OfflineMsgEngine::OfflineMsgEngine(Friend* frnd, ICoreFriendMessageSender* messageSender) - : mutex(QMutex::Recursive) - , f(frnd) + : f(frnd) , messageSender(messageSender) {} diff --git a/src/persistence/offlinemsgengine.h b/src/persistence/offlinemsgengine.h index adac2aa93..9c098d6ca 100644 --- a/src/persistence/offlinemsgengine.h +++ b/src/persistence/offlinemsgengine.h @@ -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 #include #include @@ -63,7 +66,7 @@ private slots: private: void checkForCompleteMessages(ReceiptNum receipt); - QMutex mutex; + CompatibleRecursiveMutex mutex; const Friend* f; ICoreFriendMessageSender* messageSender; QVector receivedReceipts; diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 7b8d632ec..e724775f3 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -33,6 +33,8 @@ #endif #include "src/ipc.h" +#include "src/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 d235c4b67..0effc96c1 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -29,6 +29,8 @@ #include "src/persistence/igroupsettings.h" #include "src/video/ivideosettings.h" +#include "src/util/compatiblerecursivemutex.h" + #include #include #include @@ -703,7 +705,7 @@ private: int themeColor; - static QMutex bigLock; + static CompatibleRecursiveMutex bigLock; static Settings* settings; static const QString globalSettingsFile; static QThread* settingsThread; diff --git a/src/util/compatiblerecursivemutex.h b/src/util/compatiblerecursivemutex.h new file mode 100644 index 000000000..755cf3d01 --- /dev/null +++ b/src/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 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