From e16ca561cb32b8d3a12689290dd75e357d28e857 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Wed, 4 Apr 2018 18:17:37 -0300 Subject: [PATCH] HashSet is not thread safe, hopefully this fixes the CPU issue where it throws a exception on Add --- ChocolArm64/ATranslator.cs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/ChocolArm64/ATranslator.cs b/ChocolArm64/ATranslator.cs index 02c18efd..f1bc2cff 100644 --- a/ChocolArm64/ATranslator.cs +++ b/ChocolArm64/ATranslator.cs @@ -107,25 +107,31 @@ namespace ChocolArm64 ATranslatedSub Subroutine = Context.GetSubroutine(); - if (SubBlocks.Contains(Position)) + lock (SubBlocks) { - SubBlocks.Remove(Position); + if (SubBlocks.Contains(Position)) + { + SubBlocks.Remove(Position); - Subroutine.SetType(ATranslatedSubType.SubBlock); - } - else - { - Subroutine.SetType(ATranslatedSubType.SubTier0); + Subroutine.SetType(ATranslatedSubType.SubBlock); + } + else + { + Subroutine.SetType(ATranslatedSubType.SubTier0); + } } CachedSubs.AddOrUpdate(Position, Subroutine, (Key, OldVal) => Subroutine); AOpCode LastOp = Block.GetLastOp(); - if (LastOp.Emitter != AInstEmit.Ret && - LastOp.Emitter != AInstEmit.Br) + lock (SubBlocks) { - SubBlocks.Add(LastOp.Position + 4); + if (LastOp.Emitter != AInstEmit.Ret && + LastOp.Emitter != AInstEmit.Br) + { + SubBlocks.Add(LastOp.Position + 4); + } } return Subroutine;