Skip to content

Commit

Permalink
[#129] Store SharedMemoryManagent in separate pointer instead of acqu…
Browse files Browse the repository at this point in the history
…iring it from the base address
  • Loading branch information
elfenpiff committed Mar 6, 2024
1 parent b787bf5 commit 5b9d0cf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ windows-sys = { version = "0.48.0", features = ["Win32_Security", "Win32_Securit
"Win32_System_SystemServices"] }

[profile.release]
strip = true
lto = true
# opt-level = "z"
panic = "abort"
debug = true
# strip = true
# lto = true
# # opt-level = "z"
# panic = "abort"
18 changes: 12 additions & 6 deletions iceoryx2-cal/src/zero_copy_connection/posix_shared_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,13 @@ impl ZeroCopyConnectionBuilder<Connection> for Builder {
let shm = fail!(from self, when self.create_or_open_shm(),
"{} since the corresponding connection could not be created or opened", msg);

let mgmt_ref = unsafe { &mut *(shm.base_address().as_ptr() as *mut SharedManagementData) };
self.reserve_port(mgmt_ref, State::Sender.value(), msg)?;
let mgmt = unsafe { &mut *(shm.base_address().as_ptr() as *mut SharedManagementData) };
self.reserve_port(mgmt, State::Sender.value(), msg)?;

Ok(Sender {
shared_memory: shm,
name: self.name,
mgmt,
})
}

Expand All @@ -422,13 +423,14 @@ impl ZeroCopyConnectionBuilder<Connection> for Builder {
let shm = fail!(from self, when self.create_or_open_shm(),
"{} since the corresponding connection could not be created or opened", msg);

let mgmt_ref = unsafe { &mut *(shm.base_address().as_ptr() as *mut SharedManagementData) };
self.reserve_port(mgmt_ref, State::Receiver.value(), msg)?;
let mgmt = unsafe { &mut *(shm.base_address().as_ptr() as *mut SharedManagementData) };
self.reserve_port(mgmt, State::Receiver.value(), msg)?;

Ok(Receiver {
shared_memory: shm,
borrow_counter: UnsafeCell::new(0),
name: self.name,
mgmt,
})
}
}
Expand All @@ -437,6 +439,7 @@ impl ZeroCopyConnectionBuilder<Connection> for Builder {
pub struct Sender {
shared_memory: SharedMemory,
name: FileName,
mgmt: *const SharedManagementData,
}

impl Drop for Sender {
Expand All @@ -446,8 +449,9 @@ impl Drop for Sender {
}

impl Sender {
#[inline(always)]
fn mgmt(&self) -> &SharedManagementData {
unsafe { &*(self.shared_memory.base_address().as_ptr() as *const SharedManagementData) }
unsafe { &*self.mgmt }
}
}

Expand Down Expand Up @@ -555,6 +559,7 @@ pub struct Receiver {
shared_memory: SharedMemory,
borrow_counter: UnsafeCell<usize>,
name: FileName,
mgmt: *const SharedManagementData,
}

impl Drop for Receiver {
Expand All @@ -564,8 +569,9 @@ impl Drop for Receiver {
}

impl Receiver {
#[inline(always)]
fn mgmt(&self) -> &SharedManagementData {
unsafe { &*(self.shared_memory.base_address().as_ptr() as *const SharedManagementData) }
unsafe { &*self.mgmt }
}

#[allow(clippy::mut_from_ref)]
Expand Down

0 comments on commit 5b9d0cf

Please sign in to comment.