Merge pull request #12688 from JosJuice/android-alert-synchronize
Android: Fix race condition in displayAlertMsg
This commit is contained in:
commit
b623a36005
|
@ -21,6 +21,7 @@ import org.dolphinemu.dolphinemu.utils.Log;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.concurrent.Semaphore;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class which contains methods that interact
|
* Class which contains methods that interact
|
||||||
|
@ -28,7 +29,7 @@ import java.util.LinkedHashMap;
|
||||||
*/
|
*/
|
||||||
public final class NativeLibrary
|
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 boolean sIsShowingAlertMessage = false;
|
||||||
|
|
||||||
private static WeakReference<EmulationActivity> sEmulationActivity = new WeakReference<>(null);
|
private static WeakReference<EmulationActivity> sEmulationActivity = new WeakReference<>(null);
|
||||||
|
@ -491,15 +492,12 @@ public final class NativeLibrary
|
||||||
});
|
});
|
||||||
|
|
||||||
// Wait for the lock to notify that it is complete.
|
// 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)
|
if (yesNo)
|
||||||
|
@ -519,10 +517,7 @@ public final class NativeLibrary
|
||||||
|
|
||||||
public static void NotifyAlertMessageLock()
|
public static void NotifyAlertMessageLock()
|
||||||
{
|
{
|
||||||
synchronized (sAlertMessageLock)
|
sAlertMessageSemaphore.release();
|
||||||
{
|
|
||||||
sAlertMessageLock.notify();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setEmulationActivity(EmulationActivity emulationActivity)
|
public static void setEmulationActivity(EmulationActivity emulationActivity)
|
||||||
|
|
Loading…
Reference in New Issue