HashSet is not thread safe, hopefully this fixes the CPU issue where it throws a exception on Add

This commit is contained in:
gdkchan 2018-04-04 18:17:37 -03:00
parent a20d6b34ab
commit e16ca561cb

View file

@ -107,6 +107,8 @@ namespace ChocolArm64
ATranslatedSub Subroutine = Context.GetSubroutine(); ATranslatedSub Subroutine = Context.GetSubroutine();
lock (SubBlocks)
{
if (SubBlocks.Contains(Position)) if (SubBlocks.Contains(Position))
{ {
SubBlocks.Remove(Position); SubBlocks.Remove(Position);
@ -117,16 +119,20 @@ namespace ChocolArm64
{ {
Subroutine.SetType(ATranslatedSubType.SubTier0); Subroutine.SetType(ATranslatedSubType.SubTier0);
} }
}
CachedSubs.AddOrUpdate(Position, Subroutine, (Key, OldVal) => Subroutine); CachedSubs.AddOrUpdate(Position, Subroutine, (Key, OldVal) => Subroutine);
AOpCode LastOp = Block.GetLastOp(); AOpCode LastOp = Block.GetLastOp();
lock (SubBlocks)
{
if (LastOp.Emitter != AInstEmit.Ret && if (LastOp.Emitter != AInstEmit.Ret &&
LastOp.Emitter != AInstEmit.Br) LastOp.Emitter != AInstEmit.Br)
{ {
SubBlocks.Add(LastOp.Position + 4); SubBlocks.Add(LastOp.Position + 4);
} }
}
return Subroutine; return Subroutine;
} }