Реализация в cpp

This commit is contained in:
Andrei Astafev 2020-04-06 00:06:57 +03:00
parent ce596d8113
commit 76a655aa6c
2 changed files with 18 additions and 16 deletions

View File

@ -13,6 +13,23 @@ namespace filesystem {
Paths::Paths() = default;
Paths* Paths::getInstance()
{
volatile Paths* localInstance = mInstance.load( std::memory_order_acquire );
if ( !localInstance )
{
std::lock_guard< std::mutex > myLock( mMutex );
localInstance = mInstance.load( std::memory_order_relaxed );
if ( !localInstance ) // -V1036
{
localInstance = new Paths();
mInstance.store( const_cast< Paths* >( localInstance ), std::memory_order_release );
}
}
return( const_cast< Paths* >( localInstance ) );
}
Paths::HierarchyType Paths::getHierarchyType()
{
QRegExp binRegexp( "/s*bin$" );

View File

@ -91,22 +91,7 @@ public:
* @brief getInstance
* @return Уникальный экземпляр класса Paths
*/
static Paths* getInstance()
{
volatile Paths* localInstance = mInstance.load( std::memory_order_acquire );
if ( !localInstance )
{
std::lock_guard< std::mutex > myLock( mMutex );
localInstance = mInstance.load( std::memory_order_relaxed );
if ( !localInstance ) // -V1036
{
localInstance = new Paths();
mInstance.store( const_cast< Paths* >( localInstance ), std::memory_order_release );
}
}
return( const_cast< Paths* >( localInstance ) );
}
static Paths* getInstance();
/**
* @brief Обновление путей с учётом расположения исполняемого файла