Skip to content

Commit 478324f

Browse files
committed
No need to make gchandles for permits at all
1 parent 0ee6a32 commit 478324f

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

src/Temporalio/Bridge/CustomSlotSupplier.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal class CustomSlotSupplier : NativeInvokeableClass<Interop.CustomSlotSupp
1515
{
1616
private readonly ILogger logger;
1717
private readonly Temporalio.Worker.Tuning.ICustomSlotSupplier userSupplier;
18-
private readonly Dictionary<uint, GCHandle> permits = new();
18+
private readonly Dictionary<uint, Temporalio.Worker.Tuning.ISlotPermit> permits = new();
1919
private uint permitId = 1;
2020

2121
/// <summary>
@@ -167,11 +167,10 @@ private void Release(Interop.SlotReleaseCtx ctx)
167167

168168
private uint AddPermitToMap(Temporalio.Worker.Tuning.ISlotPermit permit)
169169
{
170-
var handle = GCHandle.Alloc(permit);
171170
lock (permits)
172171
{
173172
var usedPermitId = permitId;
174-
permits.Add(permitId, handle);
173+
permits.Add(permitId, permit);
175174
permitId += 1;
176175
return usedPermitId;
177176
}

src/Temporalio/Worker/Tuning/SlotMarkUsedContext.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ public class SlotMarkUsedContext
1414
/// Initializes a new instance of the <see cref="SlotMarkUsedContext"/> class.
1515
/// </summary>
1616
/// <param name="ctx">The bridge version of the slot mark used context.</param>
17-
/// <param name="userData">The user data associated with the slot.</param>
18-
internal SlotMarkUsedContext(Temporalio.Bridge.Interop.SlotMarkUsedCtx ctx, GCHandle userData)
17+
/// <param name="permit">The user-create permit instance.</param>
18+
internal SlotMarkUsedContext(Temporalio.Bridge.Interop.SlotMarkUsedCtx ctx, ISlotPermit permit)
1919
{
2020
this.SlotInfo = SlotInfo.FromBridge(ctx.slot_info);
21-
unsafe
22-
{
23-
this.Permit = (ISlotPermit)userData.Target!;
24-
}
21+
this.Permit = permit;
2522
}
2623

2724
/// <summary>

src/Temporalio/Worker/Tuning/SlotReleaseContext.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System.Runtime.InteropServices;
2-
31
namespace Temporalio.Worker.Tuning
42
{
53
/// <summary>
@@ -14,14 +12,14 @@ public class SlotReleaseContext
1412
/// Initializes a new instance of the <see cref="SlotReleaseContext"/> class.
1513
/// </summary>
1614
/// <param name="ctx">The bridge version of the slot release context.</param>
17-
/// <param name="userData">The user data associated with the slot.</param>
18-
internal SlotReleaseContext(Temporalio.Bridge.Interop.SlotReleaseCtx ctx, GCHandle userData)
15+
/// <param name="permit">The user-create permit instance.</param>
16+
internal SlotReleaseContext(Temporalio.Bridge.Interop.SlotReleaseCtx ctx, ISlotPermit permit)
1917
{
2018
unsafe
2119
{
2220
this.SlotInfo = ctx.slot_info is null ? null : SlotInfo.FromBridge(*ctx.slot_info);
23-
this.Permit = (ISlotPermit)userData.Target!;
2421
}
22+
this.Permit = permit;
2523
}
2624

2725
/// <summary>

0 commit comments

Comments
 (0)