From 411b7573cc0b874d452e4d49c1a6bc7c3ae698a1 Mon Sep 17 00:00:00 2001 From: Ladislav Michl Date: Wed, 29 Mar 2023 15:49:45 +0200 Subject: [PATCH] Base: Use std::recursive_mutex --- src/Base/CMakeLists.txt | 2 -- src/Base/Mutex.cpp | 36 ------------------------------------ src/Base/Mutex.h | 39 --------------------------------------- src/Base/PreCompiled.h | 3 +-- src/Base/Sequencer.cpp | 31 ++++++++++++++----------------- 5 files changed, 15 insertions(+), 96 deletions(-) delete mode 100644 src/Base/Mutex.cpp delete mode 100644 src/Base/Mutex.h diff --git a/src/Base/CMakeLists.txt b/src/Base/CMakeLists.txt index 478bb59a8b..f2528e7155 100644 --- a/src/Base/CMakeLists.txt +++ b/src/Base/CMakeLists.txt @@ -243,7 +243,6 @@ SET(FreeCADBase_CPP_SRCS Matrix.cpp MatrixPyImp.cpp MemDebug.cpp - Mutex.cpp Observer.cpp Parameter.xsd Parameter.cpp @@ -314,7 +313,6 @@ SET(FreeCADBase_HPP_SRCS Interpreter.h Matrix.h MemDebug.h - Mutex.h Observer.h Parameter.h Persistence.h diff --git a/src/Base/Mutex.cpp b/src/Base/Mutex.cpp deleted file mode 100644 index e3d07c4a4e..0000000000 --- a/src/Base/Mutex.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2022 Werner Mayer * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" - -#include "Mutex.h" - - -#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) -QRecursiveMutex::QRecursiveMutex() - : QMutex(QMutex::Recursive) -{} - -QRecursiveMutex::~QRecursiveMutex() -{} -#endif diff --git a/src/Base/Mutex.h b/src/Base/Mutex.h deleted file mode 100644 index e65db63092..0000000000 --- a/src/Base/Mutex.h +++ /dev/null @@ -1,39 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2022 Werner Mayer * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library 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 Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#ifndef BASE_MUTEX_H -#define BASE_MUTEX_H - -#include -#include - -#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) -class BaseExport QRecursiveMutex: public QMutex -{ -public: - QRecursiveMutex(); - ~QRecursiveMutex(); -}; -#endif - -#endif // BASE_MUTEX_H diff --git a/src/Base/PreCompiled.h b/src/Base/PreCompiled.h index f81b2e771b..b38b44a68d 100644 --- a/src/Base/PreCompiled.h +++ b/src/Base/PreCompiled.h @@ -73,6 +73,7 @@ #include #include #include +#include #include // streams @@ -130,8 +131,6 @@ #include #include #include -#include -#include #include #include diff --git a/src/Base/Sequencer.cpp b/src/Base/Sequencer.cpp index 4d41dc0009..3ab27b74be 100644 --- a/src/Base/Sequencer.cpp +++ b/src/Base/Sequencer.cpp @@ -24,12 +24,11 @@ #include "PreCompiled.h" #ifndef _PreComp_ -#include +#include +#include #endif #include "Sequencer.h" -#include "Mutex.h" - using namespace Base; @@ -40,7 +39,7 @@ struct SequencerP // members static std::vector _instances; /**< A vector of all created instances */ static SequencerLauncher* _topLauncher; /**< The outermost launcher */ - static QRecursiveMutex mutex; /**< A mutex-locker for the launcher */ + static std::recursive_mutex mutex; /**< A mutex-locker for the launcher */ /** Sets a global sequencer object. * Access to the last registered object is performed by @see Sequencer(). */ @@ -66,7 +65,7 @@ struct SequencerP */ std::vector SequencerP::_instances; SequencerLauncher* SequencerP::_topLauncher = nullptr; -QRecursiveMutex SequencerP::mutex; +std::recursive_mutex SequencerP::mutex; } // namespace Base SequencerBase& SequencerBase::Instance() @@ -160,7 +159,7 @@ bool SequencerBase::isBlocking() const bool SequencerBase::setLocked(bool bLocked) { - QMutexLocker locker(&SequencerP::mutex); + std::lock_guard locker(SequencerP::mutex); bool old = this->_bLocked; this->_bLocked = bLocked; return old; @@ -168,19 +167,19 @@ bool SequencerBase::setLocked(bool bLocked) bool SequencerBase::isLocked() const { - QMutexLocker locker(&SequencerP::mutex); + std::lock_guard locker(SequencerP::mutex); return this->_bLocked; } bool SequencerBase::isRunning() const { - QMutexLocker locker(&SequencerP::mutex); + std::lock_guard locker(SequencerP::mutex); return (SequencerP::_topLauncher != nullptr); } bool SequencerBase::wasCanceled() const { - QMutexLocker locker(&SequencerP::mutex); + std::lock_guard locker(SequencerP::mutex); return this->_bCanceled; } @@ -236,7 +235,7 @@ void ConsoleSequencer::resetData() SequencerLauncher::SequencerLauncher(const char* pszStr, size_t steps) { - QMutexLocker locker(&SequencerP::mutex); + std::lock_guard locker(SequencerP::mutex); // Have we already an instance of SequencerLauncher created? if (!SequencerP::_topLauncher) { SequencerBase::Instance().start(pszStr, steps); @@ -246,24 +245,22 @@ SequencerLauncher::SequencerLauncher(const char* pszStr, size_t steps) SequencerLauncher::~SequencerLauncher() { - QMutexLocker locker(&SequencerP::mutex); + std::lock_guard locker(SequencerP::mutex); if (SequencerP::_topLauncher == this) { SequencerBase::Instance().stop(); - } - if (SequencerP::_topLauncher == this) { SequencerP::_topLauncher = nullptr; } } void SequencerLauncher::setText(const char* pszTxt) { - QMutexLocker locker(&SequencerP::mutex); + std::lock_guard locker(SequencerP::mutex); SequencerBase::Instance().setText(pszTxt); } bool SequencerLauncher::next(bool canAbort) { - QMutexLocker locker(&SequencerP::mutex); + std::lock_guard locker(SequencerP::mutex); if (SequencerP::_topLauncher != this) { return true; // ignore } @@ -272,13 +269,13 @@ bool SequencerLauncher::next(bool canAbort) void SequencerLauncher::setProgress(size_t pos) { - QMutexLocker locker(&SequencerP::mutex); + std::lock_guard locker(SequencerP::mutex); SequencerBase::Instance().setProgress(pos); } size_t SequencerLauncher::numberOfSteps() const { - QMutexLocker locker(&SequencerP::mutex); + std::lock_guard locker(SequencerP::mutex); return SequencerBase::Instance().numberOfSteps(); }