Fix bug where multiple threads modify same variable at the same time. Perform some refactoring

This commit is contained in:
Duc
2025-03-13 14:40:58 -07:00
parent ffa9905494
commit 492cbb9cd9
10 changed files with 84 additions and 102 deletions

View File

@@ -1,9 +1,5 @@
using Raytheon.Instruments.PowerSupply;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
using Raytheon.Instruments.PowerSupply;
namespace ProgramLib
{
@@ -27,20 +23,17 @@ namespace ProgramLib
{
// create a mutex for each module
syncObjDict[moduleName] = new object();
_powerSupplyDataDict[moduleName] = new PowerSupplyData();
}
}
lock (syncObjDict[moduleName])
{
if (!_powerSupplyDataDict.ContainsKey(moduleName))
{
_powerSupplyDataDict[moduleName] = new PowerSupplyData();
}
_powerSupplyDataDict[moduleName]._voltage = voltage;
_powerSupplyDataDict[moduleName]._current = current;
_powerSupplyDataDict[moduleName]._initialized = true;
_powerSupplyDataDict[moduleName]._powerSupplyModuleInfo = powerSupplyModuleInfo;
_powerSupplyDataDict[moduleName].Voltage = voltage;
_powerSupplyDataDict[moduleName].Current = current;
_powerSupplyDataDict[moduleName].Initialized = true;
_powerSupplyDataDict[moduleName].PowerSupplyModuleInfo = powerSupplyModuleInfo;
}
}
@@ -55,6 +48,8 @@ namespace ProgramLib
{
// create a mutex for each module
syncObjDict[moduleName] = new object();
_powerSupplyDataDict[moduleName] = new PowerSupplyData();
}
}