Skip to content

Commit 41f951f

Browse files
committed
docs: safety for Send+Sync for ProfileStatus
1 parent 208c5f6 commit 41f951f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

libdd-profiling-ffi/src/profile_status.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,25 @@ impl Default for ProfileStatus {
4444
}
4545
}
4646

47+
// SAFETY: ProfileStatus is Send because:
48+
// 1. The `flags` field is a usize, which is Send.
49+
// 2. The `err` pointer is either:
50+
// - Null (FLAG_OK), which is trivially Send
51+
// - Points to static data (FLAG_STATIC), which is 'static and therefore Send
52+
// - Points to heap-allocated data (FLAG_ALLOCATED) that this ProfileStatus owns exclusively.
53+
// When sent to another thread, the ownership of the allocation transfers with it, and the drop
54+
// implementation ensures proper cleanup on the receiving thread.
55+
// This is semantically equivalent to `Result<(), Cow<'static, CStr>>`, which is Send.
4756
unsafe impl Send for ProfileStatus {}
57+
58+
// SAFETY: ProfileStatus is Sync because:
59+
// 1. All fields are immutable from a shared reference (&ProfileStatus).
60+
// 2. The `err` pointer points to immutable data:
61+
// - Static CStr (FLAG_STATIC): &'static CStr is Sync
62+
// - Heap-allocated CStr (FLAG_ALLOCATED): The CStr is never mutated after creation, so multiple
63+
// threads can safely read it concurrently.
64+
// 3. There are no interior mutability patterns (no Cell, RefCell, etc.).
65+
// Multiple threads holding &ProfileStatus can safely read the same error message.
4866
unsafe impl Sync for ProfileStatus {}
4967

5068
impl<E> From<Result<(), E>> for ProfileStatus

0 commit comments

Comments
 (0)