fec77632ef
* Fix issues with seedlist for AutomatedTesting Fixes error reporting so it will show the file hint in the tool. Removes any missing assets from the .seed file. Remove an unnecessary dependency from AutomatedTesting dependencies file. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Make ArchiveComponent use AZ::IO::IArchive Initial changes that will get the sychronous calls in ArchiveComponent to use IArchive interface rather than external zip/7z tools. Some of the asynchronous api are still in place, anything that wasn't being used has been removed for now. This may change later if we move towards all the api being asynchronous. Until then, we can't remove the reliance upon the external archive tools completely. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Updates AZStd::thread constructors Adds a variadic constructor which forwards args to the functor. Because of our thread_desc extension, there was confusion on the arugments, so the args were reordered to take the thread_desc first, before the functor and args. Also the thread_desc is taken as reference rather than by pointer. Update callsites to account for this change. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Async operation of ArchiveComponent api This sets up the ArchiveComponent to operate asynchronously. It uses promise/future to transfer results to caller. This is still broken, there's a few things that need to get fixed up, but this is a good checkpoint for the work as it solidifies the api, cleans up a bunch of unused code, and compiles. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Removes the platform-specific ArchiveComponen These are no longer needed, as they control the direct interaction with host OS tools like 7za.exe or /bin/zip. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Removes the platform-specific files from cmake Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Removes the 7za.exe (and legal notice) This tool is no longer needed in the repo. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Fixes usage of IArchive::GetFullPath() This changed to return a PathView, updated to reflect that. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Fix promises and threads Make sure promises are only set exactly once. This meant reworking some of the initial error checking. Detach threads when created. Adds [[nodiscard]] to the functions that return a future. Since threads are detached, the future is the main way to get communication from the thread. Clean up interface, add comments. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * More edits to thread creation Changes to thread construction to account for parameter change. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Fix some remaining issues with ArchiveComponent Put created threads inside a container, then join them at Deactivate. Fix asset bundler case when injecting a file with no working directory. Fix thread constructor that applies args to a function. Fix lambdas to take string args by value rather than reference. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Fixes some remaining bugs in ArchiveComponent Open archive as read-only during extract & list operations. Fixes paths issues. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Fix initialize of opaque thread handle in thread_UnixLike.h Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Removed unused variable in AssetBundleComponent.cpp to fix compiler warning Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Fix some issues with archives File paths in the CDR and the local headers need to match, but there were issues with path separators and case that made it possible to get invalid headers errors in some archives. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Adds some new ArchiveComponent unit tests Adds new tests for extraction of archive and adding files from a file list to an archive. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Fix file data offset issues when opening archives When opening an INestedArchive it would run through the CDR headers to create file entries in the zip cache. The offsets to the compressed data were being calculated incorrectly because they were using the CDR headers rather than jumping to the local file headers and getting offsets from those sizes. Removed and refactored some archive validation flow and zip cache factory init methods to either init default or init w/ additional validation checks. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Addresses PR feedback Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Address more points of feedback in PR Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Address additional PR feedback Fixes up some error checks and uses of strings vs paths. Enable archive component tests on Linux so we can see if they will pass. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Address PR feedback Change the INestedArchive interface to list files as AZ::IO::Path. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Disabling the ArchiveComponent tests on Linux They failed so we will revisit them to attempt a fix. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Rename a member variable to be more accurate Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Address feedback on PR Bump version of Archive Components for serialize context. Improve error messages during archive open and validation. Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> * Revert recent changes Signed-off-by: amzn-phist <52085794+amzn-phist@users.noreply.github.com> Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
417 lines
21 KiB
C++
417 lines
21 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
#include <SaveDataSystemComponent.h>
|
|
#include <SaveData/SaveDataNotificationBus.h>
|
|
|
|
#include <AzCore/Serialization/SerializeContext.h>
|
|
#include <AzCore/Serialization/EditContext.h>
|
|
#include <AzCore/Serialization/EditContextConstants.inl>
|
|
|
|
#include <AzCore/IO/SystemFile.h>
|
|
#include <AzCore/std/parallel/lock.h>
|
|
#include <AzCore/std/parallel/thread.h>
|
|
#include <AzCore/std/smart_ptr/make_shared.h>
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
namespace SaveData
|
|
{
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
const char* SaveDataFileExtension = ".savedata";
|
|
const char* TempSaveDataFileExtension = ".tmpsavedata";
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SaveDataSystemComponent::Reflect(AZ::ReflectContext* context)
|
|
{
|
|
if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
|
|
{
|
|
serialize->Class<SaveDataSystemComponent, AZ::Component>()
|
|
->Version(0);
|
|
|
|
if (AZ::EditContext* ec = serialize->GetEditContext())
|
|
{
|
|
ec->Class<SaveDataSystemComponent>("SaveData", "Provides functionality for saving and loading persistent user data.")
|
|
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
|
|
->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System"))
|
|
->Attribute(AZ::Edit::Attributes::AutoExpand, true)
|
|
;
|
|
}
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SaveDataSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
|
|
{
|
|
provided.push_back(AZ_CRC("SaveDataService"));
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SaveDataSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
|
|
{
|
|
incompatible.push_back(AZ_CRC("SaveDataService"));
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SaveDataSystemComponent::Activate()
|
|
{
|
|
m_pimpl.reset(Implementation::Create(*this));
|
|
SaveDataRequestBus::Handler::BusConnect();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SaveDataSystemComponent::Deactivate()
|
|
{
|
|
SaveDataRequestBus::Handler::BusDisconnect();
|
|
m_pimpl.reset();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SaveDataSystemComponent::SaveDataBuffer(const SaveDataBufferParams& saveDataBufferParams)
|
|
{
|
|
if (m_pimpl)
|
|
{
|
|
m_pimpl->SaveDataBuffer(saveDataBufferParams);
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SaveDataSystemComponent::LoadDataBuffer(const LoadDataBufferParams& loadDataBufferParams)
|
|
{
|
|
if (m_pimpl)
|
|
{
|
|
m_pimpl->LoadDataBuffer(loadDataBufferParams);
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SaveDataSystemComponent::SetSaveDataDirectoryPath(const char* saveDataDirectoryPath)
|
|
{
|
|
if (m_pimpl)
|
|
{
|
|
m_pimpl->SetSaveDataDirectoryPath(saveDataDirectoryPath);
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
SaveDataSystemComponent::Implementation::Implementation(SaveDataSystemComponent& saveDataSystemComponent)
|
|
: m_saveDataSystemComponent(saveDataSystemComponent)
|
|
{
|
|
AZ::TickBus::Handler::BusConnect();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
SaveDataSystemComponent::Implementation::~Implementation()
|
|
{
|
|
AZ::TickBus::Handler::BusDisconnect();
|
|
|
|
// Make sure we join all active threads, regardless of their completion state.
|
|
JoinAllActiveThreads();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SaveDataSystemComponent::Implementation::OnSaveDataBufferComplete(const AZStd::string& dataBufferName,
|
|
const AzFramework::LocalUserId localUserId,
|
|
const SaveDataRequests::OnDataBufferSaved& callback,
|
|
const SaveDataNotifications::Result& result)
|
|
{
|
|
// Always queue the OnDataBufferSaved notification back on the main thread.
|
|
// Even if this is being called from the main thread already, this ensures
|
|
// the callback / notifications are aways sent at the same time each frame.
|
|
AZ::TickBus::QueueFunction([dataBufferName, localUserId, callback, result]()
|
|
{
|
|
SaveDataNotifications::DataBufferSavedParams dataBufferSavedParams;
|
|
dataBufferSavedParams.dataBufferName = dataBufferName;
|
|
dataBufferSavedParams.localUserId = localUserId;
|
|
dataBufferSavedParams.result = result;
|
|
if (callback)
|
|
{
|
|
callback(dataBufferSavedParams);
|
|
}
|
|
SaveDataNotificationBus::Broadcast(&SaveDataNotifications::OnDataBufferSaved,
|
|
dataBufferSavedParams);
|
|
});
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SaveDataSystemComponent::Implementation::SaveDataBufferToFileSystem(const SaveDataBufferParams& saveDataBufferParams,
|
|
const AZStd::string& absoluteFilePath,
|
|
bool waitForCompletion,
|
|
bool useTemporaryFile)
|
|
{
|
|
// Perform parameter error checking but handle gracefully
|
|
AZ_Assert(saveDataBufferParams.dataBuffer, "Invalid param: dataBuffer");
|
|
AZ_Assert(saveDataBufferParams.dataBufferSize, "Invalid param: dataBufferSize");
|
|
AZ_Assert(!saveDataBufferParams.dataBufferName.empty(), "Invalid param: dataBufferName");
|
|
if (!saveDataBufferParams.dataBuffer ||
|
|
!saveDataBufferParams.dataBufferSize ||
|
|
saveDataBufferParams.dataBufferName.empty())
|
|
{
|
|
OnSaveDataBufferComplete(saveDataBufferParams.dataBufferName,
|
|
saveDataBufferParams.localUserId,
|
|
saveDataBufferParams.callback,
|
|
SaveDataNotifications::Result::ErrorInvalid);
|
|
return;
|
|
}
|
|
|
|
// Start a new thread to perform the save, capturing the necessary parameters by value,
|
|
// except for the data buffer itself which must be moved (because it is a unique_ptr).
|
|
AZStd::thread_desc saveThreadDesc;
|
|
saveThreadDesc.m_cpuId = AFFINITY_MASK_USERTHREADS;
|
|
saveThreadDesc.m_name = "SaveDataBufferToFileSystem";
|
|
ThreadCompletionPair* threadCompletionPair = nullptr;
|
|
{
|
|
AZStd::lock_guard<AZStd::mutex> lock(m_activeThreadsMutex);
|
|
m_activeThreads.emplace_back();
|
|
threadCompletionPair = &m_activeThreads.back();
|
|
}
|
|
|
|
// This is safe access outside the lock guard because we only remove elements from the list
|
|
// after the thread completion flag has been set to true (see also JoinAllCompletedThreads).
|
|
threadCompletionPair->m_thread = AZStd::make_unique<AZStd::thread>(saveThreadDesc,
|
|
[&threadCompleteFlag = threadCompletionPair->m_threadComplete,
|
|
dataBuffer = AZStd::move(saveDataBufferParams.dataBuffer),
|
|
dataBufferSize = saveDataBufferParams.dataBufferSize,
|
|
dataBufferName = saveDataBufferParams.dataBufferName,
|
|
onSavedCallback = saveDataBufferParams.callback,
|
|
localUserId = saveDataBufferParams.localUserId,
|
|
absoluteFilePath,
|
|
useTemporaryFile]()
|
|
{
|
|
SaveDataNotifications::Result result = SaveDataNotifications::Result::ErrorUnspecified;
|
|
|
|
// If useTemporaryFile == true we save first to a '.tmp' file so we
|
|
// do not overwrite existing save data until we are sure of success.
|
|
const AZStd::string tempSaveDataFilePath = absoluteFilePath + TempSaveDataFileExtension;
|
|
const AZStd::string finalSaveDataFilePath = absoluteFilePath + SaveDataFileExtension;
|
|
|
|
// Open the temp save data file for writing, creating it (and
|
|
// any intermediate directories) if it doesn't already exist.
|
|
AZ::IO::SystemFile systemFile;
|
|
const bool openFileResult = systemFile.Open(useTemporaryFile ? tempSaveDataFilePath.c_str() : finalSaveDataFilePath.c_str(),
|
|
AZ::IO::SystemFile::SF_OPEN_WRITE_ONLY |
|
|
AZ::IO::SystemFile::SF_OPEN_CREATE |
|
|
AZ::IO::SystemFile::SF_OPEN_CREATE_PATH);
|
|
if (!openFileResult)
|
|
{
|
|
result = SaveDataNotifications::Result::ErrorIOFailure;
|
|
}
|
|
else
|
|
{
|
|
// Write the data buffer to the temp file and then close it.
|
|
const AZ::IO::SystemFile::SizeType bytesWritten = systemFile.Write(dataBuffer.get(),
|
|
dataBufferSize);
|
|
systemFile.Close();
|
|
|
|
// Verify that we wrote the correct number of bytes.
|
|
if (bytesWritten != dataBufferSize)
|
|
{
|
|
result = SaveDataNotifications::Result::ErrorIOFailure;
|
|
}
|
|
else if (useTemporaryFile)
|
|
{
|
|
// Rename the temp save data file we successfully wrote to.
|
|
const bool renameFileResult = AZ::IO::SystemFile::Rename(tempSaveDataFilePath.c_str(),
|
|
finalSaveDataFilePath.c_str(),
|
|
true);
|
|
result = renameFileResult ? SaveDataNotifications::Result::Success :
|
|
SaveDataNotifications::Result::ErrorIOFailure;
|
|
|
|
// Delete the temp save data file.
|
|
AZ::IO::SystemFile::Delete(tempSaveDataFilePath.c_str());
|
|
}
|
|
else
|
|
{
|
|
result = SaveDataNotifications::Result::Success;
|
|
}
|
|
}
|
|
|
|
// Invoke the callback and broadcast the OnDataBufferSaved notification from the main thread.
|
|
OnSaveDataBufferComplete(dataBufferName, localUserId, onSavedCallback, result);
|
|
|
|
// Set the thread completion flag so it will be joined in JoinAllCompletedThreads.
|
|
threadCompleteFlag = true;
|
|
});
|
|
|
|
if (waitForCompletion)
|
|
{
|
|
// The thread completion flag will be set in join, and the thread completion
|
|
// pair removed from m_activeThreads when JoinAllCompletedThreads is called.
|
|
threadCompletionPair->m_thread->join();
|
|
threadCompletionPair->m_thread.reset();
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SaveDataSystemComponent::Implementation::OnLoadDataBufferComplete(SaveDataNotifications::DataBuffer dataBuffer,
|
|
AZ::u64 dataBufferSize,
|
|
const AZStd::string& dataBufferName,
|
|
const AzFramework::LocalUserId localUserId,
|
|
const SaveDataRequests::OnDataBufferLoaded& callback,
|
|
const SaveDataNotifications::Result& result)
|
|
{
|
|
AZ::TickBus::QueueFunction([dataBuffer, dataBufferSize, dataBufferName, localUserId, callback, result]()
|
|
{
|
|
SaveDataNotifications::DataBufferLoadedParams dataBufferLoadedParams;
|
|
dataBufferLoadedParams.dataBuffer = dataBuffer;
|
|
dataBufferLoadedParams.dataBufferSize = dataBufferSize;
|
|
dataBufferLoadedParams.dataBufferName = dataBufferName;
|
|
dataBufferLoadedParams.localUserId = localUserId;
|
|
dataBufferLoadedParams.result = result;
|
|
if (callback)
|
|
{
|
|
callback(dataBufferLoadedParams);
|
|
}
|
|
SaveDataNotificationBus::Broadcast(&SaveDataNotifications::OnDataBufferLoaded,
|
|
dataBufferLoadedParams);
|
|
});
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SaveDataSystemComponent::Implementation::LoadDataBufferFromFileSystem(const LoadDataBufferParams& loadDataBufferParams,
|
|
const AZStd::string& absoluteFilePath,
|
|
bool waitForCompletion)
|
|
{
|
|
// Perform parameter error checking but handle gracefully
|
|
AZ_Assert(!loadDataBufferParams.dataBufferName.empty(), "Invalid param: dataBufferName");
|
|
if (loadDataBufferParams.dataBufferName.empty())
|
|
{
|
|
OnLoadDataBufferComplete(nullptr,
|
|
0,
|
|
loadDataBufferParams.dataBufferName,
|
|
loadDataBufferParams.localUserId,
|
|
loadDataBufferParams.callback,
|
|
SaveDataNotifications::Result::ErrorInvalid);
|
|
return;
|
|
}
|
|
|
|
// Start a new thread to perform the load.
|
|
AZStd::thread_desc loadThreadDesc;
|
|
loadThreadDesc.m_cpuId = AFFINITY_MASK_USERTHREADS;
|
|
loadThreadDesc.m_name = "LoadDataBufferFromFileSystem";
|
|
ThreadCompletionPair* threadCompletionPair = nullptr;
|
|
{
|
|
AZStd::lock_guard<AZStd::mutex> lock(m_activeThreadsMutex);
|
|
m_activeThreads.emplace_back();
|
|
threadCompletionPair = &m_activeThreads.back();
|
|
}
|
|
|
|
// This is safe access outside the lock guard because we only remove elements from the list
|
|
// after the thread completion flag has been set to true (see also JoinAllCompletedThreads).
|
|
threadCompletionPair->m_thread = AZStd::make_unique<AZStd::thread>(loadThreadDesc,
|
|
[&threadCompleteFlag = threadCompletionPair->m_threadComplete,
|
|
loadDataBufferParams,
|
|
absoluteFilePath]()
|
|
{
|
|
SaveDataNotifications::DataBuffer dataBuffer = nullptr;
|
|
AZ::u64 dataBufferSize = 0;
|
|
SaveDataNotifications::Result result = SaveDataNotifications::Result::ErrorUnspecified;
|
|
|
|
// Open the save data file for reading.
|
|
AZ::IO::SystemFile systemFile;
|
|
const AZStd::string finalSaveDataFilePath = absoluteFilePath + SaveDataFileExtension;
|
|
const bool openFileResult = systemFile.Open(finalSaveDataFilePath.c_str(),
|
|
AZ::IO::SystemFile::SF_OPEN_READ_ONLY);
|
|
if (!openFileResult)
|
|
{
|
|
result = SaveDataNotifications::Result::ErrorNotFound;
|
|
}
|
|
else
|
|
{
|
|
// Allocate the memory we'll read the data buffer into.
|
|
// Please note that we use a custom deleter to free it.
|
|
const AZ::IO::SystemFile::SizeType fileLength = systemFile.Length();
|
|
dataBuffer = SaveDataNotifications::DataBuffer(azmalloc(fileLength),
|
|
[](void* p) { azfree(p); });
|
|
if (!dataBuffer)
|
|
{
|
|
AZ_Error("LoadDataBufferFromFileSystem", false, "Failed to allocate %llu bytes", fileLength);
|
|
result = SaveDataNotifications::Result::ErrorOutOfMemory;
|
|
}
|
|
else
|
|
{
|
|
// Read the contents of the file into a data buffer and then close it.
|
|
dataBufferSize = systemFile.Read(fileLength, dataBuffer.get());
|
|
systemFile.Close();
|
|
|
|
// Verify that we read the correct number of bytes.
|
|
result = (dataBufferSize == fileLength) ? SaveDataNotifications::Result::Success :
|
|
SaveDataNotifications::Result::ErrorIOFailure;
|
|
}
|
|
}
|
|
|
|
// Invoke the callback and broadcast the OnDataBufferLoaded notification from the main thread.
|
|
OnLoadDataBufferComplete(dataBuffer,
|
|
dataBufferSize,
|
|
loadDataBufferParams.dataBufferName,
|
|
loadDataBufferParams.localUserId,
|
|
loadDataBufferParams.callback,
|
|
result);
|
|
|
|
// Set the thread completion flag so it will be joined in JoinAllCompletedThreads.
|
|
threadCompleteFlag = true;
|
|
});
|
|
|
|
if (waitForCompletion)
|
|
{
|
|
// The thread completion flag will be set in join, and the thread completion
|
|
// pair removed from m_activeThreads when JoinAllCompletedThreads is called.
|
|
threadCompletionPair->m_thread->join();
|
|
threadCompletionPair->m_thread.reset();
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SaveDataSystemComponent::Implementation::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint scriptTimePoint)
|
|
{
|
|
// We could potentially only do this every n milliseconds, or perhaps try and signal when a
|
|
// thread completes and only check it then, but in almost all cases there will only ever be
|
|
// one save or load thread running at any time (if there are any at all), so iterating over
|
|
// the list each frame to check each atomic bool should not have any impact on performance.
|
|
JoinAllCompletedThreads();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SaveDataSystemComponent::Implementation::JoinAllActiveThreads()
|
|
{
|
|
AZStd::lock_guard<AZStd::mutex> lock(m_activeThreadsMutex);
|
|
for (auto& threadCompletionPair : m_activeThreads)
|
|
{
|
|
if (threadCompletionPair.m_thread && threadCompletionPair.m_thread->joinable())
|
|
{
|
|
threadCompletionPair.m_thread->join();
|
|
threadCompletionPair.m_thread.reset();
|
|
}
|
|
}
|
|
|
|
// It's important not to call clear (or otherwise modify m_activeThreads) here, but rather
|
|
// only in JoinAllCompletedThreads where we explicitly check for the m_threadComplete flag.
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
|
void SaveDataSystemComponent::Implementation::JoinAllCompletedThreads()
|
|
{
|
|
AZStd::lock_guard<AZStd::mutex> lock(m_activeThreadsMutex);
|
|
auto it = m_activeThreads.begin();
|
|
while (it != m_activeThreads.end())
|
|
{
|
|
if (it->m_threadComplete)
|
|
{
|
|
if (it->m_thread && it->m_thread->joinable())
|
|
{
|
|
it->m_thread->join();
|
|
}
|
|
it = m_activeThreads.erase(it);
|
|
}
|
|
else
|
|
{
|
|
++it;
|
|
}
|
|
}
|
|
}
|
|
}
|