123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #[allow(dead_code)]
- pub type KResult<T> = Result<T, u32>;
- macro_rules! dont_check {
- ($arg:expr) => {
- match $arg {
- Ok(_) => (),
- Err(_) => (),
- }
- };
- }
- use alloc::sync::Arc;
- #[allow(unused_imports)]
- pub(crate) use dont_check;
- #[allow(unused_imports)]
- pub use crate::bindings::root as bindings;
- #[allow(unused_imports)]
- pub(crate) use crate::kernel::console::{
- print, println, println_debug, println_fatal, println_info, println_warn,
- };
- #[allow(unused_imports)]
- pub(crate) use crate::sync::might_sleep;
- #[allow(unused_imports)]
- pub(crate) use alloc::{boxed::Box, string::String, vec, vec::Vec};
- #[allow(unused_imports)]
- pub(crate) use core::{any::Any, fmt::Write, marker::PhantomData, str};
- use core::{mem::ManuallyDrop, ops::Deref};
- pub use crate::sync::{Mutex, RwSemaphore, Semaphore, Spin, Locked};
- pub struct BorrowedArc<'lt, T: ?Sized> {
- arc: ManuallyDrop<Arc<T>>,
- _phantom: PhantomData<&'lt ()>,
- }
- impl<'lt, T: ?Sized> BorrowedArc<'lt, T> {
- pub fn from_raw(ptr: *const T) -> Self {
- assert!(!ptr.is_null());
- Self {
- arc: ManuallyDrop::new(unsafe { Arc::from_raw(ptr) }),
- _phantom: PhantomData,
- }
- }
- pub fn new(ptr: &'lt *const T) -> Self {
- assert!(!ptr.is_null());
- Self {
- arc: ManuallyDrop::new(unsafe { Arc::from_raw(*ptr) }),
- _phantom: PhantomData,
- }
- }
- }
- impl<'lt, T: ?Sized> Deref for BorrowedArc<'lt, T> {
- type Target = Arc<T>;
- fn deref(&self) -> &Self::Target {
- &self.arc
- }
- }
- impl<'lt, T: ?Sized> AsRef<Arc<T>> for BorrowedArc<'lt, T> {
- fn as_ref(&self) -> &Arc<T> {
- &self.arc
- }
- }
- pub trait AsAny: Send + Sync {
- fn as_any(&self) -> &dyn Any;
- fn as_any_mut(&mut self) -> &mut dyn Any;
- }
- macro_rules! impl_any {
- ($t:ty) => {
- impl AsAny for $t {
- fn as_any(&self) -> &dyn Any {
- self
- }
- fn as_any_mut(&mut self) -> &mut dyn Any {
- self
- }
- }
- };
- }
- macro_rules! addr_of_mut_field {
- ($pointer:expr, $field:ident) => {
- core::ptr::addr_of_mut!((*$pointer).$field)
- };
- }
- pub(crate) use {addr_of_mut_field, impl_any};
|