- Added pre-touch to the ContentPath.FullPath to make them thread-safe.

This commit is contained in:
MapleWheels
2026-02-09 15:52:37 -05:00
parent 70e98467e8
commit 511f98ec18
2 changed files with 33 additions and 3 deletions

View File

@@ -99,12 +99,13 @@ namespace Barotrauma
public static ContentPath FromRaw(ContentPackage? contentPackage, string? rawValue)
{
var newRaw = new ContentPath(contentPackage, rawValue);
if (prevCreatedRaw is not null && prevCreatedRaw.ContentPackage == contentPackage &&
// Removed as this almost never happens but makes the constructor not thread-safe.
/*if (prevCreatedRaw is not null && prevCreatedRaw.ContentPackage == contentPackage &&
prevCreatedRaw.RawValue == rawValue)
{
newRaw.cachedValue = prevCreatedRaw.Value;
}
prevCreatedRaw = newRaw;
prevCreatedRaw = newRaw;*/
return newRaw;
}
@@ -158,4 +159,4 @@ namespace Barotrauma
public override string? ToString() => Value;
}
}
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Barotrauma.Extensions;
using Barotrauma.LuaCs.Data;
@@ -138,7 +139,9 @@ public sealed class PackageManagementService : IPackageManagementService
{
result.WithReasons(pkgConfig.Config.Reasons);
if (pkgConfig.Config.IsSuccess)
{
result.WithReasons(UnsafeAddPackageInternal(pkgConfig.Source, pkgConfig.Config.Value).Reasons);
}
}
return result;
@@ -152,6 +155,32 @@ public sealed class PackageManagementService : IPackageManagementService
return FluentResults.Result.Ok();
}
// We need to touch ContentPath.Fullpath once in a single-threaded context to make it thread-safe.
foreach (var info in config.Assemblies)
{
TouchMeFullPaths(info);
}
foreach (var info in config.Configs)
{
TouchMeFullPaths(info);
}
foreach (var info in config.LuaScripts)
{
TouchMeFullPaths(info);
}
// We need to touch ContentPath.Fullpath once in a single-threaded context to make it thread-safe.
[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.PreserveSig)]
void TouchMeFullPaths(IBaseResourceInfo info)
{
foreach (var contentPath in info.FilePaths)
{
var s = contentPath.FullPath;
}
}
_loadedPackages[package] = config;
try
{