Skip to content

Commit

Permalink
SELF_VTABLE is now properly guarded by lock
Browse files Browse the repository at this point in the history
  • Loading branch information
bazhenov committed Jan 4, 2025
1 parent 8252203 commit 64e8a97
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tango-bench/src/dylib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ impl Spi {
}

pub(crate) fn for_self(mode: SpiModeKind) -> Option<Spi> {
unsafe { SELF_VTABLE.take() }.map(|vt| spi_handle_for_vtable(vt, mode))
SELF_VTABLE
.lock()
.unwrap()
.take()
.map(|vt| spi_handle_for_vtable(vt, mode))
}

pub(crate) fn tests(&self) -> &[NamedFunction] {
Expand Down Expand Up @@ -329,6 +333,7 @@ pub mod ffi {
os::raw::c_char,
panic::{catch_unwind, UnwindSafe},
ptr::null,
sync::Mutex,
};

/// Signature types of all FFI API functions
Expand Down Expand Up @@ -470,7 +475,7 @@ pub mod ffi {
}
}

pub(super) static mut SELF_VTABLE: Option<VTable> = Some(VTable::for_self());
pub(super) static SELF_VTABLE: Mutex<Option<VTable>> = Mutex::new(Some(VTable::for_self()));

pub(super) struct VTable {
/// SAFETY: using plain function pointers instead of [`Symbol`] here to generalize over case
Expand Down

0 comments on commit 64e8a97

Please sign in to comment.