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_