1
0
Fork 0
forked from wry/wry

autocommit 2022-03-02 14:24:07 CET

This commit is contained in:
Julian Orth 2022-03-02 14:24:07 +01:00
parent 0e9afcbfa5
commit aa0cb94143
30 changed files with 1059 additions and 123 deletions

View file

@ -1,22 +0,0 @@
use uapi::{Packed, Pod};
#[repr(C, align(8))]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct AlignedI64(pub i64);
unsafe impl Pod for AlignedI64 {}
unsafe impl Packed for AlignedI64 {}
#[repr(C, align(8))]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct AlignedU64(pub u64);
unsafe impl Pod for AlignedU64 {}
unsafe impl Packed for AlignedU64 {}
#[repr(C, align(8))]
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct AlignedF64(pub f64);
unsafe impl Pod for AlignedF64 {}
unsafe impl Packed for AlignedF64 {}

28
src/utils/bitfield.rs Normal file
View file

@ -0,0 +1,28 @@
use std::mem;
const SEG_SIZE: usize = 8 * mem::size_of::<usize>();
#[derive(Default)]
pub struct Bitfield {
vals: Vec<usize>,
}
impl Bitfield {
pub fn acquire(&mut self) -> u32 {
for (idx, n) in self.vals.iter_mut().enumerate() {
if *n != 0 {
let pos = n.trailing_zeros();
*n &= !(1 << pos);
return (idx * SEG_SIZE) as u32 + pos;
}
}
self.vals.push(!1);
((self.vals.len() - 1) * SEG_SIZE) as u32
}
pub fn release(&mut self, val: u32) {
let idx = val as usize / SEG_SIZE;
let pos = val as usize % SEG_SIZE;
self.vals[idx] |= 1 << pos;
}
}

View file

@ -101,7 +101,9 @@ impl BufFdOut {
_ = timeout.as_mut().unwrap() => {
return Err(BufFdError::Timeout);
},
res = self.fd.writable().fuse() => res?,
res = self.fd.writable().fuse() => {
res?;
},
}
}
}

View file

@ -1,4 +1,3 @@
pub mod aligned;
pub mod array;
pub mod asyncevent;
pub mod bitflags;
@ -18,3 +17,4 @@ pub mod stack;
pub mod tri;
pub mod vec_ext;
pub mod vecstorage;
pub mod bitfield;