Fix bug where multiple threads modify same variable at the same time. Perform some refactoring
This commit is contained in:
@@ -1,28 +1,23 @@
|
||||
using Raytheon.Instruments.PowerSupply;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProgramLib
|
||||
{
|
||||
{
|
||||
/// <summary>
|
||||
/// Stores voltage and current reading
|
||||
/// </summary>
|
||||
internal class PowerSupplyData
|
||||
{
|
||||
public double _voltage;
|
||||
public double _current;
|
||||
public PowerSupplyModuleInfo _powerSupplyModuleInfo;
|
||||
public bool _initialized;
|
||||
public double Voltage { get; set; }
|
||||
public double Current { get; set; }
|
||||
public PowerSupplyModuleInfo PowerSupplyModuleInfo { get; set; }
|
||||
public bool Initialized { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Set data to unitialized
|
||||
/// </summary>
|
||||
public void Reset()
|
||||
{
|
||||
_initialized = false;
|
||||
Initialized = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user