Skip to content

Commit 6f9cfa0

Browse files
authored
Fix shm api reexports (#2003)
* Export WithProtocolID * Update types.rs, lib.rs, and lib.rs * Remove ProtocolID from client storage * Change safety doc format
1 parent f9166cc commit 6f9cfa0

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

commons/zenoh-shm/src/api/client_storage/mod.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,19 @@ pub struct ShmClientSetBuilder;
4646
impl ShmClientSetBuilder {
4747
/// Add client to the storage (without including the default client set)
4848
#[zenoh_macros::unstable_doc]
49-
pub fn with_client(
50-
self,
51-
id: ProtocolID,
52-
client: Arc<dyn ShmClient>,
53-
) -> ShmClientStorageBuilder {
54-
let clients = BTreeMap::from([(id, client)]);
49+
pub fn with_client(self, client: Arc<dyn ShmClient>) -> ShmClientStorageBuilder {
50+
let clients = BTreeMap::from([(client.id(), client)]);
5551
ShmClientStorageBuilder::new(clients)
5652
}
5753

5854
/// Add list of clients to the storage (without including the default client set)
5955
#[zenoh_macros::unstable_doc]
60-
pub fn with_clients(
61-
self,
62-
clients: &[(ProtocolID, Arc<dyn ShmClient>)],
63-
) -> ShmClientStorageBuilder {
64-
let clients = clients.iter().cloned().collect();
56+
pub fn with_clients(self, clients: &[Arc<dyn ShmClient>]) -> ShmClientStorageBuilder {
57+
let clients = clients
58+
.iter()
59+
.cloned()
60+
.map(|client| (client.id(), client))
61+
.collect();
6562
ShmClientStorageBuilder::new(clients)
6663
}
6764

@@ -86,7 +83,8 @@ impl ShmClientStorageBuilder {
8683

8784
/// Add client to the storage
8885
#[zenoh_macros::unstable_doc]
89-
pub fn with_client(mut self, id: ProtocolID, client: Arc<dyn ShmClient>) -> ZResult<Self> {
86+
pub fn with_client(mut self, client: Arc<dyn ShmClient>) -> ZResult<Self> {
87+
let id = client.id();
9088
match self.clients.entry(id) {
9189
std::collections::btree_map::Entry::Occupied(occupied) => {
9290
bail!("Client already exists for id {id}: {:?}!", occupied)
@@ -100,8 +98,9 @@ impl ShmClientStorageBuilder {
10098

10199
/// Add list of clients to the storage
102100
#[zenoh_macros::unstable_doc]
103-
pub fn with_clients(mut self, clients: &[(ProtocolID, Arc<dyn ShmClient>)]) -> Self {
104-
self.clients.extend(clients.iter().cloned());
101+
pub fn with_clients(mut self, clients: &[Arc<dyn ShmClient>]) -> Self {
102+
self.clients
103+
.extend(clients.iter().cloned().map(|client| (client.id(), client)));
105104
self
106105
}
107106

commons/zenoh-shm/src/api/common/types.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ impl PtrInSegment {
4545
self.ptr
4646
}
4747

48-
pub fn ptr_mut(&mut self) -> *mut u8 {
48+
/// # SAFETY
49+
///
50+
/// This function is safe if there is guarantee that there is no concurrent access
51+
pub unsafe fn ptr_mut(&mut self) -> *mut u8 {
4952
self.ptr
5053
}
5154
}

commons/zenoh-shm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ tested_crate_module!(shm);
7171
#[derive(Clone, Debug, PartialEq, Eq)]
7272
pub struct ShmBufInfo {
7373
/// Actual data length
74-
/// NOTE: data_descriptor's len is >= of this len and describes the actual memory length
74+
/// NOTE: data descriptor's len is >= of this len and describes the actual memory length
7575
/// dedicated in shared memory segment for this particular buffer.
7676
pub data_len: NonZeroUsize,
7777

zenoh/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,10 @@ pub mod shm {
542542
cleanup::cleanup_orphaned_shm_segments,
543543
client::{shm_client::ShmClient, shm_segment::ShmSegment},
544544
client_storage::{ShmClientStorage, GLOBAL_CLIENT_STORAGE},
545-
common::types::{ChunkID, ProtocolID, SegmentID},
545+
common::{
546+
types::{ChunkID, ProtocolID, PtrInSegment, SegmentID},
547+
with_id::WithProtocolID,
548+
},
546549
protocol_implementations::posix::{
547550
posix_shm_client::PosixShmClient,
548551
posix_shm_provider_backend::{

0 commit comments

Comments
 (0)