Android: Don't hold gameFileCache lock while finding games

FindAllGamePaths may take a little while, and holding the
gameFileCache lock isn't actually necessary until it's time to
put the results returned by FindAllGamePaths into gameFileCache.

The downside of this change is that we have to do an extra
round of JNI in between FindAllGamePaths and Update,
but I don't think that's much of a problem.
This commit is contained in:
JosJuice 2021-08-24 14:36:08 +02:00
parent 757985d4c2
commit bba33c7ced
3 changed files with 31 additions and 12 deletions

View File

@ -96,12 +96,7 @@ public class GameFileCache
return pathSet;
}
/**
* Scans through the file system and updates the cache to match.
*
* @return true if the cache was modified
*/
public boolean update()
public static String[] getAllGamePaths()
{
boolean recursiveScan = BooleanSetting.MAIN_RECURSIVE_ISO_PATHS.getBooleanGlobal();
@ -109,17 +104,33 @@ public class GameFileCache
String[] folderPaths = folderPathsSet.toArray(new String[0]);
return update(folderPaths, recursiveScan);
return getAllGamePaths(folderPaths, recursiveScan);
}
public static native String[] getAllGamePaths(String[] folderPaths, boolean recursiveScan);
public native int getSize();
public native GameFile[] getAllGames();
public native GameFile addOrGet(String gamePath);
public native boolean update(String[] folderPaths, boolean recursiveScan);
/**
* Sets the list of games to cache.
*
* Games which are in the passed-in list but not in the cache are scanned and added to the cache,
* and games which are in the cache but not in the passed-in list are removed from the cache.
*
* @return true if the cache was modified
*/
public native boolean update(String[] gamePaths);
/**
* For each game that already is in the cache, scans the folder that contains the game
* for additional metadata files (PNG/XML).
*
* @return true if the cache was modified
*/
public native boolean updateAdditionalMetadata();
public native boolean load();

View File

@ -192,9 +192,11 @@ public final class GameFileCacheService extends IntentService
{
if (gameFileCache != null)
{
String[] gamePaths = GameFileCache.getAllGamePaths();
synchronized (gameFileCache)
{
boolean changed = gameFileCache.update();
boolean changed = gameFileCache.update(gamePaths);
if (changed)
{
updateGameFileArray();

View File

@ -38,6 +38,13 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_finali
delete GetPointer(env, obj);
}
JNIEXPORT jobjectArray JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_getAllGamePaths(
JNIEnv* env, jclass, jobjectArray folder_paths, jboolean recursive_scan)
{
return VectorToJStringArray(
env, UICommon::FindAllGamePaths(JStringArrayToVector(env, folder_paths), recursive_scan));
}
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_getSize(JNIEnv* env,
jobject obj)
{
@ -66,10 +73,9 @@ JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_add
}
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_model_GameFileCache_update(
JNIEnv* env, jobject obj, jobjectArray folder_paths, jboolean recursive_scan)
JNIEnv* env, jobject obj, jobjectArray game_paths)
{
return GetPointer(env, obj)->Update(
UICommon::FindAllGamePaths(JStringArrayToVector(env, folder_paths), recursive_scan));
return GetPointer(env, obj)->Update(JStringArrayToVector(env, game_paths));
}
JNIEXPORT jboolean JNICALL