v0.9.2b: simplified thread coordination to reduce deadlock risk

This commit is contained in:
Evan Debenham
2021-03-19 20:57:05 -04:00
parent c91b90a514
commit 3e7a48d59b
2 changed files with 10 additions and 17 deletions
@@ -26,7 +26,6 @@ import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob; import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff; import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob; import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.watabou.utils.Bundlable; import com.watabou.utils.Bundlable;
import com.watabou.utils.Bundle; import com.watabou.utils.Bundle;
import com.watabou.utils.SparseArray; import com.watabou.utils.SparseArray;
@@ -283,11 +282,9 @@ public abstract class Actor implements Bundlable {
current = null; current = null;
interrupted = false; interrupted = false;
} }
synchronized (GameScene.class){ //signals to the gamescene that actor processing is finished for now
//signals to the gamescene that actor processing is finished for now Thread.currentThread().notify();
GameScene.class.notify();
}
try { try {
Thread.currentThread().wait(); Thread.currentThread().wait();
@@ -555,21 +555,17 @@ public class GameScene extends PixelScene {
} }
public boolean waitForActorThread(int msToWait ){ public boolean waitForActorThread(int msToWait ){
synchronized (GameScene.class) { if (actorThread == null || !actorThread.isAlive()) {
if (actorThread == null || !actorThread.isAlive()) { return true;
return true; }
} synchronized (actorThread) {
synchronized (actorThread) { actorThread.interrupt();
actorThread.interrupt();
}
try { try {
GameScene.class.wait(msToWait); actorThread.wait(msToWait);
} catch (InterruptedException e) { } catch (InterruptedException e) {
ShatteredPixelDungeon.reportException(e); ShatteredPixelDungeon.reportException(e);
} }
synchronized (actorThread) { return !Actor.processing();
return !Actor.processing();
}
} }
} }