Skip to content

Commit

Permalink
struct MsacAsmContextBuf: unsafe impl Send + Sync.
Browse files Browse the repository at this point in the history
  • Loading branch information
kkysen committed Jul 14, 2024
1 parent 5bb8b97 commit 1ec6eab
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/msac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,30 @@ impl Default for Rav1dMsacDSPContext {

pub type EcWin = usize;

/// # Safety
///
/// [`Self`] must be the first field of [`MsacAsmContext`] for asm layout purposes.
/// And [`Self::pos`] and [`Self::end`] must be either [`ptr::null`],
/// or [`Self::pos`] must point into (or the end of) [`MsacContext::data`],
/// and [`Self::end`] must point to the end of [`MsacContext::data`].
#[repr(C)]
struct MsacAsmContextBuf {
pos: *const u8,
end: *const u8,
}

/// SAFETY: [`MsacAsmContextBuf`] is always contained in [`MsacAsmContext::buf`],
/// which is always contained in [`MsacContext::asm`], whose [`MsacContext::data`] field
/// is what is stored in [`MsacAsmContextBuf::pos`] and [`MsacAsmContextBuf::end`].
/// Since [`MsacContext::data`] is [`Send`], [`MsacAsmContextBuf`] is also [`Send`].
unsafe impl Send for MsacAsmContextBuf {}

/// SAFETY: [`MsacAsmContextBuf`] is always contained in [`MsacAsmContext::buf`],
/// which is always contained in [`MsacContext::asm`], whose [`MsacContext::data`] field
/// is what is stored in [`MsacAsmContextBuf::pos`] and [`MsacAsmContextBuf::end`].
/// Since [`MsacContext::data`] is [`Sync`], [`MsacAsmContextBuf`] is also [`Sync`].
unsafe impl Sync for MsacAsmContextBuf {}

impl Default for MsacAsmContextBuf {
fn default() -> Self {
Self {
Expand Down

0 comments on commit 1ec6eab

Please sign in to comment.