Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom slot suplier #372

Merged
merged 8 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ obj/
/tests/golangworker/golangworker
/.vs
/.vscode
/.idea
/.idea
/.zed
Temporalio.sln.DotSettings.user
29 changes: 15 additions & 14 deletions src/Temporalio/Bridge/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/Temporalio/Bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
anyhow = "1.0"
async-trait = "0.1"
futures = "0.3"
libc = "0.2"
log = "0.4"
Expand All @@ -21,7 +22,9 @@ rand = "0.8.5"
rand_pcg = "0.3.1"
serde_json = "1.0"
temporal-client = { version = "0.1.0", path = "./sdk-core/client" }
temporal-sdk-core = { version = "0.1.0", path = "./sdk-core/core", features = ["ephemeral-server"] }
temporal-sdk-core = { version = "0.1.0", path = "./sdk-core/core", features = [
"ephemeral-server",
] }
temporal-sdk-core-api = { version = "0.1.0", path = "./sdk-core/core-api" }
temporal-sdk-core-protos = { version = "0.1.0", path = "./sdk-core/sdk-core-protos" }
tokio = "1.26"
Expand All @@ -39,3 +42,4 @@ incremental = false

[build-dependencies]
cbindgen = "0.24"
anyhow = "1.0"
36 changes: 3 additions & 33 deletions src/Temporalio/Bridge/CustomMetricMeter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ namespace Temporalio.Bridge
/// <summary>
/// Core wrapper for a custom metric meter implementation.
/// </summary>
internal class CustomMetricMeter
internal class CustomMetricMeter : NativeInvokeableClass<Interop.CustomMetricMeter>
{
private readonly Temporalio.Runtime.ICustomMetricMeter meter;
private readonly Temporalio.Runtime.CustomMetricMeterOptions options;
private readonly List<GCHandle> handles = new();

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

// Pin the metric meter pointer and set it as the first handle
var interopMeterHandle = GCHandle.Alloc(interopMeter, GCHandleType.Pinned);
handles.Insert(0, interopMeterHandle);
Ptr = (Interop.CustomMetricMeter*)interopMeterHandle.AddrOfPinnedObject();

// Add handle for ourself
handles.Add(GCHandle.Alloc(this));
PinCallbackHolder(interopMeter);
}

/// <summary>
/// Gets the pointer to the native metric meter.
/// </summary>
internal unsafe Interop.CustomMetricMeter* Ptr { get; private init; }

private static unsafe string? GetStringOrNull(Interop.ByteArrayRef bytes) =>
(int)bytes.size == 0 ? null : GetString(bytes);

Expand Down Expand Up @@ -220,23 +208,5 @@ private unsafe void RecordMetricDuration(void* metric, ulong valueMs, void* attr
}

private unsafe void FreeAttributes(void* attributes) => GCHandle.FromIntPtr(new(attributes)).Free();

private unsafe void Free(Interop.CustomMetricMeter* meter)
{
// Free in order which frees function pointers first then meter handles
foreach (var handle in handles)
{
handle.Free();
}
}

// Similar to Scope.FunctionPointer
private IntPtr FunctionPointer<T>(T func)
where T : Delegate
{
var handle = GCHandle.Alloc(func);
handles.Add(handle);
return Marshal.GetFunctionPointerForDelegate(handle.Target!);
}
}
}
}
Loading
Loading