VSIFileManager *VSIFileManager::Get()
{
static volatile GPtrDiff_t nConstructerPID = 0;
if( poManager != nullptr )
{
if( nConstructerPID != 0 )
{
GPtrDiff_t nCurrentPID = static_cast<GPtrDiff_t>(CPLGetPID());
if( nConstructerPID != nCurrentPID )
{
{
CPLMutexHolder oHolder( &hVSIFileManagerMutex );
}
// This construct to avoid a lock is highly questionable
// and could probably fail with out-of-order CPU execution
// so the cppcheck warning is probably quite relevant.
// cppcheck-suppress identicalInnerCondition
if( nConstructerPID != 0 )
{
VSIDebug1( "nConstructerPID != 0: %d", nConstructerPID);
assert(false);
}
}
}
return poManager;
}
CPLMutexHolder oHolder2( &hVSIFileManagerMutex );
if( poManager == nullptr )
{
nConstructerPID = static_cast<GPtrDiff_t>(CPLGetPID());
#ifdef DEBUG_VERBOSE
printf("Thread " CPL_FRMT_GIB": VSIFileManager in construction\n", // ok
static_cast<GIntBig>(nConstructerPID));
#endif
poManager = new VSIFileManager;
VSIInstallLargeFileHandler();
VSIInstallSubFileHandler();
VSIInstallMemFileHandler();
#ifdef HAVE_LIBZ
VSIInstallGZipFileHandler();
VSIInstallZipFileHandler();
#endif
#ifdef HAVE_CURL
VSIInstallCurlFileHandler();
VSIInstallCurlStreamingFileHandler();
VSIInstallS3FileHandler();
VSIInstallS3StreamingFileHandler();
VSIInstallGSFileHandler();
VSIInstallGSStreamingFileHandler();
VSIInstallAzureFileHandler();
VSIInstallAzureStreamingFileHandler();
VSIInstallOSSFileHandler();
VSIInstallOSSStreamingFileHandler();
VSIInstallSwiftFileHandler();
VSIInstallSwiftStreamingFileHandler();
#endif
VSIInstallStdinHandler();
VSIInstallStdoutHandler();
VSIInstallSparseFileHandler();
VSIInstallTarFileHandler();
VSIInstallCryptFileHandler();
#ifdef DEBUG_VERBOSE
printf("Thread " CPL_FRMT_GIB": VSIFileManager construction finished\n", // ok
static_cast<GIntBig>(nConstructerPID));
#endif
nConstructerPID = 0;
}
return poManager;
}