From 7ec97f8f19318d6535c0b1b0e32258ce371a6a1f Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Thu, 9 Apr 2020 09:38:28 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/filesystem/paths_mt.cpp | 34 ++++++++++++++++++++++ src/myx/filesystem/paths_mt.hpp | 50 +++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 src/myx/filesystem/paths_mt.cpp create mode 100644 src/myx/filesystem/paths_mt.hpp diff --git a/src/myx/filesystem/paths_mt.cpp b/src/myx/filesystem/paths_mt.cpp new file mode 100644 index 0000000..cffebf0 --- /dev/null +++ b/src/myx/filesystem/paths_mt.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +#include + +#include +#include + +namespace myx { + +namespace filesystem { + +PathsMT::PathsMT() = default; + +PathsMT* PathsMT::instance() +{ + volatile PathsMT* localInstance = mInstance.load( std::memory_order_acquire ); + if ( localInstance == nullptr ) + { + std::lock_guard< std::mutex > myLock( mMutex ); + localInstance = mInstance.load( std::memory_order_relaxed ); + if ( localInstance == nullptr ) // -V1036 + { + localInstance = new PathsMT(); + mInstance.store( const_cast< PathsMT* >( localInstance ), std::memory_order_release ); // NOLINT + } + } + return( const_cast< PathsMT* >( localInstance ) ); // NOLINT +} + +} // namespace filesystem + +} // namespace myx diff --git a/src/myx/filesystem/paths_mt.hpp b/src/myx/filesystem/paths_mt.hpp new file mode 100644 index 0000000..1e5a5bc --- /dev/null +++ b/src/myx/filesystem/paths_mt.hpp @@ -0,0 +1,50 @@ +/** + * @file paths.hpp + * @brief Стандартные пути к каталогам и файлам + */ + +#ifndef MYX_FILESYSTEM_PATHS_MT_HPP_ +#define MYX_FILESYSTEM_PATHS_MT_HPP_ + +#pragma once + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +namespace myx { + +namespace filesystem { + +/// @brief Потокобезопасная версия класса myx::filesystem::Paths +class PathsMT : public Paths +{ + PathsMT(); + ~PathsMT() = default; + PathsMT( const PathsMT& ) = delete; + PathsMT& operator=( const PathsMT& ) = delete; + + static std::atomic< PathsMT* > mInstance; + static std::mutex mMutex; + +public: + /** + * @brief getInstance + * @return Уникальный экземпляр класса PathsMT + */ + static PathsMT* instance(); +}; // class PathsMT + +} // namespace filesystem + +} // namespace myx + +#endif // MYX_FILESYSTEM_PATHS_MT_HPP_