Skip to content
4 changes: 2 additions & 2 deletions adapter/common/src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ use blueos::{
};
use blueos_infra::{
impl_simple_intrusive_adapter,
list::typed_ilist::{ListHead, ListIterator},
list::typed_ilist::{ListHead, ListHeadIterator},
};
use core::alloc::Layout;

// FIXME: We haven't got builtin memory pool API in allocator, so we just use
// HEAP's public API to implement the memory pool. There might be performance degradation.

type BlockList = ListHead<Block, Node>;
type BlockListIterator = ListIterator<Block, Node>;
type BlockListIterator = ListHeadIterator<Block, Node>;

#[derive(Debug)]
struct MemoryPoolInner {
Expand Down
3 changes: 1 addition & 2 deletions infra/src/lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ impl LiveFor<'_> {
}
}

// Similar to LiveFor, additionally contains a reference to a value.
// Borrow and BorrowMut have been used in [rust-std](https://doc.rust-lang.org/std/borrow/trait.BorrowMut.html),
// so we use Iou (I Owe U, aka, 借据) to name this struct.
// so we use Iou (I Owe You, aka, 借据) to name this struct.
#[derive(Default)]
#[repr(transparent)]
pub struct Iou<'a, T> {
Expand Down
1 change: 0 additions & 1 deletion infra/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ pub mod typed_ilist;

pub trait GenericList {
type Node;
type Iter: Iterator;
}
21 changes: 12 additions & 9 deletions infra/src/list/typed_atomic_ilist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,17 @@ impl<T, A: Adapter<T>> AtomicListHead<T, A> {
}

#[inline]
pub unsafe fn list_head_of_mut_unchecked(this: &mut T) -> &mut Self {
pub fn list_head_of_mut(this: &mut T) -> &mut Self {
let ptr = this as *mut _ as *mut u8;
let list_head_ptr = ptr.add(A::offset()) as *mut Self;
&mut *list_head_ptr
let list_head_ptr = unsafe { ptr.add(A::offset()) as *mut Self };
unsafe { &mut *list_head_ptr }
}

#[inline]
pub unsafe fn list_head_of(this: &T) -> &mut Self {
let ptr: *mut u8 = core::mem::transmute(this as *const _ as *const u8);
let list_head_ptr = unsafe { ptr.add(A::offset()) as *mut Self };
unsafe { &mut *list_head_ptr }
}

#[inline]
Expand Down Expand Up @@ -339,9 +346,7 @@ mod tests {
let inserted = inserted.clone();
let detached = detached.clone();
let t = thread::spawn(move || {
let lh = unsafe {
Ty::list_head_of_mut_unchecked(Arc::<Foo>::get_mut_unchecked(&mut f))
};
let lh = unsafe { Ty::list_head_of_mut(Arc::<Foo>::get_mut_unchecked(&mut f)) };
for k in 0..256 {
{
let mut h = head.write();
Expand Down Expand Up @@ -383,9 +388,7 @@ mod tests {
let num_bob = num_bob.clone();
let now_in = now_in.clone();
let t = thread::spawn(move || {
let lh = unsafe {
Ty::list_head_of_mut_unchecked(Arc::<Foo>::get_mut_unchecked(&mut f))
};
let lh = unsafe { Ty::list_head_of_mut(Arc::<Foo>::get_mut_unchecked(&mut f)) };
if i & 1 == 0 {
let mut aw = alice.write();
if Ty::insert_after(&mut *aw, lh) {
Expand Down
Loading