Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substitute recursive mutex enum with QRecursiveMutex #720

Merged
merged 1 commit into from Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions Engine/AppManager.cpp
Expand Up @@ -2023,10 +2023,18 @@ AppManager::registerPlugin(const QString& resourcesPath,
int minor,
bool isDeprecated)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QRecursiveMutex* pluginMutex = nullptr;
#else
QMutex* pluginMutex = 0;
#endif

if (mustCreateMutex) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
pluginMutex = new QRecursiveMutex();
#else
pluginMutex = new QMutex(QMutex::Recursive);
#endif
}
Plugin* plugin = new Plugin(binary, resourcesPath, pluginID, pluginLabel, pluginIconPath, groupIconPath, groups, pluginMutex, major, minor,
isReader, isWriter, isDeprecated);
Expand Down
15 changes: 15 additions & 0 deletions Engine/CurvePrivate.h
Expand Up @@ -33,6 +33,9 @@
#endif

#include <QtCore/QMutex>
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
#include <QRecursiveMutex>
#endif

#include "Engine/Variant.h"
#include "Engine/Knob.h"
Expand Down Expand Up @@ -67,7 +70,11 @@ struct CurvePrivate
CurveTypeEnum type;
double xMin, xMax;
double yMin, yMax;
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
mutable QRecursiveMutex _lock;
#else
mutable QMutex _lock; //< the plug-ins can call getValueAt at any moment and we must make sure the user is not playing around
#endif
bool isParametric;
bool isPeriodic;

Expand All @@ -83,14 +90,22 @@ struct CurvePrivate
, xMax(std::numeric_limits<double>::infinity())
, yMin(-std::numeric_limits<double>::infinity())
, yMax(std::numeric_limits<double>::infinity())
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
, _lock()
#else
, _lock(QMutex::Recursive)
#endif
, isParametric(false)
, isPeriodic(false)
{
}

CurvePrivate(const CurvePrivate & other)
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
: _lock()
#else
: _lock(QMutex::Recursive)
#endif
{
*this = other;
}
Expand Down
8 changes: 8 additions & 0 deletions Engine/EffectInstancePrivate.cpp
Expand Up @@ -423,7 +423,11 @@ EffectInstance::Implementation::Implementation(EffectInstance* publicInterface)
, metadata()
, runningClipPreferences(false)
, overlaysViewport(0)
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
, attachedContextsMutex()
#else
, attachedContextsMutex(QMutex::Recursive)
#endif
, attachedContexts()
, mainInstance(0)
, isDoingInstanceSafeRender(false)
Expand Down Expand Up @@ -453,7 +457,11 @@ EffectInstance::Implementation::Implementation(const Implementation& other)
, metadata(other.metadata)
, runningClipPreferences(other.runningClipPreferences)
, overlaysViewport(other.overlaysViewport)
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
, attachedContextsMutex()
#else
, attachedContextsMutex(QMutex::Recursive)
#endif
, attachedContexts()
, mainInstance(other._publicInterface)
, isDoingInstanceSafeRender(false)
Expand Down
7 changes: 7 additions & 0 deletions Engine/EffectInstancePrivate.h
Expand Up @@ -37,6 +37,9 @@
#include <QtCore/QCoreApplication>
#include <QtCore/QWaitCondition>
#include <QtCore/QMutex>
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
#include <QRecursiveMutex>
#endif

#include "Global/GlobalDefines.h"

Expand Down Expand Up @@ -224,7 +227,11 @@ class EffectInstance::Implementation

// set during interact actions on main-thread
OverlaySupport* overlaysViewport;
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
mutable QRecursiveMutex attachedContextsMutex;
#else
mutable QMutex attachedContextsMutex;
#endif
// A list of context that are currently attached (i.e attachOpenGLContext() has been called on them but not yet dettachOpenGLContext).
// If a plug-in returns false to supportsConcurrentOpenGLRenders() then whenever trying to attach a context, we take a lock in attachOpenGLContext
// that is released in dettachOpenGLContext so that there can only be a single attached OpenGL context at any time.
Expand Down
8 changes: 8 additions & 0 deletions Engine/Knob.cpp
Expand Up @@ -4887,7 +4887,11 @@ struct KnobHolder::KnobHolderPrivate
, isDequeingValuesSet(false)
, paramsEditLevel(eMultipleParamsEditOff)
, paramsEditRecursionLevel(0)
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
, evaluationBlockedMutex()
#else
, evaluationBlockedMutex(QMutex::Recursive)
#endif
, evaluationBlocked(0)
, canCurrentlySetValue(true)
, knobChanged()
Expand Down Expand Up @@ -4915,7 +4919,11 @@ struct KnobHolder::KnobHolderPrivate
, isDequeingValuesSet(other.isDequeingValuesSet)
, paramsEditLevel(other.paramsEditLevel)
, paramsEditRecursionLevel(other.paramsEditRecursionLevel)
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
, evaluationBlockedMutex()
#else
, evaluationBlockedMutex(QMutex::Recursive)
#endif
, evaluationBlocked(0)
, canCurrentlySetValue(other.canCurrentlySetValue)
, knobChanged()
Expand Down
15 changes: 15 additions & 0 deletions Engine/Knob.h
Expand Up @@ -42,6 +42,9 @@
#include <QtCore/QMutex>
#include <QtCore/QString>
#include <QtCore/QCoreApplication>
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
#include <QRecursiveMutex>
#endif

