Skip to content

Commit

Permalink
Merge pull request #639 from eesast/dev
Browse files Browse the repository at this point in the history
fix locking
  • Loading branch information
DragonAura authored May 26, 2023
2 parents da0d579 + 4e8afd1 commit ddf0bf4
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions logic/Gaming/ActionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ public bool Fix(Student player)// 自动检查有无发电机可修
gameMap.AddNumOfRepairedGenerators();
if (generatorForFix.DegreeOfRepair == GameData.degreeOfFixedGenerator)
{
lock (player.ActionLock)
{
if (stateNum == player.StateNum)
player.SetPlayerState(RunningStateType.Null);
}
player.ResetPlayerState(stateNum);
return false;
}
return true;
Expand Down Expand Up @@ -211,11 +207,7 @@ public bool Treat(Student player, Student? playerTreated = null)
long stateNum = player.SetPlayerState(RunningStateType.Waiting, PlayerStateType.Treating);
if (stateNum == -1)
{
lock (playerTreated.ActionLock)
{
if (playerTreated.StateNum == stateNumTreated)
player.SetPlayerStateNaturally();
}
playerTreated.ResetPlayerState(stateNumTreated);
return false;
}

Expand All @@ -227,23 +219,15 @@ public bool Treat(Student player, Student? playerTreated = null)
if (!player.StartThread(stateNum, RunningStateType.RunningActively))
{
player.ThreadNum.Release();
lock (playerTreated.ActionLock)
{
if (playerTreated.StateNum == stateNumTreated)
playerTreated.SetPlayerStateNaturally();
}
playerTreated.ResetPlayerState(stateNumTreated);
return;
}
playerTreated.ThreadNum.WaitOne();
if (!playerTreated.StartThread(stateNum, RunningStateType.RunningActively))
{
playerTreated.ThreadNum.Release();
lock (player.ActionLock)
{
if (player.StateNum == stateNum)
player.SetPlayerStateNaturally();
}
player.ResetPlayerState(stateNum);
player.ThreadNum.Release();
return;
}
Expand Down

0 comments on commit ddf0bf4

Please sign in to comment.