Android: Don't hold gameFileCache lock during updateAdditionalMetadata
It seems like we spend a lot of the game list scanning time in updateAdditionalMetadata, which I suppose makes sense considering how many different files that function attempts to open. With the addition of just one little atomic operation, we can make it safe to call updateAdditionalMetadata without holding a lock.
This commit is contained in:
parent
bba33c7ced
commit
fb265b610d
|
@ -194,26 +194,27 @@ public final class GameFileCacheService extends IntentService
|
|||
{
|
||||
String[] gamePaths = GameFileCache.getAllGamePaths();
|
||||
|
||||
boolean changed;
|
||||
synchronized (gameFileCache)
|
||||
{
|
||||
boolean changed = gameFileCache.update(gamePaths);
|
||||
if (changed)
|
||||
{
|
||||
updateGameFileArray();
|
||||
sendBroadcast(CACHE_UPDATED);
|
||||
}
|
||||
changed = gameFileCache.update(gamePaths);
|
||||
}
|
||||
if (changed)
|
||||
{
|
||||
updateGameFileArray();
|
||||
sendBroadcast(CACHE_UPDATED);
|
||||
}
|
||||
|
||||
boolean additionalMetadataChanged = gameFileCache.updateAdditionalMetadata();
|
||||
if (additionalMetadataChanged)
|
||||
{
|
||||
updateGameFileArray();
|
||||
sendBroadcast(CACHE_UPDATED);
|
||||
}
|
||||
boolean additionalMetadataChanged = gameFileCache.updateAdditionalMetadata();
|
||||
if (additionalMetadataChanged)
|
||||
{
|
||||
updateGameFileArray();
|
||||
sendBroadcast(CACHE_UPDATED);
|
||||
}
|
||||
|
||||
if (changed || additionalMetadataChanged)
|
||||
{
|
||||
gameFileCache.save();
|
||||
}
|
||||
if (changed || additionalMetadataChanged)
|
||||
{
|
||||
gameFileCache.save();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ if(CMAKE_SYSTEM_NAME MATCHES "Windows")
|
|||
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
|
||||
add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
|
||||
add_definitions(-D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
|
||||
# The replacement for the old atomic shared_ptr functions was added in C++20, so we can't use it yet
|
||||
add_definitions(-D_SILENCE_CXX20_OLD_SHARED_PTR_ATOMIC_SUPPORT_DEPRECATION_WARNING)
|
||||
endif()
|
||||
|
||||
if (MSVC)
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "UICommon/GameFileCache.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
|
@ -202,7 +203,7 @@ bool GameFileCache::UpdateAdditionalMetadata(std::shared_ptr<GameFile>* game_fil
|
|||
if (custom_cover_changed)
|
||||
copy->CustomCoverCommit();
|
||||
|
||||
*game_file = std::move(copy);
|
||||
std::atomic_store(game_file, std::move(copy));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -64,6 +64,8 @@
|
|||
<PreprocessorDefinitions>_WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<!--Currently needed for some code in StringUtil used only on Android-->
|
||||
<PreprocessorDefinitions>_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<!--The replacement for the old atomic shared_ptr functions was added in C++20, so we can't use it yet-->
|
||||
<PreprocessorDefinitions>_SILENCE_CXX20_OLD_SHARED_PTR_ATOMIC_SUPPORT_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>USE_UPNP;USE_USBDK;__LIBUSB__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>SFML_STATIC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>USE_ANALYTICS=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
|
|
Loading…
Reference in New Issue