From 0a41c4199f9d1b6974d59b6114de607ac1d77690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Omn=C3=A8s?= <26088210+flomnes@users.noreply.github.com> Date: Mon, 26 Feb 2024 13:06:55 +0100 Subject: [PATCH] Remove Yuni::Mutex, use std::mutex instead (#1964) Remove deprecated Yuni::Mutex, use std::mutex instead. Co-authored-by: Nicolas Salmieri Co-authored-by: OMNES Florian Co-authored-by: Vincent Payet --- .../benchmarking/DurationCollector.cpp | 2 +- .../antares/benchmarking/file_content.cpp | 4 +-- src/libs/antares/io/statistics.cpp | 31 ++++++++++--------- src/libs/antares/memory/memory.cpp | 11 ++++--- src/libs/antares/study/finder/finder.cpp | 14 ++++----- .../include/antares/study/finder/finder.h | 14 +++++---- .../antares/study/progression/progression.h | 3 +- .../antares/study/progression/progression.cpp | 2 +- src/libs/antares/sys/policy.cpp | 18 +++++------ src/libs/antares/writer/zip_writer.cpp | 4 +-- src/libs/fswalker/fswalker.cpp | 7 +++-- src/ui/common/dispatcher/action.cpp | 5 +-- src/ui/simulator/application/main/logs.cpp | 2 +- .../datagrid/renderer/analyzer/areas.cpp | 18 +++++------ .../datagrid/renderer/analyzer/areas.h | 3 +- .../renderer/constraintsbuilder/links.h | 3 +- .../simulator/toolbox/ext-source/performer.h | 3 +- src/ui/simulator/toolbox/jobs/job.cpp | 10 +++--- src/ui/simulator/toolbox/jobs/job.h | 5 +-- .../simulator/windows/analyzer/analyzer.cpp | 2 +- src/ui/simulator/windows/cleaner.cpp | 8 ++--- src/ui/simulator/windows/cleaner.h | 3 +- src/ui/simulator/windows/output/output.h | 4 +-- .../windows/output/panel/area-link.cpp | 4 +-- .../simulator/windows/output/panel/panel.cpp | 12 +++---- src/ui/simulator/windows/output/panel/panel.h | 6 ++-- .../windows/output/spotlight-provider.cpp | 2 +- src/ui/simulator/windows/studylogs.h | 3 +- 28 files changed, 108 insertions(+), 95 deletions(-) diff --git a/src/libs/antares/benchmarking/DurationCollector.cpp b/src/libs/antares/benchmarking/DurationCollector.cpp index 404560aff0..6d6dfe4db7 100644 --- a/src/libs/antares/benchmarking/DurationCollector.cpp +++ b/src/libs/antares/benchmarking/DurationCollector.cpp @@ -26,7 +26,7 @@ namespace Benchmarking { void DurationCollector::addDuration(const std::string& name, int64_t duration) { - const std::lock_guard lock(mutex_); + const std::lock_guard lock(mutex_); duration_items_[name].push_back(duration); } diff --git a/src/libs/antares/benchmarking/file_content.cpp b/src/libs/antares/benchmarking/file_content.cpp index 2dc8998c86..8f2c64765b 100644 --- a/src/libs/antares/benchmarking/file_content.cpp +++ b/src/libs/antares/benchmarking/file_content.cpp @@ -38,13 +38,13 @@ FileContent::iterator FileContent::end() void FileContent::addItemToSection(const string& section, const string& key, int value) { - std::lock_guard guard(pSectionsMutex); + std::lock_guard guard(pSectionsMutex); sections_[section][key] = to_string(value); } void FileContent::addItemToSection(const string& section, const string& key, const string& value) { - std::lock_guard guard(pSectionsMutex); + std::lock_guard guard(pSectionsMutex); sections_[section][key] = value; } diff --git a/src/libs/antares/io/statistics.cpp b/src/libs/antares/io/statistics.cpp index a1aa3c4946..0df899f87b 100644 --- a/src/libs/antares/io/statistics.cpp +++ b/src/libs/antares/io/statistics.cpp @@ -19,6 +19,7 @@ ** along with Antares_Simulator. If not, see . */ +#include #include "antares/io/statistics.h" #include #include @@ -41,61 +42,61 @@ static uint64_t gWrittenToDiskSinceStartup; static uint64_t gReadFromNetworkSinceStartup; static uint64_t gWrittenToNetworkSinceStartup; -static Yuni::Mutex gMutex; +static std::mutex gMutex; } // anonymous namespace uint64_t ReadFromDisk() { - Yuni::MutexLocker locker(gMutex); + std::lock_guard locker(gMutex); return (uint64_t)gReadFromDisk; } uint64_t WrittenToDisk() { - Yuni::MutexLocker locker(gMutex); + std::lock_guard locker(gMutex); return (uint64_t)gWrittenToDisk; } uint64_t ReadFromDiskSinceStartup() { - Yuni::MutexLocker locker(gMutex); + std::lock_guard locker(gMutex); return (uint64_t)gReadFromDiskSinceStartup; } uint64_t WrittenToDiskSinceStartup() { - Yuni::MutexLocker locker(gMutex); + std::lock_guard locker(gMutex); return (int64_t)gWrittenToDiskSinceStartup; } uint64_t ReadFromNetwork() { - Yuni::MutexLocker locker(gMutex); + std::lock_guard locker(gMutex); return (uint64_t)gReadFromNetwork; } uint64_t WrittenToNetwork() { - Yuni::MutexLocker locker(gMutex); + std::lock_guard locker(gMutex); return (uint64_t)gWrittenToNetwork; } uint64_t ReadFromNetworkSinceStartup() { - Yuni::MutexLocker locker(gMutex); + std::lock_guard locker(gMutex); return (uint64_t)gReadFromNetworkSinceStartup; } uint64_t WrittenToNetworkSinceStartup() { - Yuni::MutexLocker locker(gMutex); + std::lock_guard locker(gMutex); return (uint64_t)gWrittenToNetworkSinceStartup; } void Reset() { - Yuni::MutexLocker locker(gMutex); + std::lock_guard locker(gMutex); gReadFromDisk = 0; gReadFromNetwork = 0; gWrittenToDisk = 0; @@ -104,7 +105,7 @@ void Reset() void DumpToLogs() { - Yuni::MutexLocker locker(gMutex); + std::lock_guard locker(gMutex); logs.info() << "[statistics] disk: read: " << (gReadFromDisk / 1024) << " ko, written: " << (gWrittenToDisk / 1024) << " ko"; logs.info() << "[statistics] network: read: " << (gReadFromNetwork / 1024) @@ -113,28 +114,28 @@ void DumpToLogs() void HasReadFromDisk(uint64_t size) { - Yuni::MutexLocker locker(gMutex); + std::lock_guard locker(gMutex); gReadFromDisk += size; gReadFromDiskSinceStartup += size; } void HasWrittenToDisk(uint64_t size) { - Yuni::MutexLocker locker(gMutex); + std::lock_guard locker(gMutex); gWrittenToDisk += size; gWrittenToDiskSinceStartup += size; } void HasReadFromNetwork(uint64_t size) { - Yuni::MutexLocker locker(gMutex); + std::lock_guard locker(gMutex); gReadFromNetwork += size; gReadFromNetworkSinceStartup += size; } void HasWrittenToNetwork(uint64_t size) { - Yuni::MutexLocker locker(gMutex); + std::lock_guard locker(gMutex); gWrittenToNetwork += size; gWrittenToNetworkSinceStartup += size; } diff --git a/src/libs/antares/memory/memory.cpp b/src/libs/antares/memory/memory.cpp index cdfc1a6a9f..38697f86ec 100644 --- a/src/libs/antares/memory/memory.cpp +++ b/src/libs/antares/memory/memory.cpp @@ -19,6 +19,7 @@ ** along with Antares_Simulator. If not, see . */ +#include #include #include #include @@ -53,12 +54,12 @@ Memory memory; namespace // anonymous { // Global mutex for memory handler -static Yuni::Mutex gMutex; +static std::mutex gMutex; } // anonymous namespace bool Memory::initializeTemporaryFolder() { - Yuni::MutexLocker locker(gMutex); + std::lock_guard locker(gMutex); if (pAlreadyInitialized) return true; @@ -122,19 +123,19 @@ void Memory::displayInfo() const logs.info() << " memory pool: system info: page size: " << sysconf(_SC_PAGESIZE); #endif - Yuni::MutexLocker locker(gMutex); + std::lock_guard locker(gMutex); logs.info() << " memory pool: cache folder: " << pCacheFolder; } const String& Memory::cacheFolder() const { - MutexLocker locker(gMutex); + std::lock_guard locker(gMutex); return pCacheFolder; } void Memory::cacheFolder(const AnyString& folder) { - MutexLocker locker(gMutex); + std::lock_guard locker(gMutex); if (pAllowedToChangeCacheFolder) pCacheFolder = folder; } diff --git a/src/libs/antares/study/finder/finder.cpp b/src/libs/antares/study/finder/finder.cpp index 484be90794..51edbc4d99 100644 --- a/src/libs/antares/study/finder/finder.cpp +++ b/src/libs/antares/study/finder/finder.cpp @@ -86,7 +86,7 @@ StudyFinder::StudyFinder() : pLycos(nullptr) { } -StudyFinder::StudyFinder(const StudyFinder&) : ThreadingPolicy(), pLycos(nullptr) +StudyFinder::StudyFinder(const StudyFinder&) : pLycos(nullptr) { } @@ -101,28 +101,28 @@ StudyFinder::~StudyFinder() void StudyFinder::stop(uint timeout) { - ThreadingPolicy::MutexLocker locker(*this); + std::lock_guard locker(mutex); if (pLycos) pLycos->stop(timeout); } void StudyFinder::wait() { - ThreadingPolicy::MutexLocker locker(*this); + std::lock_guard locker(mutex); if (pLycos) pLycos->wait(); } void StudyFinder::wait(uint timeout) { - ThreadingPolicy::MutexLocker locker(*this); + std::lock_guard locker(mutex); if (pLycos) pLycos->wait(timeout); } void StudyFinder::lookup(const Yuni::String::Vector& folder) { - ThreadingPolicy::MutexLocker locker(*this); + std::lock_guard locker(mutex); if (pLycos) pLycos->stop(10000); else @@ -138,7 +138,7 @@ void StudyFinder::lookup(const Yuni::String::Vector& folder) void StudyFinder::lookup(const Yuni::String::List& folder) { - ThreadingPolicy::MutexLocker locker(*this); + std::lock_guard locker(mutex); if (pLycos) pLycos->stop(10000); else @@ -153,7 +153,7 @@ void StudyFinder::lookup(const Yuni::String::List& folder) void StudyFinder::lookup(const String& folder) { - ThreadingPolicy::MutexLocker locker(*this); + std::lock_guard locker(mutex); if (pLycos) pLycos->stop(10000); else diff --git a/src/libs/antares/study/include/antares/study/finder/finder.h b/src/libs/antares/study/include/antares/study/finder/finder.h index f6b8ff75f2..c3d2558efd 100644 --- a/src/libs/antares/study/include/antares/study/finder/finder.h +++ b/src/libs/antares/study/include/antares/study/finder/finder.h @@ -21,11 +21,15 @@ #ifndef __ANTARES_LIB_FINDER_FINDER_H__ #define __ANTARES_LIB_FINDER_FINDER_H__ +#include #include #include #include "antares/study/study.h" #include +#include "../version.h" + + namespace Antares { namespace Data @@ -33,13 +37,10 @@ namespace Data /*! ** \brief Look for study folders asynchronously */ -class StudyFinder : public Yuni::Policy::ObjectLevelLockable +class StudyFinder { public: - //! The threading policy - using ThreadingPolicy = Yuni::Policy::ObjectLevelLockable; - enum - { + enum { //! The default value for the timeout defaultTimeout = 10000, // 10s }; @@ -123,7 +124,8 @@ class StudyFinder : public Yuni::Policy::ObjectLevelLockable virtual void onLookupAborted() { } - +protected: + std::mutex mutex; private: Yuni::IO::Directory::IIterator* pLycos; diff --git a/src/libs/antares/study/include/antares/study/progression/progression.h b/src/libs/antares/study/include/antares/study/progression/progression.h index 3d179ade61..814685f8f8 100644 --- a/src/libs/antares/study/include/antares/study/progression/progression.h +++ b/src/libs/antares/study/include/antares/study/progression/progression.h @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -183,7 +184,7 @@ class Progression final // Progression::Part::Map parts; Part::ListRef inUse; - Yuni::Mutex mutex; + std::mutex mutex; uint nbParallelYears; // Because writing something to the logs might be expensive, we have to diff --git a/src/libs/antares/study/progression/progression.cpp b/src/libs/antares/study/progression/progression.cpp index b60a40a9eb..e9c4690cf7 100644 --- a/src/libs/antares/study/progression/progression.cpp +++ b/src/libs/antares/study/progression/progression.cpp @@ -148,7 +148,7 @@ Progression::~Progression() bool Progression::saveToFile(const Yuni::String& filename, IResultWriter& writer) { Yuni::Clob buffer; - MutexLocker locker(pProgressMeter.mutex); + std::lock_guard locker(pProgressMeter.mutex); { uint year; const Part::Map::const_iterator end = pProgressMeter.parts.end(); diff --git a/src/libs/antares/sys/policy.cpp b/src/libs/antares/sys/policy.cpp index 5d00c1c4b4..1803671d4d 100644 --- a/src/libs/antares/sys/policy.cpp +++ b/src/libs/antares/sys/policy.cpp @@ -20,6 +20,7 @@ */ #include "antares/sys/policy.h" +#include #include #include #include "antares/sys/appdata.h" @@ -50,8 +51,7 @@ using PolicyMap = std::map; //! All entries static PolicyMap* entries = nullptr; -//! Mutex for policy entries -static Mutex gsMutex; +static std::mutex gsMutex;//!< Mutex for policy entries template static void OpenFromINIFileWL(const String& filename, const StringT& hostname) @@ -162,7 +162,7 @@ static inline void ExpansionWL() bool Open(bool expandEntries) { // avoid concurrent changes - MutexLocker locker(gsMutex); + std::lock_guard locker(gsMutex); if (localPoliciesOpened) return true; @@ -233,7 +233,7 @@ bool Open(bool expandEntries) void Close() { // avoid concurrent changes - MutexLocker locker(gsMutex); + std::lock_guard locker(gsMutex); if (localPoliciesOpened) { @@ -249,7 +249,7 @@ void Close() bool Read(String& out, const PolicyKey& key) { // avoid concurrent changes - MutexLocker locker(gsMutex); + std::lock_guard locker(gsMutex); if (not key.empty() and entries) { @@ -267,7 +267,7 @@ bool Read(String& out, const PolicyKey& key) bool ReadAsBool(const PolicyKey& key, bool defval) { // avoid concurrent changes - MutexLocker locker(gsMutex); + std::lock_guard locker(gsMutex); if (not key.empty() and entries) { @@ -285,7 +285,7 @@ bool ReadAsBool(const PolicyKey& key, bool defval) void DumpToString(Clob& out) { // avoid concurrent changes - MutexLocker locker(gsMutex); + std::lock_guard locker(gsMutex); if (!entries or entries->empty()) return; @@ -319,7 +319,7 @@ void DumpToString(Clob& out) void DumpToLogs() { // avoid concurrent changes - MutexLocker locker(gsMutex); + std::lock_guard locker(gsMutex); if (not entries or entries->empty()) { @@ -339,7 +339,7 @@ void DumpToLogs() void CheckRootPrefix(const char* argv0) { // avoid concurrent changes - MutexLocker locker(gsMutex); + std::lock_guard locker(gsMutex); if (entries == nullptr) return; diff --git a/src/libs/antares/writer/zip_writer.cpp b/src/libs/antares/writer/zip_writer.cpp index fc52f95897..0e5b66b5fc 100644 --- a/src/libs/antares/writer/zip_writer.cpp +++ b/src/libs/antares/writer/zip_writer.cpp @@ -88,7 +88,7 @@ void ZipWriteJob::writeEntry() auto file_info = createInfo(pEntryPath); Benchmarking::Timer timer_wait; - std::lock_guard guard(pZipMutex); // Wait + std::lock_guard guard(pZipMutex); // Wait timer_wait.stop(); pDurationCollector.addDuration("zip_wait", timer_wait.get_duration()); @@ -196,7 +196,7 @@ void ZipWriter::finalize(bool verbose) if (verbose) logs.notice() << "Writing results..."; - std::lock_guard guard(pZipMutex); + std::lock_guard guard(pZipMutex); if (int ret = mz_zip_writer_close(pZipHandle); ret != MZ_OK && verbose) logs.warning() << "Error closing the zip file " << pArchivePath << " (" << ret << ")"; diff --git a/src/libs/fswalker/fswalker.cpp b/src/libs/fswalker/fswalker.cpp index d92fae897c..978936b0f4 100644 --- a/src/libs/fswalker/fswalker.cpp +++ b/src/libs/fswalker/fswalker.cpp @@ -21,6 +21,7 @@ #include "fswalker.h" #include +#include #include #include #include @@ -39,8 +40,8 @@ using namespace Antares; namespace FSWalker { -//! Mutex for the global queueservice -static Yuni::Mutex gsMutex; + +static std::mutex gsMutex;//!< Mutex for the global queueservice static bool queueserviceInitialized = false; //! Global Queue service static Job::QueueService queueservice; @@ -132,7 +133,7 @@ WalkerThread::WalkerThread(Statistics& stats) : pFileJob(nullptr), pOriginalStat pJobCounter = std::make_shared>(); pShouldStop = false; - MutexLocker locker(gsMutex); + std::lock_guard locker(gsMutex); if (not queueserviceInitialized) { queueserviceInitialized = true; diff --git a/src/ui/common/dispatcher/action.cpp b/src/ui/common/dispatcher/action.cpp index 6384abe65c..be721728be 100644 --- a/src/ui/common/dispatcher/action.cpp +++ b/src/ui/common/dispatcher/action.cpp @@ -19,6 +19,7 @@ ** along with Antares_Simulator. If not, see . */ +#include #include #include #include @@ -44,7 +45,7 @@ using DispatcherServiceType = Yuni::Job::QueueService; static DispatcherServiceType gDispatcher; static LinkedList gGUIDispatcherList; -static Yuni::Mutex gGUIMutex; +static std::mutex gGUIMutex; class JobDelay final : public Yuni::Job::IJob { @@ -138,7 +139,7 @@ void Wait() bool Empty() { - Yuni::MutexLocker locker(Antares::Dispatcher::gGUIMutex); + std::lock_guard locker(Antares::Dispatcher::gGUIMutex); return Antares::Dispatcher::gGUIDispatcherList.empty(); } diff --git a/src/ui/simulator/application/main/logs.cpp b/src/ui/simulator/application/main/logs.cpp index 1dd7b2063e..06d417674a 100644 --- a/src/ui/simulator/application/main/logs.cpp +++ b/src/ui/simulator/application/main/logs.cpp @@ -48,7 +48,7 @@ class LogInfo final using WaitingLogEntries = std::vector; WaitingLogEntries waitingLogEntry; -Yuni::Mutex logMutex; +std::mutex logMutex; std::atomic logUpdateCount; diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/analyzer/areas.cpp b/src/ui/simulator/toolbox/components/datagrid/renderer/analyzer/areas.cpp index 6ad6e63d84..7657e324dd 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/analyzer/areas.cpp +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/analyzer/areas.cpp @@ -108,7 +108,7 @@ void Areas::reloadDistributionLawsFromStudy(Data::TimeSeriesType ts) void Areas::resetStatus(Record::Status status, bool invalidateSize) { - Yuni::MutexLocker locker(pRecord.mutex); + std::lock_guard locker(pRecord.mutex); auto end = pRecord.array.end(); for (auto i = pRecord.array.begin(); i != end; ++i) { @@ -145,7 +145,7 @@ wxString Areas::columnCaption(int colIndx) const wxString Areas::rowCaption(int rowIndx) const { - Yuni::MutexLocker locker(pRecord.mutex); + std::lock_guard locker(pRecord.mutex); if (rowIndx < (int)pRecord.size()) return pRecord.array[rowIndx].wxAreaName; return wxEmptyString; @@ -153,7 +153,7 @@ wxString Areas::rowCaption(int rowIndx) const IRenderer::CellStyle Areas::cellStyle(int col, int row) const { - Yuni::MutexLocker locker(pRecord.mutex); + std::lock_guard locker(pRecord.mutex); if (row >= (int)pRecord.size()) return IRenderer::cellStyleError; const Record& record = pRecord.array[row]; @@ -189,7 +189,7 @@ wxColour Areas::cellTextColor(int, int) const wxString Areas::cellValue(int x, int y) const { - Yuni::MutexLocker locker(pRecord.mutex); + std::lock_guard locker(pRecord.mutex); if (y >= (int)pRecord.size()) return wxEmptyString; const Record& record = pRecord.array[y]; @@ -224,7 +224,7 @@ wxString Areas::cellValue(int x, int y) const double Areas::cellNumericValue(int x, int y) const { - Yuni::MutexLocker locker(pRecord.mutex); + std::lock_guard locker(pRecord.mutex); if (y >= (int)pRecord.size()) return IRenderer::cellStyleError; const Record& record = pRecord.array[y]; @@ -245,7 +245,7 @@ bool Areas::cellValue(int x, int y, const String& value) { if (x == 0) { - Yuni::MutexLocker locker(pRecord.mutex); + std::lock_guard locker(pRecord.mutex); if (y >= (int)pRecord.size()) return false; pOnBeforeUpdate(x, y); @@ -261,7 +261,7 @@ bool Areas::cellValue(int x, int y, const String& value) } if (x == 1) // distribution { - Yuni::MutexLocker locker(pRecord.mutex); + std::lock_guard locker(pRecord.mutex); if (y >= (int)pRecord.size()) return false; Record& record = pRecord.array[y]; @@ -278,7 +278,7 @@ bool Areas::cellValue(int x, int y, const String& value) } if (x == 2) // absolute { - Yuni::MutexLocker locker(pRecord.mutex); + std::lock_guard locker(pRecord.mutex); if (y >= (int)pRecord.size()) return false; Record& record = pRecord.array[y]; @@ -303,7 +303,7 @@ bool Areas::cellValue(int x, int y, const String& value) } if (x == 3) { - Yuni::MutexLocker locker(pRecord.mutex); + std::lock_guard locker(pRecord.mutex); if (y >= (int)pRecord.size()) return false; pOnBeforeUpdate(x, y); diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/analyzer/areas.h b/src/ui/simulator/toolbox/components/datagrid/renderer/analyzer/areas.h index bc0e7985ef..22e41882a8 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/analyzer/areas.h +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/analyzer/areas.h @@ -23,6 +23,7 @@ #include "../../renderer.h" #include +#include #include #include #include @@ -70,7 +71,7 @@ class Areas final : public virtual Renderer::IRenderer } public: - mutable Yuni::Mutex mutex; + mutable std::mutex mutex; std::vector array; bool canRunAnalyzer; }; diff --git a/src/ui/simulator/toolbox/components/datagrid/renderer/constraintsbuilder/links.h b/src/ui/simulator/toolbox/components/datagrid/renderer/constraintsbuilder/links.h index 26e0acd69a..b8907fab63 100644 --- a/src/ui/simulator/toolbox/components/datagrid/renderer/constraintsbuilder/links.h +++ b/src/ui/simulator/toolbox/components/datagrid/renderer/constraintsbuilder/links.h @@ -24,6 +24,7 @@ #include "../../renderer.h" #include #include "antares/solver/constraints-builder/cbuilder.h" +#include #include #include #include @@ -70,7 +71,7 @@ class Links final : public virtual Renderer::IRenderer } public: - mutable Yuni::Mutex mutex; + mutable std::mutex mutex; std::vector array; bool canRunAnalyzer; }; diff --git a/src/ui/simulator/toolbox/ext-source/performer.h b/src/ui/simulator/toolbox/ext-source/performer.h index 1f2372f51a..8188014efe 100644 --- a/src/ui/simulator/toolbox/ext-source/performer.h +++ b/src/ui/simulator/toolbox/ext-source/performer.h @@ -28,6 +28,7 @@ #include #include "../components/progressbar.h" #include +#include namespace Antares { @@ -93,7 +94,7 @@ class PerformerDialog : public wxDialog wxTimer* pTimer; Yuni::Thread::IThread* pThread; - Yuni::Mutex pMutex; + std::mutex pMutex; std::atomic pGUINeedRefresh; std::atomic pProgression; std::atomic pProgressionMax; diff --git a/src/ui/simulator/toolbox/jobs/job.cpp b/src/ui/simulator/toolbox/jobs/job.cpp index 524fbb0380..35e9115dfd 100644 --- a/src/ui/simulator/toolbox/jobs/job.cpp +++ b/src/ui/simulator/toolbox/jobs/job.cpp @@ -19,6 +19,7 @@ ** along with Antares_Simulator. If not, see . */ +#include #include #include #include @@ -368,7 +369,7 @@ class TimerElapsedTime final : public Yuni::Thread::Timer bool pUseProgression; Job& pJob; wxDateTime pStartTime; - Yuni::Mutex pMutex; + std::mutex pMutex; PartList& pParts; }; // class TimerElapsedTime @@ -474,7 +475,7 @@ class TimerRemainingTime final : public Yuni::Thread::Timer class MessageFlusherTimer final : public wxTimer { public: - MessageFlusherTimer(const wxString& messageBuffer, wxStaticText* label, Yuni::Mutex& mutex) : + MessageFlusherTimer(const wxString& messageBuffer, wxStaticText* label, std::mutex& mutex) : wxTimer(), pMessageBuffer(messageBuffer), pLabel(label), pMutex(mutex) { assert(pLabel != NULL); @@ -487,7 +488,7 @@ class MessageFlusherTimer final : public wxTimer virtual void Notify() { { - Yuni::MutexLocker locker(pMutex); + std::lock_guard locker(pMutex); // We use .c_str() here to force the copy of the string if (pStrCopy == pMessageBuffer) return; @@ -503,8 +504,7 @@ class MessageFlusherTimer final : public wxTimer wxString pStrCopy; //! GUI label wxStaticText* pLabel; - //! Mutex - Yuni::Mutex& pMutex; + std::mutex& pMutex; }; // class MessageFlusherTimer diff --git a/src/ui/simulator/toolbox/jobs/job.h b/src/ui/simulator/toolbox/jobs/job.h index d32ab773e2..4f4c1000d6 100644 --- a/src/ui/simulator/toolbox/jobs/job.h +++ b/src/ui/simulator/toolbox/jobs/job.h @@ -37,6 +37,7 @@ #include "../create.h" #include +#include #include #include @@ -285,8 +286,8 @@ class Job : public wxDialog, public Yuni::IEventObserver wxString pMessage; wxString pSubMessage; - Yuni::Mutex pMutex; - Yuni::Mutex pErrorMutex; + std::mutex pMutex; + std::mutex pErrorMutex; PartList* pPartList; diff --git a/src/ui/simulator/windows/analyzer/analyzer.cpp b/src/ui/simulator/windows/analyzer/analyzer.cpp index 0afe2c702e..7e688488f8 100644 --- a/src/ui/simulator/windows/analyzer/analyzer.cpp +++ b/src/ui/simulator/windows/analyzer/analyzer.cpp @@ -183,7 +183,7 @@ class AnalyzeSourceFolder final : public Yuni::Thread::IThread private: AnalyzerWizard& pForm; - Mutex pDataMutex; + std::mutex pDataMutex; String pFolder; AnalyzerWizard::FileMappingPtr pMapping; diff --git a/src/ui/simulator/windows/cleaner.cpp b/src/ui/simulator/windows/cleaner.cpp index 502beafed5..c8368f9dd5 100644 --- a/src/ui/simulator/windows/cleaner.cpp +++ b/src/ui/simulator/windows/cleaner.cpp @@ -55,7 +55,7 @@ class CleaningThread final : public Yuni::Thread::IThread { // Removing references to this instance { - Yuni::MutexLocker locker(pParent->pMutex); + std::lock_guard locker(pParent->pMutex); if (pParent->pInfos) pParent->pInfos->onProgress.unbind(); } @@ -66,7 +66,7 @@ class CleaningThread final : public Yuni::Thread::IThread virtual bool onStarting() override { // Cleaning - Yuni::MutexLocker locker(pParent->pMutex); + std::lock_guard locker(pParent->pMutex); if (pParent->pInfos) { pParent->pInfos->onProgress.bind(this, &CleaningThread::onProgress); @@ -241,7 +241,7 @@ void StudyCleaner::studyFolder(const wxString& folder) // Reset internal variables { - Yuni::MutexLocker locker(pMutex); + std::lock_guard locker(pMutex); if (&pFolder != &folder) // avoid possible undefined behavior pFolder = folder; pProgressionCount = 0; @@ -397,7 +397,7 @@ void StudyCleaner::updateGUI(bool hasItems) void StudyCleaner::progress(uint count) { - Yuni::MutexLocker locker(pMutex); + std::lock_guard locker(pMutex); pProgressionCount = count; } diff --git a/src/ui/simulator/windows/cleaner.h b/src/ui/simulator/windows/cleaner.h index c42022d6c3..b8add294ba 100644 --- a/src/ui/simulator/windows/cleaner.h +++ b/src/ui/simulator/windows/cleaner.h @@ -21,6 +21,7 @@ #ifndef __ANTARES_APPLICATION_WINDOW_CLEANER_H__ #define __ANTARES_APPLICATION_WINDOW_CLEANER_H__ +#include #include #include #include @@ -90,7 +91,7 @@ class StudyCleaner final : public wxDialog wxTimer* pRefreshTimer; Yuni::Thread::IThread* pThread; - Yuni::Mutex pMutex; + std::mutex pMutex; uint pProgressionCount; friend class CleaningThread; diff --git a/src/ui/simulator/windows/output/output.h b/src/ui/simulator/windows/output/output.h index 3b0bbca14b..4e83b77fb6 100644 --- a/src/ui/simulator/windows/output/output.h +++ b/src/ui/simulator/windows/output/output.h @@ -21,6 +21,7 @@ #ifndef __ANTARES_WINDOWS_OUTPUT_OUTPUT_H__ #define __ANTARES_WINDOWS_OUTPUT_OUTPUT_H__ +#include #include #include "../../application/study.h" #include "../../toolbox/components/button.h" @@ -372,8 +373,7 @@ class Component : public Antares::Component::Panel, public Yuni::IEventObserver< //! \name Background process //@{ - //! Mutex - Yuni::Mutex pMutex; + std::mutex pMutex; //! Jobs Antares::Private::OutputViewerData::JobVector pJobs; //! All already prepared outputs diff --git a/src/ui/simulator/windows/output/panel/area-link.cpp b/src/ui/simulator/windows/output/panel/area-link.cpp index 32a2434c73..eecbbc2bf9 100644 --- a/src/ui/simulator/windows/output/panel/area-link.cpp +++ b/src/ui/simulator/windows/output/panel/area-link.cpp @@ -121,7 +121,7 @@ class JobMatrix : public Yuni::Job::IJob, public Yuni::IEventObserver { // file lock auto mutex = ProvideLockingForFileLocking(filename); - Yuni::MutexLocker locker(*mutex); + std::lock_guard locker(*mutex); if (not shouldAbort) success = pMatrix->loadFromCSVFile(filename, 1, 0, options); } @@ -275,7 +275,7 @@ class JobAggregator : public Yuni::Job::IJob, public Yuni::IEventObserver Panel::pPanelsInCallingLoadDataFromFile = 0; namespace // anonymous { -static std::map> mutexForFiles; -static Yuni::Mutex mutexToAccessToLockFiles; +static std::map> mutexForFiles; +static std::mutex mutexToAccessToLockFiles; static inline void DefaultBckColour(Antares::Component::Panel* panel) { @@ -472,18 +472,18 @@ void Panel::executeAggregator() delete exec; } -std::shared_ptr ProvideLockingForFileLocking(const YString& filename) +std::shared_ptr ProvideLockingForFileLocking(const YString& filename) { - Yuni::MutexLocker locker(mutexToAccessToLockFiles); + std::lock_guard locker(mutexToAccessToLockFiles); auto& ptr = mutexForFiles[filename]; if (!ptr) - ptr = std::make_shared(); + ptr = std::make_shared(); return ptr; } void ClearAllMutexForFileLocking() { - Yuni::MutexLocker locker(mutexToAccessToLockFiles); + std::lock_guard locker(mutexToAccessToLockFiles); mutexForFiles.clear(); } diff --git a/src/ui/simulator/windows/output/panel/panel.h b/src/ui/simulator/windows/output/panel/panel.h index 5cabf4e6e1..d9eec73201 100644 --- a/src/ui/simulator/windows/output/panel/panel.h +++ b/src/ui/simulator/windows/output/panel/panel.h @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -142,8 +143,7 @@ class Panel final : public Antares::Component::Panel wxWindow* pButton; bool pShouldRebuildMessage; - //! Mutex - Yuni::Mutex pMutex; + std::mutex pMutex; //! Data IData* pData; //! Filename currently used @@ -163,7 +163,7 @@ class Panel final : public Antares::Component::Panel ** This variable is cleared when the study is closed or the user get back ** to the input */ -std::shared_ptr ProvideLockingForFileLocking(const YString& filename); +std::shared_ptr ProvideLockingForFileLocking(const YString& filename); /*! ** \brief Clear all mutex for file locking diff --git a/src/ui/simulator/windows/output/spotlight-provider.cpp b/src/ui/simulator/windows/output/spotlight-provider.cpp index 791718bcdf..cca302e2e1 100644 --- a/src/ui/simulator/windows/output/spotlight-provider.cpp +++ b/src/ui/simulator/windows/output/spotlight-provider.cpp @@ -139,7 +139,7 @@ void SpotlightProvider::search(Spotlight::IItem::Vector& out, return; // Looking for the list of areas and links - Yuni::MutexLocker locker(pComponent->pMutex); + std::lock_guard locker(pComponent->pMutex); auto it = pComponent->pAlreadyPreparedContents.find(outputPath); if (it == pComponent->pAlreadyPreparedContents.end()) diff --git a/src/ui/simulator/windows/studylogs.h b/src/ui/simulator/windows/studylogs.h index ab4fe81e91..66a5321734 100644 --- a/src/ui/simulator/windows/studylogs.h +++ b/src/ui/simulator/windows/studylogs.h @@ -21,6 +21,7 @@ #ifndef __ANTARES_APPLICATION_WINDOWS_STUDY_LOGS_H__ #define __ANTARES_APPLICATION_WINDOWS_STUDY_LOGS_H__ +#include #include #include @@ -180,7 +181,7 @@ class StudyLogs final : public Component::Frame::WxLocalFrame //! Temporary structure used for displaying the list of all available files LogFilenameInfo::Map pLogFilenameInfo; - Yuni::Mutex pLoadingMutex; + std::mutex pLoadingMutex; //! Flag to display all log files bool pShowAllLogsFiles;