use std::ops::Deref;
use crate::bindings::vlib_main_t;
pub mod sync;
#[repr(transparent)]
pub struct MainRef(foreign_types::Opaque);
impl MainRef {
pub unsafe fn from_ptr_mut<'a>(ptr: *mut vlib_main_t) -> &'a mut Self {
unsafe { &mut *(ptr as *mut _) }
}
pub fn as_ptr(&self) -> *mut vlib_main_t {
self as *const _ as *mut _
}
pub fn thread_index(&self) -> u16 {
unsafe { (*self.as_ptr()).thread_index }
}
}
pub struct BarrierHeldMainRef(MainRef);
impl BarrierHeldMainRef {
pub unsafe fn from_ptr_mut<'a>(ptr: *mut vlib_main_t) -> &'a mut Self {
unsafe {
debug_assert!((*ptr).thread_index == 0);
&mut *(ptr as *mut _)
}
}
}
impl Deref for BarrierHeldMainRef {
type Target = MainRef;
fn deref(&self) -> &Self::Target {
&self.0
}
}