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

View File

@@ -26,7 +26,6 @@ import com.shatteredpixel.shatteredpixeldungeon.Statistics;
import com.shatteredpixel.shatteredpixeldungeon.actors.blobs.Blob;
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
import com.shatteredpixel.shatteredpixeldungeon.actors.mobs.Mob;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.watabou.utils.Bundlable;
import com.watabou.utils.Bundle;
import com.watabou.utils.SparseArray;
@@ -283,11 +282,9 @@ public abstract class Actor implements Bundlable {
current = null;
interrupted = false;
}
synchronized (GameScene.class){
//signals to the gamescene that actor processing is finished for now
GameScene.class.notify();
}
//signals to the gamescene that actor processing is finished for now
Thread.currentThread().notify();
try {
Thread.currentThread().wait();

View File

@@ -555,21 +555,17 @@ public class GameScene extends PixelScene {
}
public boolean waitForActorThread(int msToWait ){
synchronized (GameScene.class) {
if (actorThread == null || !actorThread.isAlive()) {
return true;
}
synchronized (actorThread) {
actorThread.interrupt();
}
if (actorThread == null || !actorThread.isAlive()) {
return true;
}
synchronized (actorThread) {
actorThread.interrupt();
try {
GameScene.class.wait(msToWait);
actorThread.wait(msToWait);
} catch (InterruptedException e) {
ShatteredPixelDungeon.reportException(e);
}
synchronized (actorThread) {
return !Actor.processing();
}
return !Actor.processing();
}
}