Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Fix race condition in displayAlertMsg #12688

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@

import java.lang.ref.WeakReference;
import java.util.LinkedHashMap;
import java.util.concurrent.Semaphore;

/**
* Class which contains methods that interact
* with the native side of the Dolphin code.
*/
public final class NativeLibrary
{
private static final Object sAlertMessageLock = new Object();
private static final Semaphore sAlertMessageSemaphore = new Semaphore(0);
private static boolean sIsShowingAlertMessage = false;

private static WeakReference<EmulationActivity> sEmulationActivity = new WeakReference<>(null);
Expand Down Expand Up @@ -492,15 +493,12 @@ public static boolean displayAlertMsg(final String caption, final String text,
});

// Wait for the lock to notify that it is complete.
synchronized (sAlertMessageLock)
try
{
sAlertMessageSemaphore.acquire();
}
catch (InterruptedException ignored)
{
try
{
sAlertMessageLock.wait();
}
catch (Exception ignored)
{
}
}

if (yesNo)
Expand All @@ -520,10 +518,7 @@ public static boolean IsShowingAlertMessage()

public static void NotifyAlertMessageLock()
{
synchronized (sAlertMessageLock)
{
sAlertMessageLock.notify();
}
sAlertMessageSemaphore.release();
}

public static void setEmulationActivity(EmulationActivity emulationActivity)
Expand Down