Skip to content

Commit 15a3142

Browse files
authored
Custom slot suplier (#372)
1 parent c219615 commit 15a3142

31 files changed

+1456
-130
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ obj/
77
/tests/golangworker/golangworker
88
/.vs
99
/.vscode
10-
/.idea
10+
/.idea
11+
/.zed
12+
Temporalio.sln.DotSettings.user

src/Temporalio/Bridge/Cargo.lock

Lines changed: 15 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Temporalio/Bridge/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ crate-type = ["cdylib", "rlib"]
99

1010
[dependencies]
1111
anyhow = "1.0"
12+
async-trait = "0.1"
1213
futures = "0.3"
1314
libc = "0.2"
1415
log = "0.4"
@@ -21,7 +22,9 @@ rand = "0.8.5"
2122
rand_pcg = "0.3.1"
2223
serde_json = "1.0"
2324
temporal-client = { version = "0.1.0", path = "./sdk-core/client" }
24-
temporal-sdk-core = { version = "0.1.0", path = "./sdk-core/core", features = ["ephemeral-server"] }
25+
temporal-sdk-core = { version = "0.1.0", path = "./sdk-core/core", features = [
26+
"ephemeral-server",
27+
] }
2528
temporal-sdk-core-api = { version = "0.1.0", path = "./sdk-core/core-api" }
2629
temporal-sdk-core-protos = { version = "0.1.0", path = "./sdk-core/sdk-core-protos" }
2730
tokio = "1.26"
@@ -39,3 +42,4 @@ incremental = false
3942

4043
[build-dependencies]
4144
cbindgen = "0.24"
45+
anyhow = "1.0"

src/Temporalio/Bridge/CustomMetricMeter.cs

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ namespace Temporalio.Bridge
77
/// <summary>
88
/// Core wrapper for a custom metric meter implementation.
99
/// </summary>
10-
internal class CustomMetricMeter
10+
internal class CustomMetricMeter : NativeInvokeableClass<Interop.CustomMetricMeter>
1111
{
1212
private readonly Temporalio.Runtime.ICustomMetricMeter meter;
1313
private readonly Temporalio.Runtime.CustomMetricMeterOptions options;
14-
private readonly List<GCHandle> handles = new();
1514

1615
/// <summary>
1716
/// Initializes a new instance of the <see cref="CustomMetricMeter" /> class.
@@ -38,20 +37,9 @@ public unsafe CustomMetricMeter(
3837
meter_free = FunctionPointer<Interop.CustomMetricMeterMeterFreeCallback>(Free),
3938
};
4039

41-
// Pin the metric meter pointer and set it as the first handle
42-
var interopMeterHandle = GCHandle.Alloc(interopMeter, GCHandleType.Pinned);
43-
handles.Insert(0, interopMeterHandle);
44-
Ptr = (Interop.CustomMetricMeter*)interopMeterHandle.AddrOfPinnedObject();
45-
46-
// Add handle for ourself
47-
handles.Add(GCHandle.Alloc(this));
40+
PinCallbackHolder(interopMeter);
4841
}
4942

50-
/// <summary>
51-
/// Gets the pointer to the native metric meter.
52-
/// </summary>
53-
internal unsafe Interop.CustomMetricMeter* Ptr { get; private init; }
54-
5543
private static unsafe string? GetStringOrNull(Interop.ByteArrayRef bytes) =>
5644
(int)bytes.size == 0 ? null : GetString(bytes);
5745

@@ -220,23 +208,5 @@ private unsafe void RecordMetricDuration(void* metric, ulong valueMs, void* attr
220208
}
221209

222210
private unsafe void FreeAttributes(void* attributes) => GCHandle.FromIntPtr(new(attributes)).Free();
223-
224-
private unsafe void Free(Interop.CustomMetricMeter* meter)
225-
{
226-
// Free in order which frees function pointers first then meter handles
227-
foreach (var handle in handles)
228-
{
229-
handle.Free();
230-
}
231-
}
232-
233-
// Similar to Scope.FunctionPointer
234-
private IntPtr FunctionPointer<T>(T func)
235-
where T : Delegate
236-
{
237-
var handle = GCHandle.Alloc(func);
238-
handles.Add(handle);
239-
return Marshal.GetFunctionPointerForDelegate(handle.Target!);
240-
}
241211
}
242-
}
212+
}

0 commit comments

Comments
 (0)