Skip to content
Open
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
19 changes: 17 additions & 2 deletions src/ptr/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ pub use tagged_pointer::TaggedPtr;

pub mod ref_count;
pub use ref_count::{
AnyRefCounted, CellRefCounted, RefCount, RefCounted, RefPtr, ScopedRef, ThreadSafeRefCount,
ThreadSafeRefCounted, destroy_box_with, finalize_js_box, finalize_js_box_noop,
AnyRefCounted, CellRefCounted, OwnedRef, RefCount, RefCounted, RefPtr, ScopedRef,
ThreadSafeRefCount, ThreadSafeRefCounted, destroy_box_with, finalize_js_box,
finalize_js_box_noop,
};
// Derive macros — same names as the traits (separate namespace). The derives
// expand to `::bun_ptr::…` paths, so this crate is the canonical re-export
Expand Down Expand Up @@ -626,6 +627,20 @@ where
// SAFETY: `ThisPtr::new` invariant — `self.0` points to a live `T`.
unsafe { ScopedRef::new(self.0.as_ptr()) }
}

/// Take a ref to keep, as an [`OwnedRef`]: for parking `this` in a field
/// or a queue while an operation it started is in flight. Dropping the
/// returned value later is the matching release.
///
/// Safe for the same reason as [`ref_guard`](Self::ref_guard): `new`
/// established that the pointee is live, and the pointer is the one the
/// dispatch handed us, which is the one its `deref()` expects.
Comment thread
robobun marked this conversation as resolved.
#[inline]
pub fn owned_ref(self) -> OwnedRef<T> {
// SAFETY: `ThisPtr::new` invariant — `self.0` points to a live `T`,
// via the root pointer the callback was dispatched with.
unsafe { OwnedRef::acquire(self.0.as_ptr()) }
}
}

// SAFETY: `BackRef<T, P>` is morally `&T` (Deref/get) with, for `P = Mut`, an
Expand Down
Loading