mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
fix: use channel threadlocal instead of a ThreadStatic
This commit is contained in:
parent
b18b8b40e5
commit
8cced4c1d7
2 changed files with 22 additions and 7 deletions
|
|
@ -2,6 +2,7 @@ using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
using Dalamud.Plugin.Internal.Types;
|
using Dalamud.Plugin.Internal.Types;
|
||||||
using Dalamud.Plugin.Ipc.Exceptions;
|
using Dalamud.Plugin.Ipc.Exceptions;
|
||||||
|
|
@ -17,6 +18,8 @@ namespace Dalamud.Plugin.Ipc.Internal;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class CallGateChannel
|
internal class CallGateChannel
|
||||||
{
|
{
|
||||||
|
private readonly ThreadLocal<IpcContext> ipcExecutionContext = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The actual storage.
|
/// The actual storage.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -146,6 +149,21 @@ internal class CallGateChannel
|
||||||
return (TRet)result;
|
return (TRet)result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void SetInvocationContext(IpcContext ipcContext)
|
||||||
|
{
|
||||||
|
this.ipcExecutionContext.Value = ipcContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal IpcContext? GetInvocationContext()
|
||||||
|
{
|
||||||
|
return this.ipcExecutionContext.IsValueCreated ? this.ipcExecutionContext.Value : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void ClearInvocationContext()
|
||||||
|
{
|
||||||
|
this.ipcExecutionContext.Value = null;
|
||||||
|
}
|
||||||
|
|
||||||
private void CheckAndConvertArgs(object?[]? args, MethodInfo methodInfo)
|
private void CheckAndConvertArgs(object?[]? args, MethodInfo methodInfo)
|
||||||
{
|
{
|
||||||
var paramTypes = methodInfo.GetParameters()
|
var paramTypes = methodInfo.GetParameters()
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,6 @@ namespace Dalamud.Plugin.Ipc.Internal;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal abstract class CallGatePubSubBase
|
internal abstract class CallGatePubSubBase
|
||||||
{
|
{
|
||||||
[ThreadStatic]
|
|
||||||
private static IpcContext? ipcExecutionContext;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="CallGatePubSubBase"/> class.
|
/// Initializes a new instance of the <see cref="CallGatePubSubBase"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -77,7 +74,7 @@ internal abstract class CallGatePubSubBase
|
||||||
/// <returns>Returns a potential IPC context.</returns>
|
/// <returns>Returns a potential IPC context.</returns>
|
||||||
public IpcContext? GetContext()
|
public IpcContext? GetContext()
|
||||||
{
|
{
|
||||||
return ipcExecutionContext;
|
return this.Channel.GetInvocationContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -172,11 +169,11 @@ internal abstract class CallGatePubSubBase
|
||||||
|
|
||||||
private IDisposable BuildContext()
|
private IDisposable BuildContext()
|
||||||
{
|
{
|
||||||
ipcExecutionContext = new IpcContext
|
this.Channel.SetInvocationContext(new IpcContext
|
||||||
{
|
{
|
||||||
SourcePlugin = this.OwningPlugin != null ? new ExposedPlugin(this.OwningPlugin) : null,
|
SourcePlugin = this.OwningPlugin != null ? new ExposedPlugin(this.OwningPlugin) : null,
|
||||||
};
|
});
|
||||||
|
|
||||||
return Disposable.Create(() => { ipcExecutionContext = null; });
|
return Disposable.Create(() => { this.Channel.ClearInvocationContext(); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue