- Added pre-touch to the ContentPath.FullPath to make them thread-safe.
This commit is contained in:
@@ -99,12 +99,13 @@ namespace Barotrauma
|
|||||||
public static ContentPath FromRaw(ContentPackage? contentPackage, string? rawValue)
|
public static ContentPath FromRaw(ContentPackage? contentPackage, string? rawValue)
|
||||||
{
|
{
|
||||||
var newRaw = new ContentPath(contentPackage, 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)
|
prevCreatedRaw.RawValue == rawValue)
|
||||||
{
|
{
|
||||||
newRaw.cachedValue = prevCreatedRaw.Value;
|
newRaw.cachedValue = prevCreatedRaw.Value;
|
||||||
}
|
}
|
||||||
prevCreatedRaw = newRaw;
|
prevCreatedRaw = newRaw;*/
|
||||||
return newRaw;
|
return newRaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Collections.Concurrent;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Barotrauma.Extensions;
|
using Barotrauma.Extensions;
|
||||||
using Barotrauma.LuaCs.Data;
|
using Barotrauma.LuaCs.Data;
|
||||||
@@ -138,7 +139,9 @@ public sealed class PackageManagementService : IPackageManagementService
|
|||||||
{
|
{
|
||||||
result.WithReasons(pkgConfig.Config.Reasons);
|
result.WithReasons(pkgConfig.Config.Reasons);
|
||||||
if (pkgConfig.Config.IsSuccess)
|
if (pkgConfig.Config.IsSuccess)
|
||||||
|
{
|
||||||
result.WithReasons(UnsafeAddPackageInternal(pkgConfig.Source, pkgConfig.Config.Value).Reasons);
|
result.WithReasons(UnsafeAddPackageInternal(pkgConfig.Source, pkgConfig.Config.Value).Reasons);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -152,6 +155,32 @@ public sealed class PackageManagementService : IPackageManagementService
|
|||||||
return FluentResults.Result.Ok();
|
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;
|
_loadedPackages[package] = config;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user