From 49fc029c516f6312c014fd8ccda4d3db63af0601 Mon Sep 17 00:00:00 2001 From: Mazo Date: Sat, 16 May 2020 17:18:31 +0100 Subject: [PATCH] Replace mutable HashMap with concurrent TrieMap to hopefully improve thread safety for inventory item operations (#441) --- .../scala/net/psforever/objects/inventory/GridInventory.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/src/main/scala/net/psforever/objects/inventory/GridInventory.scala b/common/src/main/scala/net/psforever/objects/inventory/GridInventory.scala index 46fb430a..2038d5aa 100644 --- a/common/src/main/scala/net/psforever/objects/inventory/GridInventory.scala +++ b/common/src/main/scala/net/psforever/objects/inventory/GridInventory.scala @@ -8,6 +8,7 @@ import net.psforever.types.PlanetSideGUID import scala.annotation.tailrec import scala.collection.mutable +import scala.collection.concurrent import scala.util.{Failure, Success, Try} /** @@ -32,7 +33,7 @@ class GridInventory extends Container { private var offset : Int = 0 //the effective index of the first cell in the inventory where offset >= 0 /* key - an integer (not especially meaningful beyond being unique); value - the card that represents the stowed item */ - private val items : mutable.HashMap[Int, InventoryItem] = mutable.HashMap[Int, InventoryItem]() + private val items : concurrent.TrieMap[Int, InventoryItem] = concurrent.TrieMap[Int, InventoryItem]() private val entryIndex : AtomicInteger = new AtomicInteger(0) private var grid : Array[Int] = Array.fill[Int](1)(-1)