Skip to content

Commit

Permalink
Ensure ReentrantLock is unlocked after being locked, and on same th…
Browse files Browse the repository at this point in the history
…read (#2759)

Cherry-pick 30f3e41
  • Loading branch information
TimSylvester committed Oct 15, 2024
1 parent f617a5a commit b2d8af1
Showing 1 changed file with 6 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,33 +195,16 @@ public static boolean isExternalStorageReadable() {
@UiThread
public static void initializeFileDirsPaths(Context context) {
ThreadUtils.checkThread(TAG);
lockPathLoaders();
if (resourcesCachePath == null || internalCachePath == null) {
new FileDirsPathsTask().execute(context);
}
new FileDirsPathsTask().execute(context);
}

private static class FileDirsPathsTask extends AsyncTask<Context, Void, String[]> {

@Override
protected void onCancelled() {
unlockPathLoaders();
}

@NonNull
@Override
protected String[] doInBackground(Context... contexts) {
return new String[] {
getCachePath(contexts[0]),
contexts[0].getCacheDir().getAbsolutePath()
};
}
private static class FileDirsPathsTask extends AsyncTask<Context, Void, Void> {

@Override
protected void onPostExecute(String[] paths) {
resourcesCachePath = paths[0];
internalCachePath = paths[1];
unlockPathLoaders();
protected Void doInBackground(Context... contexts) {
getResourcesCachePath(contexts[0]);
getInternalCachePath(contexts[0]);
return null;
}
}

Expand Down Expand Up @@ -358,16 +341,6 @@ private static boolean isPathWritable(String path) {
return new File(path).canWrite();
}

private static void lockPathLoaders() {
internalCachePathLoaderLock.lock();
resourcesCachePathLoaderLock.lock();
}

private static void unlockPathLoaders() {
resourcesCachePathLoaderLock.unlock();
internalCachePathLoaderLock.unlock();
}

@Keep
private long nativePtr;

Expand Down

0 comments on commit b2d8af1

Please sign in to comment.