Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Commit

Permalink
fix thread safety in swaps
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Baltzell authored and baltzell committed May 16, 2023
1 parent e5bdaa5 commit e081e7b
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public class SwapManager {
"RTPC"
};

private final HashMap<Integer,HashMap<String,SwapTable>> swaps = new HashMap<>();
private volatile HashMap<Integer,HashMap<String,SwapTable>> swaps = new HashMap<>();

private final Map<String,String> banksToTables = new HashMap<>();
private final Map<String,List<String>> detsToBanks = new HashMap<>();
private final Map<String,String> detsToTables = new HashMap<>();
Expand Down Expand Up @@ -189,12 +190,15 @@ public int[] get(DataEvent event, String bankName, int row) {
* Initialize the swaps for a given run number.
* @param run
*/
private void add(int run) {
this.swaps.put(run,new HashMap<>());
for (String tableName : this.banksToTables.values()) {
IndexedTable prev = prevConman.getConstants(run, tableName);
IndexedTable curr = currConman.getConstants(run, tableName);
this.swaps.get(run).put(tableName,new SwapTable(prev,curr));
synchronized private void add(int run) {
if (!this.swaps.containsKey(run)) {
HashMap<String, SwapTable> x = new HashMap<>();
for (String tableName : this.banksToTables.values()) {
IndexedTable prev = prevConman.getConstants(run, tableName);
IndexedTable curr = currConman.getConstants(run, tableName);
x.put(tableName,new SwapTable(prev,curr));
}
this.swaps.put(run, x);
}
}

Expand Down

0 comments on commit e081e7b

Please sign in to comment.