Base: Use std::recursive_mutex

This commit is contained in:
Ladislav Michl
2023-03-29 15:49:45 +02:00
committed by 3x380V
parent 562fb5114a
commit 915bfd3dde
5 changed files with 15 additions and 96 deletions

View File

@@ -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

View File

@@ -1,36 +0,0 @@
/***************************************************************************
* Copyright (c) 2022 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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

View File

@@ -1,39 +0,0 @@
/***************************************************************************
* Copyright (c) 2022 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <QMutex>
#include <FCGlobal.h>
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
class BaseExport QRecursiveMutex: public QMutex
{
public:
QRecursiveMutex();
~QRecursiveMutex();
};
#endif
#endif // BASE_MUTEX_H

View File

@@ -73,6 +73,7 @@
#include <stack>
#include <queue>
#include <memory>
#include <mutex>
#include <bitset>
// streams
@@ -130,8 +131,6 @@
#include <QWriteLocker>
#include <QReadLocker>
#include <QReadWriteLock>
#include <QMutex>
#include <QMutexLocker>
#include <QTime>
#include <QUuid>

View File

@@ -24,12 +24,11 @@
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QMutexLocker>
#include <mutex>
#include <vector>
#endif
#include "Sequencer.h"
#include "Mutex.h"
using namespace Base;
@@ -40,7 +39,7 @@ struct SequencerP
// members
static std::vector<SequencerBase*> _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<SequencerBase*> 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<std::recursive_mutex> 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<std::recursive_mutex> locker(SequencerP::mutex);
return this->_bLocked;
}
bool SequencerBase::isRunning() const
{
QMutexLocker locker(&SequencerP::mutex);
std::lock_guard<std::recursive_mutex> locker(SequencerP::mutex);
return (SequencerP::_topLauncher != nullptr);
}
bool SequencerBase::wasCanceled() const
{
QMutexLocker locker(&SequencerP::mutex);
std::lock_guard<std::recursive_mutex> 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<std::recursive_mutex> 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<std::recursive_mutex> 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<std::recursive_mutex> locker(SequencerP::mutex);
SequencerBase::Instance().setText(pszTxt);
}
bool SequencerLauncher::next(bool canAbort)
{
QMutexLocker locker(&SequencerP::mutex);
std::lock_guard<std::recursive_mutex> 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<std::recursive_mutex> locker(SequencerP::mutex);
SequencerBase::Instance().setProgress(pos);
}
size_t SequencerLauncher::numberOfSteps() const
{
QMutexLocker locker(&SequencerP::mutex);
std::lock_guard<std::recursive_mutex> locker(SequencerP::mutex);
return SequencerBase::Instance().numberOfSteps();
}