-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adopt some SHM data structures to support NPO (needed as elegant way …
…to equalize some data structure sizes in zenoh-c)
- Loading branch information
1 parent
fc18f90
commit 6bd1b78
Showing
12 changed files
with
123 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
// Contributors: | ||
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
use std::num::NonZeroUsize; | ||
|
||
use zenoh_buffers::{ | ||
reader::{DidntRead, Reader}, | ||
writer::{DidntWrite, Writer}, | ||
|
@@ -62,6 +64,18 @@ where | |
} | ||
} | ||
|
||
impl<W> WCodec<NonZeroUsize, &mut W> for Zenoh080 | ||
where | ||
W: Writer, | ||
{ | ||
type Output = Result<(), DidntWrite>; | ||
|
||
fn write(self, writer: &mut W, x: NonZeroUsize) -> Self::Output { | ||
self.write(&mut *writer, x.get())?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl<W> WCodec<&ShmBufInfo, &mut W> for Zenoh080 | ||
where | ||
W: Writer, | ||
|
@@ -80,7 +94,7 @@ where | |
|
||
self.write(&mut *writer, data_descriptor)?; | ||
self.write(&mut *writer, shm_protocol)?; | ||
self.write(&mut *writer, data_len)?; | ||
self.write(&mut *writer, *data_len)?; | ||
self.write(&mut *writer, watchdog_descriptor)?; | ||
self.write(&mut *writer, header_descriptor)?; | ||
self.write(&mut *writer, generation)?; | ||
|
@@ -138,6 +152,19 @@ where | |
} | ||
} | ||
|
||
impl<R> RCodec<NonZeroUsize, &mut R> for Zenoh080 | ||
where | ||
R: Reader, | ||
{ | ||
type Error = DidntRead; | ||
|
||
fn read(self, reader: &mut R) -> Result<NonZeroUsize, Self::Error> { | ||
let size: usize = self.read(&mut *reader)?; | ||
let size = NonZeroUsize::new(size).ok_or(DidntRead)?; | ||
Ok(size) | ||
} | ||
} | ||
|
||
impl<R> RCodec<ShmBufInfo, &mut R> for Zenoh080 | ||
where | ||
R: Reader, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
|
||
use std::sync::atomic::AtomicPtr; | ||
use std::{num::NonZeroUsize, sync::atomic::AtomicPtr}; | ||
|
||
use zenoh_result::ZResult; | ||
|
||
|
@@ -32,8 +32,8 @@ pub(crate) struct PosixShmSegment { | |
} | ||
|
||
impl PosixShmSegment { | ||
pub(crate) fn create(alloc_size: usize) -> ZResult<Self> { | ||
let segment = ArrayInSHM::create(alloc_size, POSIX_SHM_SEGMENT_PREFIX)?; | ||
pub(crate) fn create(alloc_size: NonZeroUsize) -> ZResult<Self> { | ||
let segment = ArrayInSHM::create(alloc_size.get(), POSIX_SHM_SEGMENT_PREFIX)?; | ||
Ok(Self { segment }) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
|
||
use std::sync::atomic::AtomicPtr; | ||
use std::{num::NonZeroUsize, sync::atomic::AtomicPtr}; | ||
|
||
use crate::api::common::types::{ChunkID, SegmentID}; | ||
|
||
|
@@ -22,13 +22,13 @@ use crate::api::common::types::{ChunkID, SegmentID}; | |
pub struct ChunkDescriptor { | ||
pub segment: SegmentID, | ||
pub chunk: ChunkID, | ||
pub len: usize, | ||
pub len: NonZeroUsize, | ||
} | ||
|
||
impl ChunkDescriptor { | ||
/// Create a new Chunk Descriptor | ||
#[zenoh_macros::unstable_doc] | ||
pub fn new(segment: SegmentID, chunk: ChunkID, len: usize) -> Self { | ||
pub fn new(segment: SegmentID, chunk: ChunkID, len: NonZeroUsize) -> Self { | ||
Self { | ||
segment, | ||
chunk, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,9 @@ | |
// Contributors: | ||
// ZettaScale Zenoh Team, <[email protected]> | ||
// | ||
|
||
use zenoh_result::ZResult; | ||
|
||
use super::{ | ||
chunk::ChunkDescriptor, | ||
types::{ChunkAllocResult, MemoryLayout}, | ||
types::{ChunkAllocResult, MemoryLayout, ZLayoutError}, | ||
}; | ||
|
||
/// The provider backend trait | ||
|
@@ -48,5 +45,5 @@ pub trait ShmProviderBackend { | |
/// - validate, if the provided layout can be used with this backend | ||
/// - adopt the layout for backend capabilities | ||
#[zenoh_macros::unstable_doc] | ||
fn layout_for(&self, layout: MemoryLayout) -> ZResult<MemoryLayout>; | ||
fn layout_for(&self, layout: MemoryLayout) -> Result<MemoryLayout, ZLayoutError>; | ||
} |
Oops, something went wrong.