Skip to content

Commit

Permalink
Use separate object for locking between threads (#3049)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluemarvin committed Mar 25, 2020
1 parent d4af5a0 commit 7c64ae7
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java
Expand Up @@ -712,21 +712,23 @@ public boolean dispatchKeyEvent(KeyEvent event) {
return super.dispatchKeyEvent(event);
}

final Object mWaitLock = new Object();

final Runnable mExitImmersive = new Runnable() {
@Override
public void run() {
exitImmersiveNative();
synchronized(this) {
this.notifyAll();
synchronized(mWaitLock) {
mWaitLock.notifyAll();
}
}
};

private void exitImmersiveSync() {
synchronized (mExitImmersive) {
synchronized (mWaitLock) {
queueRunnable(mExitImmersive);
try {
mExitImmersive.wait();
mWaitLock.wait();
} catch (InterruptedException e) {
Log.e(LOGTAG, "Waiting for exit immersive onPause interrupted");
}
Expand Down Expand Up @@ -916,16 +918,18 @@ void registerExternalContext(long aContext) {
GeckoVRManager.setExternalContext(aContext);
}

final Object mCompositorLock = new Object();

class PauseCompositorRunnable implements Runnable {
public boolean done;
@Override
public void run() {
synchronized (VRBrowserActivity.this) {
synchronized (mCompositorLock) {
Log.d(LOGTAG, "About to pause Compositor");
mWindows.pauseCompositor();
Log.d(LOGTAG, "Compositor Paused");
done = true;
VRBrowserActivity.this.notify();
mCompositorLock.notify();
}
}
}
Expand All @@ -942,11 +946,11 @@ void pauseGeckoViewCompositor() {
GleanMetricsService.startImmersive();
PauseCompositorRunnable runnable = new PauseCompositorRunnable();

synchronized (this) {
synchronized (mCompositorLock) {
runOnUiThread(runnable);
while (!runnable.done) {
try {
this.wait();
mCompositorLock.wait();
} catch (InterruptedException e) {
Log.e(LOGTAG, "Waiting for compositor pause interrupted");
}
Expand Down

0 comments on commit 7c64ae7

Please sign in to comment.