Made locks more consistent across solution
This commit is contained in:
@@ -6,7 +6,7 @@ namespace SPTarkov.Common.Extensions;
|
||||
public static class ObjectExtensions
|
||||
{
|
||||
private static readonly Dictionary<Type, Dictionary<string, PropertyInfo>> _indexedProperties = new();
|
||||
private static readonly object _indexedPropertiesLockObject = new();
|
||||
private static readonly Lock _indexedPropertiesLockObject = new();
|
||||
|
||||
private static bool TryGetCachedProperty(Type type, string key, out PropertyInfo cachedProperty)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace SPTarkov.Common.Extensions;
|
||||
public static class StringExtensions
|
||||
{
|
||||
private static readonly Dictionary<string, Regex> RegexCache = new();
|
||||
private static readonly object RegexCacheLock = new();
|
||||
private static readonly Lock RegexCacheLock = new();
|
||||
|
||||
public static string RegexReplace(this string source, [StringSyntax(StringSyntaxAttribute.Regex)] string regexString, string newValue)
|
||||
{
|
||||
|
||||
@@ -7,11 +7,11 @@ public class ApplicationContext
|
||||
{
|
||||
protected const short MaxSavedValues = 10;
|
||||
protected readonly Dictionary<ContextVariableType, LinkedList<ContextVariable>> variables = new();
|
||||
private readonly Lock variablesLock = new();
|
||||
private readonly Lock _lockObject = new();
|
||||
|
||||
public ContextVariable? GetLatestValue(ContextVariableType type)
|
||||
{
|
||||
lock (variablesLock)
|
||||
lock (_lockObject)
|
||||
{
|
||||
if (variables.TryGetValue(type, out var savedValues))
|
||||
{
|
||||
@@ -24,7 +24,7 @@ public class ApplicationContext
|
||||
|
||||
public ICollection<ContextVariable> GetValues(ContextVariableType type)
|
||||
{
|
||||
lock (variablesLock)
|
||||
lock (_lockObject)
|
||||
{
|
||||
var values = new List<ContextVariable>();
|
||||
if (variables.TryGetValue(type, out var savedValues))
|
||||
@@ -38,7 +38,7 @@ public class ApplicationContext
|
||||
|
||||
public void AddValue(ContextVariableType type, object value)
|
||||
{
|
||||
lock (variablesLock)
|
||||
lock (_lockObject)
|
||||
{
|
||||
if (!variables.TryGetValue(type, out var savedValues))
|
||||
{
|
||||
@@ -57,7 +57,7 @@ public class ApplicationContext
|
||||
|
||||
public void ClearValues(ContextVariableType type)
|
||||
{
|
||||
lock (variablesLock)
|
||||
lock (_lockObject)
|
||||
{
|
||||
variables.Remove(type);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class SptWebSocketConnectionHandler(
|
||||
) : IWebSocketConnectionHandler
|
||||
{
|
||||
protected WsPing _defaultNotification = new();
|
||||
protected Lock _lockObject = new();
|
||||
protected readonly Lock _lockObject = new();
|
||||
protected Dictionary<string, WebSocket> _sockets = new();
|
||||
|
||||
public string GetHookUrl()
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace SPTarkov.Server.Core.Services;
|
||||
[Injectable(InjectionType.Singleton)]
|
||||
public class BotEquipmentModPoolService
|
||||
{
|
||||
private readonly Lock _lock = new();
|
||||
private readonly Lock _lockObject = new();
|
||||
protected bool _armorPoolGenerated;
|
||||
protected BotConfig _botConfig;
|
||||
protected ConfigServer _configServer;
|
||||
@@ -121,7 +121,7 @@ public class BotEquipmentModPoolService
|
||||
|
||||
private bool SetContainsTpl(HashSet<string> itemSet, string tpl)
|
||||
{
|
||||
lock (_lock)
|
||||
lock (_lockObject)
|
||||
{
|
||||
return itemSet.Contains(tpl);
|
||||
}
|
||||
@@ -129,7 +129,7 @@ public class BotEquipmentModPoolService
|
||||
|
||||
private bool AddTplToSet(HashSet<string> itemSet, string itemToAddTpl)
|
||||
{
|
||||
lock (_lock)
|
||||
lock (_lockObject)
|
||||
{
|
||||
return itemSet.Add(itemToAddTpl);
|
||||
}
|
||||
@@ -137,7 +137,7 @@ public class BotEquipmentModPoolService
|
||||
|
||||
private bool InitSetInDict(ConcurrentDictionary<string, HashSet<string>> dictionary, string slotName)
|
||||
{
|
||||
lock (_lock)
|
||||
lock (_lockObject)
|
||||
{
|
||||
return dictionary.TryAdd(slotName, []);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public class BotLootCacheService(
|
||||
ICloner _cloner
|
||||
)
|
||||
{
|
||||
protected object _lock = new();
|
||||
protected readonly Lock _lockObject = new();
|
||||
protected Dictionary<string, BotLootCache> _lootCache = new();
|
||||
|
||||
/// <summary>
|
||||
@@ -28,7 +28,7 @@ public class BotLootCacheService(
|
||||
/// </summary>
|
||||
public void ClearCache()
|
||||
{
|
||||
lock (_lock)
|
||||
lock (_lockObject)
|
||||
{
|
||||
_lootCache.Clear();
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public class BotLootCacheService(
|
||||
BotType botJsonTemplate,
|
||||
MinMax<double>? itemPriceMinMax = null)
|
||||
{
|
||||
lock (_lock)
|
||||
lock (_lockObject)
|
||||
{
|
||||
if (!BotRoleExistsInCache(botRole))
|
||||
{
|
||||
@@ -60,7 +60,7 @@ public class BotLootCacheService(
|
||||
|
||||
Dictionary<string, double> result = null;
|
||||
BotLootCache botRoleCache;
|
||||
lock (_lock)
|
||||
lock (_lockObject)
|
||||
{
|
||||
botRoleCache = _lootCache[botRole];
|
||||
}
|
||||
@@ -448,7 +448,7 @@ public class BotLootCacheService(
|
||||
}
|
||||
|
||||
BotLootCache cacheForRole;
|
||||
lock (_lock)
|
||||
lock (_lockObject)
|
||||
{
|
||||
cacheForRole = _lootCache[botRole];
|
||||
|
||||
@@ -544,7 +544,7 @@ public class BotLootCacheService(
|
||||
/// <returns>true if they exist</returns>
|
||||
protected bool BotRoleExistsInCache(string botRole)
|
||||
{
|
||||
lock (_lock)
|
||||
lock (_lockObject)
|
||||
{
|
||||
return _lootCache.ContainsKey(botRole);
|
||||
}
|
||||
@@ -556,7 +556,7 @@ public class BotLootCacheService(
|
||||
/// <param name="botRole">Bot role to hydrate</param>
|
||||
protected void InitCacheForBotRole(string botRole)
|
||||
{
|
||||
lock (_lock)
|
||||
lock (_lockObject)
|
||||
{
|
||||
_lootCache.Add(
|
||||
botRole,
|
||||
|
||||
@@ -21,7 +21,7 @@ public class BotNameService(
|
||||
)
|
||||
{
|
||||
protected BotConfig _botConfig = _configServer.GetConfig<BotConfig>();
|
||||
protected object _lock = new();
|
||||
protected readonly Lock _lockObject = new();
|
||||
protected HashSet<string> _usedNameCache = new();
|
||||
|
||||
/// <summary>
|
||||
@@ -113,7 +113,7 @@ public class BotNameService(
|
||||
|
||||
private bool AddNameToCache(string name)
|
||||
{
|
||||
lock (_lock)
|
||||
lock (_lockObject)
|
||||
{
|
||||
return _usedNameCache.Add(name);
|
||||
}
|
||||
@@ -121,7 +121,7 @@ public class BotNameService(
|
||||
|
||||
protected bool CacheContainsName(string name)
|
||||
{
|
||||
lock (_lock)
|
||||
lock (_lockObject)
|
||||
{
|
||||
return _usedNameCache.Contains(name);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class ImporterUtil
|
||||
)
|
||||
{
|
||||
var tasks = new List<Task>();
|
||||
var dictionaryLock = new object();
|
||||
var dictionaryLock = new Lock();
|
||||
var result = Activator.CreateInstance(loadedType);
|
||||
|
||||
// get all filepaths
|
||||
@@ -93,7 +93,7 @@ public class ImporterUtil
|
||||
Action<string>? onReadCallback,
|
||||
Action<string, object>? onObjectDeserialized,
|
||||
object result,
|
||||
object dictionaryLock
|
||||
Lock dictionaryLock
|
||||
)
|
||||
{
|
||||
try
|
||||
@@ -135,7 +135,7 @@ public class ImporterUtil
|
||||
string directory,
|
||||
Type loadedType,
|
||||
object result,
|
||||
object dictionaryLock
|
||||
Lock dictionaryLock
|
||||
)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -20,14 +20,14 @@ public class RagfairOfferHolder(
|
||||
{
|
||||
protected int _maxOffersPerTemplate = configServer.GetConfig<RagfairConfig>().Dynamic.OfferItemCount.Max;
|
||||
protected Dictionary<string, RagfairOffer> _offersById = new();
|
||||
protected object _offersByIdLock = new();
|
||||
protected readonly Lock _offersByIdLock = new();
|
||||
protected Dictionary<string, HashSet<string>> _offersByTemplate = new(); // key = tplId, value = list of offerIds
|
||||
protected object _offersByTemplateLock = new();
|
||||
protected readonly Lock _offersByTemplateLock = new();
|
||||
protected Dictionary<string, HashSet<string>> _offersByTrader = new(); // key = traderId, value = list of offerIds
|
||||
protected object _offersByTraderLock = new();
|
||||
protected readonly Lock _offersByTraderLock = new();
|
||||
|
||||
protected HashSet<string> _expiredOfferIds = [];
|
||||
protected object _expiredOfferIdsLock = new();
|
||||
protected readonly Lock _expiredOfferIdsLock = new();
|
||||
|
||||
/// <summary>
|
||||
/// Get a ragfair offer by its id
|
||||
|
||||
Reference in New Issue
Block a user