mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +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.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
|
||||
using Dalamud.Plugin.Internal.Types;
|
||||
using Dalamud.Plugin.Ipc.Exceptions;
|
||||
|
|
@ -17,6 +18,8 @@ namespace Dalamud.Plugin.Ipc.Internal;
|
|||
/// </summary>
|
||||
internal class CallGateChannel
|
||||
{
|
||||
private readonly ThreadLocal<IpcContext> ipcExecutionContext = new();
|
||||
|
||||
/// <summary>
|
||||
/// The actual storage.
|
||||
/// </summary>
|
||||
|
|
@ -146,6 +149,21 @@ internal class CallGateChannel
|
|||
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)
|
||||
{
|
||||
var paramTypes = methodInfo.GetParameters()
|
||||
|
|
|
|||
|
|
@ -14,9 +14,6 @@ namespace Dalamud.Plugin.Ipc.Internal;
|
|||
/// </summary>
|
||||
internal abstract class CallGatePubSubBase
|
||||
{
|
||||
[ThreadStatic]
|
||||
private static IpcContext? ipcExecutionContext;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CallGatePubSubBase"/> class.
|
||||
/// </summary>
|
||||
|
|
@ -77,7 +74,7 @@ internal abstract class CallGatePubSubBase
|
|||
/// <returns>Returns a potential IPC context.</returns>
|
||||
public IpcContext? GetContext()
|
||||
{
|
||||
return ipcExecutionContext;
|
||||
return this.Channel.GetInvocationContext();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -172,11 +169,11 @@ internal abstract class CallGatePubSubBase
|
|||
|
||||
private IDisposable BuildContext()
|
||||
{
|
||||
ipcExecutionContext = new IpcContext
|
||||
this.Channel.SetInvocationContext(new IpcContext
|
||||
{
|
||||
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