Skip to content

Commit

Permalink
Remove Yuni::Mutex, use std::mutex instead (#1964)
Browse files Browse the repository at this point in the history
Remove deprecated Yuni::Mutex, use std::mutex instead.

Co-authored-by: Nicolas Salmieri <[email protected]>
Co-authored-by: OMNES Florian <[email protected]>
Co-authored-by: Vincent Payet <[email protected]>
  • Loading branch information
4 people authored Feb 26, 2024
1 parent 48fa527 commit 0a41c41
Show file tree
Hide file tree
Showing 28 changed files with 108 additions and 95 deletions.
2 changes: 1 addition & 1 deletion src/libs/antares/benchmarking/DurationCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Benchmarking {

void DurationCollector::addDuration(const std::string& name, int64_t duration)
{
const std::lock_guard<std::mutex> lock(mutex_);
const std::lock_guard lock(mutex_);
duration_items_[name].push_back(duration);
}

Expand Down
4 changes: 2 additions & 2 deletions src/libs/antares/benchmarking/file_content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ FileContent::iterator FileContent::end()

void FileContent::addItemToSection(const string& section, const string& key, int value)
{
std::lock_guard<std::mutex> 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<std::mutex> guard(pSectionsMutex);
std::lock_guard guard(pSectionsMutex);
sections_[section][key] = value;
}

Expand Down
31 changes: 16 additions & 15 deletions src/libs/antares/io/statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/

#include <mutex>
#include "antares/io/statistics.h"
#include <yuni/core/atomic/int.h>
#include <antares/logs/logs.h>
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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;
}
Expand Down
11 changes: 6 additions & 5 deletions src/libs/antares/memory/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
*/

#include <mutex>
#include <yuni/io/directory.h>
#include <yuni/core/system/windows.hdr.h>
#include <yuni/core/system/environment.h>
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
14 changes: 7 additions & 7 deletions src/libs/antares/study/finder/finder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ StudyFinder::StudyFinder() : pLycos(nullptr)
{
}

StudyFinder::StudyFinder(const StudyFinder&) : ThreadingPolicy(), pLycos(nullptr)
StudyFinder::StudyFinder(const StudyFinder&) : pLycos(nullptr)
{
}

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
14 changes: 8 additions & 6 deletions src/libs/antares/study/include/antares/study/finder/finder.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,26 @@
#ifndef __ANTARES_LIB_FINDER_FINDER_H__
#define __ANTARES_LIB_FINDER_FINDER_H__

#include <mutex>
#include <yuni/yuni.h>
#include <yuni/core/string.h>
#include "antares/study/study.h"
#include <yuni/io/directory/iterator.h>

#include "../version.h"


namespace Antares
{
namespace Data
{
/*!
** \brief Look for study folders asynchronously
*/
class StudyFinder : public Yuni::Policy::ObjectLevelLockable<StudyFinder>
class StudyFinder
{
public:
//! The threading policy
using ThreadingPolicy = Yuni::Policy::ObjectLevelLockable<StudyFinder>;
enum
{
enum {
//! The default value for the timeout
defaultTimeout = 10000, // 10s
};
Expand Down Expand Up @@ -123,7 +124,8 @@ class StudyFinder : public Yuni::Policy::ObjectLevelLockable<StudyFinder>
virtual void onLookupAborted()
{
}

protected:
std::mutex mutex;
private:
Yuni::IO::Directory::IIterator<true>* pLycos;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <yuni/core/singleton.h>
#include <yuni/thread/timer.h>
#include <mutex>
#include <map>
#include <list>
#include <vector>
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/libs/antares/study/progression/progression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 0a41c41

Please sign in to comment.