From 982ac1effd07be6fca30c1a1b06a8dd1d3784d6f Mon Sep 17 00:00:00 2001 From: Albin Hedman Date: Thu, 14 Aug 2025 19:27:56 +0200 Subject: [PATCH] impl Send and Sync --- probe-plotter/src/metric.rs | 8 ++++++++ probe-plotter/src/setting.rs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/probe-plotter/src/metric.rs b/probe-plotter/src/metric.rs index 23fdf8c..cd0dfa1 100644 --- a/probe-plotter/src/metric.rs +++ b/probe-plotter/src/metric.rs @@ -15,6 +15,14 @@ pub struct Metric { x: *mut T, } +// Safety: No one besides us and the debug probe has the raw pointer, so we can safely transfer +// Metric to another thread / execution context if T can be safely transferred. +unsafe impl Send for Metric where T: Send + Metricable {} + +// Safety: We only allow mutability through exclusive references so there is no risk +// in having multiple shared references to this value across threads/execution contexts +unsafe impl Sync for Metric where T: Sync + Metricable {} + /// Create using [make_metric] /// /// ``` diff --git a/probe-plotter/src/setting.rs b/probe-plotter/src/setting.rs index bd5d976..d8f2609 100644 --- a/probe-plotter/src/setting.rs +++ b/probe-plotter/src/setting.rs @@ -6,6 +6,14 @@ pub struct Setting { x: *mut T, } +// Safety: No one besides us and the debug probe has the raw pointer, so we can safely transfer +// Setting to another thread / execution context if T can be safely transferred. +unsafe impl Send for Setting where T: Send + Metricable {} + +// Safety: We only allow mutability through exclusive references so there is no risk +// in having multiple shared references to this value across threads/execution contexts +unsafe impl Sync for Setting where T: Sync + Metricable {} + /// Create using [make_setting] /// /// ```