Skip to content

Commit 982ac1e

Browse files
committed
impl Send and Sync
1 parent 721d16d commit 982ac1e

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

probe-plotter/src/metric.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ pub struct Metric<T: Metricable> {
1515
x: *mut T,
1616
}
1717

18+
// Safety: No one besides us and the debug probe has the raw pointer, so we can safely transfer
19+
// Metric to another thread / execution context if T can be safely transferred.
20+
unsafe impl<T> Send for Metric<T> where T: Send + Metricable {}
21+
22+
// Safety: We only allow mutability through exclusive references so there is no risk
23+
// in having multiple shared references to this value across threads/execution contexts
24+
unsafe impl<T> Sync for Metric<T> where T: Sync + Metricable {}
25+
1826
/// Create using [make_metric]
1927
///
2028
/// ```

probe-plotter/src/setting.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ pub struct Setting<T: Metricable> {
66
x: *mut T,
77
}
88

9+
// Safety: No one besides us and the debug probe has the raw pointer, so we can safely transfer
10+
// Setting to another thread / execution context if T can be safely transferred.
11+
unsafe impl<T> Send for Setting<T> where T: Send + Metricable {}
12+
13+
// Safety: We only allow mutability through exclusive references so there is no risk
14+
// in having multiple shared references to this value across threads/execution contexts
15+
unsafe impl<T> Sync for Setting<T> where T: Sync + Metricable {}
16+
917
/// Create using [make_setting]
1018
///
1119
/// ```

0 commit comments

Comments
 (0)