From fb265b610de08df5509e56beeb3dbff68f7d4396 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 24 Aug 2021 15:07:15 +0200 Subject: [PATCH] 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. --- .../services/GameFileCacheService.java | 33 ++++++++++--------- Source/CMakeLists.txt | 2 ++ Source/Core/UICommon/GameFileCache.cpp | 3 +- Source/VSProps/Base.props | 2 ++ 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheService.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheService.java index 1a9284a9c4..a8ecc367c9 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheService.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheService.java @@ -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(); } } diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 3f0afcaf34..8ac7f4fe26 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -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) diff --git a/Source/Core/UICommon/GameFileCache.cpp b/Source/Core/UICommon/GameFileCache.cpp index a0bf0caf42..30bbca924b 100644 --- a/Source/Core/UICommon/GameFileCache.cpp +++ b/Source/Core/UICommon/GameFileCache.cpp @@ -4,6 +4,7 @@ #include "UICommon/GameFileCache.h" #include +#include #include #include #include @@ -202,7 +203,7 @@ bool GameFileCache::UpdateAdditionalMetadata(std::shared_ptr* game_fil if (custom_cover_changed) copy->CustomCoverCommit(); - *game_file = std::move(copy); + std::atomic_store(game_file, std::move(copy)); return true; } diff --git a/Source/VSProps/Base.props b/Source/VSProps/Base.props index 79489143a7..e656544188 100644 --- a/Source/VSProps/Base.props +++ b/Source/VSProps/Base.props @@ -64,6 +64,8 @@ _WINSOCK_DEPRECATED_NO_WARNINGS;%(PreprocessorDefinitions) _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;%(PreprocessorDefinitions) + + _SILENCE_CXX20_OLD_SHARED_PTR_ATOMIC_SUPPORT_DEPRECATION_WARNING;%(PreprocessorDefinitions) USE_UPNP;USE_USBDK;__LIBUSB__;%(PreprocessorDefinitions) SFML_STATIC;%(PreprocessorDefinitions) USE_ANALYTICS=1;%(PreprocessorDefinitions)