#include "Engine/Variant.h"
#include "Engine/AppManager.h" // for AppManager::createKnob
Expand Down Expand Up @@ -2246,7 +2249,11 @@ class Knob
typedef boost::shared_ptr<QueuedSetValueAtTime> QueuedSetValueAtTimePtr;

///Here is all the stuff we couldn't get rid of the template parameter
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
mutable QRecursiveMutex _valueMutex;
#else
mutable QMutex _valueMutex; //< protects _values & _guiValues & _defaultValues & ExprResults
#endif
std::vector<T> _values, _guiValues;

struct DefaultValue
Expand All @@ -2260,11 +2267,19 @@ class Knob
//Only for double and int
mutable QReadWriteLock _minMaxMutex;
std::vector<T> _minimums, _maximums, _displayMins, _displayMaxs;
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
mutable QRecursiveMutex _setValuesQueueMutex;
#else
mutable QMutex _setValuesQueueMutex;
#endif
std::list<boost::shared_ptr<QueuedSetValue> > _setValuesQueue;

///this flag is to avoid recursive setValue calls
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
mutable QRecursiveMutex _setValueRecursionLevelMutex;
#else
mutable QMutex _setValueRecursionLevelMutex;
#endif
int _setValueRecursionLevel;
};

Expand Down
12 changes: 12 additions & 0 deletions Engine/KnobImpl.h
Expand Up @@ -105,19 +105,31 @@ Knob<T>::Knob(KnobHolder* holder,
int dimension,
bool declaredByPlugin )
: KnobHelper(holder, description, dimension, declaredByPlugin)
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
, _valueMutex()
#else
, _valueMutex(QMutex::Recursive)
#endif
, _values(dimension)
, _guiValues(dimension)
, _defaultValues(dimension)
, _exprRes(dimension)
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
, _minMaxMutex()
#else
, _minMaxMutex(QReadWriteLock::Recursive)
#endif
, _minimums(dimension)
, _maximums(dimension)
, _displayMins(dimension)
, _displayMaxs(dimension)
, _setValuesQueueMutex()
, _setValuesQueue()
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
, _setValueRecursionLevelMutex()
#else
, _setValueRecursionLevelMutex(QMutex::Recursive)
#endif
, _setValueRecursionLevel(0)
{
initMinMax();
Expand Down
8 changes: 8 additions & 0 deletions Engine/NodeGroup.cpp
Expand Up @@ -1055,7 +1055,11 @@ NodeCollection::getParallelRenderArgs(std::map<NodePtr, ParallelRenderArgsPtr>&

struct NodeGroupPrivate
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
mutable QRecursiveMutex nodesLock;
#else
mutable QMutex nodesLock; // protects inputs & outputs
#endif
std::vector<NodeWPtr> inputs, guiInputs;
NodesWList outputs, guiOutputs;
bool isDeactivatingGroup;
Expand All @@ -1064,7 +1068,11 @@ struct NodeGroupPrivate
KnobButtonPtr exportAsTemplate, convertToGroup;

NodeGroupPrivate()
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
: nodesLock()
#else
: nodesLock(QMutex::Recursive)
#endif
, inputs()
, guiInputs()
, outputs()
Expand Down
4 changes: 4 additions & 0 deletions Engine/NodePrivate.h
Expand Up @@ -173,7 +173,11 @@ struct Node::Implementation
, mustQuitPreview(0)
, mustQuitPreviewMutex()
, mustQuitPreviewCond()
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
, renderInstancesSharedMutex()
#else
, renderInstancesSharedMutex(QMutex::Recursive)
#endif
, knobsAge(0)
, knobsAgeMutex()
, masterNodeMutex()
Expand Down
4 changes: 4 additions & 0 deletions Engine/OfxHost.cpp
Expand Up @@ -1534,7 +1534,11 @@ OfxHost::mutexCreate(OfxMutexHandle *mutex,

// suite functions should not throw
try {
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QRecursiveMutex* m = new QRecursiveMutex();
#else
QMutex* m = new QMutex(QMutex::Recursive);
#endif
for (int i = 0; i < lockCount; ++i) {
m->lock();
}
Expand Down
4 changes: 4 additions & 0 deletions Engine/Plugin.cpp
Expand Up @@ -180,7 +180,11 @@ Plugin::getGrouping() const
return _grouping;
}

#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QRecursiveMutex*
#else
QMutex*
#endif
Plugin::getPluginLock() const
{
return _lock;
Expand Down
15 changes: 15 additions & 0 deletions Engine/Plugin.h
Expand Up @@ -34,6 +34,9 @@
#include <list>
#include <QtCore/QString>
#include <QtCore/QStringList>
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
#include <QRecursiveMutex>
#endif

#if !defined(Q_MOC_RUN) && !defined(SBK_RUN)
#include <boost/shared_ptr.hpp>
Expand Down Expand Up @@ -173,7 +176,11 @@ class Plugin
QString _pythonModule;
OFX::Host::ImageEffect::ImageEffectPlugin* _ofxPlugin;
OFX::Host::ImageEffect::Descriptor* _ofxDescriptor;
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QRecursiveMutex* _lock;
#else
QMutex* _lock;
#endif
int _majorVersion;
int _minorVersion;
NATRON_ENUM::ContextEnum _ofxContext;
Expand Down Expand Up @@ -239,7 +246,11 @@ class Plugin
const QString & iconFilePath,
const QStringList & groupIconFilePath,
const QStringList & grouping,
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QRecursiveMutex* lock,
#else
QMutex* lock,
#endif
int majorVersion,
int minorVersion,
bool isReader,
Expand Down Expand Up @@ -338,7 +349,11 @@ class Plugin

bool getToolsetScript() const;

#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QRecursiveMutex* getPluginLock() const;
#else
QMutex* getPluginLock() const;
#endif
LibraryBinary* getLibraryBinary() const;

int getMajorVersion() const;
Expand Down
4 changes: 4 additions & 0 deletions Engine/ProjectPrivate.cpp
Expand Up @@ -64,7 +64,11 @@ ProjectPrivate::ProjectPrivate(Project* project)
, projectCreationTime(ageSinceLastSave)
, builtinFormats()
, additionalFormats()
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
, formatMutex()
#else
, formatMutex(QMutex::Recursive)
#endif
, envVars()
, projectName()
, projectPath()
Expand Down
4 changes: 4 additions & 0 deletions Engine/ProjectPrivate.h
Expand Up @@ -68,7 +68,11 @@ struct ProjectPrivate
QDateTime projectCreationTime; //< the project creation time
std::list<Format> builtinFormats;
std::list<Format> additionalFormats; //< added by the user
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
mutable QRecursiveMutex formatMutex;
#else
mutable QMutex formatMutex; //< protects builtinFormats & additionalFormats
#endif


///Project parameters (settings)
Expand Down
4 changes: 4 additions & 0 deletions Gui/GuiPrivate.cpp
Expand Up @@ -198,7 +198,11 @@ GuiPrivate::GuiPrivate(const GuiAppInstancePtr& app,
, _lastPluginDir()
, _nextViewerTabPlace(0)
, _leftRightSplitter(0)
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
, _viewerTabsMutex()
#else
, _viewerTabsMutex(QMutex::Recursive) // Gui::createNodeViewerInterface() may cause a resizeEvent, which calls Gui:redrawAllViewers()
#endif
, _viewerTabs()
, _masterSyncViewer(0)
, _activeViewer(0)
Expand Down
4 changes: 4 additions & 0 deletions Gui/GuiPrivate.h
Expand Up @@ -156,7 +156,11 @@ struct GuiPrivate
Splitter* _leftRightSplitter;

///a list of ptrs to all the viewer tabs.
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
mutable QRecursiveMutex _viewerTabsMutex;
#else
mutable QMutex _viewerTabsMutex;
#endif
std::list<ViewerTab*> _viewerTabs;

///Used when all viewers are synchronized to determine which one triggered the sync
Expand Down