Добавлены файлы

This commit is contained in:
Andrei Astafev 2020-04-09 09:38:28 +03:00
parent a39e514278
commit 7ec97f8f19
2 changed files with 84 additions and 0 deletions

View File

@ -0,0 +1,34 @@
#include <myx/base/config.hpp>
#include <myx/filesystem/current_executable.hpp>
#include <myx/filesystem/paths_mt.hpp>
#include <paths.h>
#include <QCoreApplication>
#include <QString>
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

View File

@ -0,0 +1,50 @@
/**
* @file paths.hpp
* @brief Стандартные пути к каталогам и файлам
*/
#ifndef MYX_FILESYSTEM_PATHS_MT_HPP_
#define MYX_FILESYSTEM_PATHS_MT_HPP_
#pragma once
#include <myx/filesystem/paths.hpp>
#include <myx/filesystem/current_executable.hpp>
#include <QString>
#include <QDir>
#include <QFileInfo>
#include <atomic>
#include <future>
#include <mutex>
#include <thread>
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_