Skip to content

Commit

Permalink
docs(core/mailbox): note about pinning
Browse files Browse the repository at this point in the history
  • Loading branch information
loyd committed Jun 25, 2024
1 parent ad83a64 commit 663350d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion elfo-core/src/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
///
/// [`Context`]: crate::Context
/// [`msg!`]: crate::msg
pub struct Envelope(NonNull<EnvelopeHeader>); // TODO: Pin<NonNull<_>>?
pub struct Envelope(NonNull<EnvelopeHeader>);

// Messages aren't required to be `Sync`.
assert_not_impl_any!(Envelope: Sync);
Expand Down
11 changes: 7 additions & 4 deletions elfo-core/src/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ assert_not_impl_any!(EnvelopeHeader: Unpin);
// SAFETY:
// * `EnvelopeHeader` is pinned in memory while it is in the queue, the only way
// to access inserted `EnvelopeHeader` is by using the `dequeue()` method.
// * `EnvelopeHeader` cannot be deallocated without prunning the queue.
// * `EnvelopeHeader` doesn't implement `Unpin` (checked statically).
unsafe impl Linked<Links<EnvelopeHeader>> for EnvelopeHeader {
// * `EnvelopeHeader` cannot be deallocated without prunning the queue, which is
// done also by calling `dequeue()` method multiple times.
// * `EnvelopeHeader` doesn't implement `Unpin` (checked statically above).
unsafe impl Linked<Link> for EnvelopeHeader {
// It would be nice to enforce pinning here by using `Pin<Envelope>`.
// However, it's not possible because `Pin` requires `Deref` impl.
type Handle = Envelope;

fn into_ptr(handle: Self::Handle) -> NonNull<Self> {
Expand All @@ -62,7 +65,7 @@ unsafe impl Linked<Links<EnvelopeHeader>> for EnvelopeHeader {
Self::Handle::from_header_ptr(ptr)
}

unsafe fn links(ptr: NonNull<Self>) -> NonNull<Links<Self>> {
unsafe fn links(ptr: NonNull<Self>) -> NonNull<Link> {
// Using `ptr::addr_of_mut!` permits us to avoid creating a temporary
// reference without using layout-dependent casts.
let links = ptr::addr_of_mut!((*ptr.as_ptr()).link);
Expand Down
2 changes: 0 additions & 2 deletions elfo-core/src/message/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ assert_not_impl_any!(AnyMessage: Sync);
// SAFETY: `AnyMessage` can point to `M: Message` only, which is `Send`.
unsafe impl Send for AnyMessage {}

// TODO: Pin/Unpin?

impl AnyMessage {
/// Converts a message into [`AnyMessage`].
#[inline]
Expand Down

0 comments on commit 663350d

Please sign in to comment.