Skip to content

Commit

Permalink
Merge pull request #352 from LGFae/nuke-multithreading
Browse files Browse the repository at this point in the history
Nuke multithreading
  • Loading branch information
LGFae committed Aug 12, 2024
2 parents 81ae449 + 810960d commit 886ce3e
Show file tree
Hide file tree
Showing 10 changed files with 939 additions and 863 deletions.
6 changes: 3 additions & 3 deletions common/src/ipc/transmit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@ impl From<RawMsg> for RequestRecv {

Self::Img(ImageReq {
transition,
imgs: imgs.into(),
outputs: outputs.into(),
imgs,
outputs,
animations: if animations.is_empty() {
None
} else {
Some(animations.into())
Some(animations)
},
})
}
Expand Down
6 changes: 3 additions & 3 deletions common/src/ipc/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,9 +591,9 @@ impl Animation {

pub struct ImageReq {
pub transition: Transition,
pub imgs: Box<[ImgReq]>,
pub outputs: Box<[Box<[MmappedStr]>]>,
pub animations: Option<Box<[Animation]>>,
pub imgs: Vec<ImgReq>,
pub outputs: Vec<Box<[MmappedStr]>>,
pub animations: Option<Vec<Animation>>,
}

fn deserialize_string(bytes: &[u8]) -> String {
Expand Down
20 changes: 11 additions & 9 deletions common/src/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,14 @@ impl<const UTF8: bool> Mmapped<UTF8> {
const PROT: ProtFlags = ProtFlags::READ;
const FLAGS: MapFlags = MapFlags::SHARED;

#[must_use]
pub(crate) fn new(map: &Mmap, bytes: &[u8]) -> Self {
let len = u32::from_ne_bytes(bytes[0..4].try_into().unwrap()) as usize;
let bytes = &bytes[4..];
Self::new_with_len(map, bytes, len)
}

#[must_use]
pub(crate) fn new_with_len(map: &Mmap, bytes: &[u8], len: usize) -> Self {
let offset = bytes.as_ptr() as usize - map.ptr.as_ptr() as usize;
let page_size = rustix::param::page_size();
Expand Down Expand Up @@ -293,26 +295,26 @@ impl<const UTF8: bool> Mmapped<UTF8> {
pub fn bytes(&self) -> &[u8] {
unsafe { std::slice::from_raw_parts(self.ptr.as_ptr().cast(), self.len) }
}
}

impl MmappedStr {
#[inline]
#[must_use]
pub fn str(&self) -> &str {
let s = unsafe { std::slice::from_raw_parts(self.ptr.as_ptr().cast(), self.len) };
unsafe { std::str::from_utf8_unchecked(s) }
pub const fn str(&self) -> &str {
if UTF8 {
unsafe {
let slice = std::slice::from_raw_parts(self.ptr.as_ptr().cast(), self.len);
std::str::from_utf8_unchecked(slice)
}
} else {
panic!("trying to use a mmap that is not a utf8 as str")
}
}
}

impl<const UTF8: bool> Drop for Mmapped<UTF8> {
#[inline]
fn drop(&mut self) {
let len = self.len + self.ptr.as_ptr() as usize - self.base_ptr.as_ptr() as usize;
if let Err(e) = unsafe { munmap(self.base_ptr.as_ptr(), len) } {
eprintln!("ERROR WHEN UNMAPPING MEMORY: {e}");
}
}
}

unsafe impl<const UTF8: bool> Send for Mmapped<UTF8> {}
unsafe impl<const UTF8: bool> Sync for Mmapped<UTF8> {}
104 changes: 0 additions & 104 deletions daemon/src/animations/anim_barrier.rs

This file was deleted.

Loading

0 comments on commit 886ce3e

Please sign in to comment.