change: 代码整理、定向切换时校验当前状态.

This commit is contained in:
2024-12-31 09:21:03 +08:00
parent 682266b591
commit 5fed1bbf19
9 changed files with 46 additions and 15 deletions

View File

@@ -74,11 +74,15 @@ public abstract class AbstractStateManager<S> implements StateManager<S> {
@Override
public boolean switchTo(S state) {
int i = indexOf(state);
if (i == -1) {
if (i == -1 || i == index) {
return false;
}
try {
writeLock.lock();
// 重新检查
if (i == index) {
return false;
}
index = i;
} finally {
writeLock.unlock();