[android] Fixes timertask race condition
* Revert "[android] Fix for race condition with timer."
This reverts commit
* [android] Revets previous attempt at fix, this properly fixes race condition on timertask.
@@ -67,7 +67,7 @@ class MainView extends GLSurfaceView {
boolean onPaused;
Runnable pollMe;
TimerTask pendingTimer;
- Semaphore handleResultSemaphore;
+ Semaphore pendingTimerSemaphore;
boolean renderPending = false;
@@ -78,11 +78,11 @@ class MainView extends GLSurfaceView {
super(context);
isPollImminent = false;
+ pendingTimerSemaphore = new Semaphore(1,true);
final MainView me = this;
pollMe = new Runnable() {
@Override public void run() { me.onPollHX(); }
};
- handleResultSemaphore = new Semaphore(1);
translucent = inTranslucent;
getHolder().setFormat(
@@ -254,14 +254,14 @@ class MainView extends GLSurfaceView {
// Haxe thread
public void HandleResult(int inCode)
{
- if(handleResultSemaphore.tryAcquire()) {
if (inCode==resTerminate)
{
- Log.v("VIEW","Terminate Request.");
+ //Log.v("VIEW","Terminate Request.");
mActivity.onNMEFinish();
return;
}
+
double wake = NME.getNextWake();
int delayMs = (int)(wake * 1000);
@@ -272,6 +272,8 @@ class MainView extends GLSurfaceView {
queuePoll();
else
{
+ pendingTimerSemaphore.acquireUninterruptibly();
+
if (pendingTimer!=null)
pendingTimer.cancel();
@@ -283,8 +285,8 @@ class MainView extends GLSurfaceView {
};
mTimer.schedule(pendingTimer,delayMs);
- }
- handleResultSemaphore.release();
+
+ pendingTimerSemaphore.release();
}
}
@@ -357,9 +359,11 @@ class MainView extends GLSurfaceView {
super.onPause(); //Pause GL Thread
+ pendingTimerSemaphore.acquireUninterruptibly();
if (pendingTimer != null) { //Pause the Haxe Thread
pendingTimer.cancel();
}
+ pendingTimerSemaphore.release();
}
@Override
