From 127fb3ac7c814d58325aa25845f1a48bfc7aed64 Mon Sep 17 00:00:00 2001 From: yellowhatter Date: Wed, 11 Sep 2024 13:31:06 +0300 Subject: [PATCH] res() -> wait() --- commons/zenoh-core/src/lib.rs | 2 +- .../posix/posix_shm_provider_backend.rs | 14 +++++++++----- .../zenoh-shm/src/api/provider/shm_provider.rs | 15 ++++++++++++--- commons/zenoh-shm/tests/posix_shm_provider.rs | 9 +++++---- examples/examples/z_alloc_shm.rs | 6 +++--- examples/examples/z_bytes_shm.rs | 4 ++-- examples/examples/z_get_shm.rs | 6 +++--- examples/examples/z_ping_shm.rs | 6 +++--- examples/examples/z_posix_shm_provider.rs | 12 ++++++++---- examples/examples/z_pub_shm.rs | 6 +++--- examples/examples/z_pub_shm_thr.rs | 6 +++--- examples/examples/z_queryable_shm.rs | 6 +++--- io/zenoh-transport/tests/unicast_shm.rs | 6 +++--- zenoh/src/api/bytes.rs | 11 +++++------ zenoh/tests/bytes.rs | 4 ++-- zenoh/tests/shm.rs | 4 ++-- 16 files changed, 67 insertions(+), 50 deletions(-) diff --git a/commons/zenoh-core/src/lib.rs b/commons/zenoh-core/src/lib.rs index 37102d619d..719f3bedd1 100644 --- a/commons/zenoh-core/src/lib.rs +++ b/commons/zenoh-core/src/lib.rs @@ -31,7 +31,7 @@ pub use zresult::{Error, ZResult as Result}; /// A resolvable execution, either sync or async pub trait Resolvable { - type To: Sized + Send; + type To: Sized; } /// Trick used to mark `::IntoFuture` bound as Send diff --git a/commons/zenoh-shm/src/api/protocol_implementations/posix/posix_shm_provider_backend.rs b/commons/zenoh-shm/src/api/protocol_implementations/posix/posix_shm_provider_backend.rs index 663379e034..6212cbb310 100644 --- a/commons/zenoh-shm/src/api/protocol_implementations/posix/posix_shm_provider_backend.rs +++ b/commons/zenoh-shm/src/api/protocol_implementations/posix/posix_shm_provider_backend.rs @@ -23,7 +23,7 @@ use std::{ }, }; -use zenoh_core::zlock; +use zenoh_core::{zlock, Resolvable, Wait}; use zenoh_result::ZResult; use super::posix_shm_segment::PosixShmSegment; @@ -108,10 +108,14 @@ pub struct LayoutedPosixShmProviderBackendBuilder> layout: Layout, } -impl> LayoutedPosixShmProviderBackendBuilder { - /// try to create PosixShmProviderBackend - #[zenoh_macros::unstable_doc] - pub fn res(self) -> ZResult { +#[zenoh_macros::unstable_doc] +impl> Resolvable for LayoutedPosixShmProviderBackendBuilder { + type To = ZResult; +} + +#[zenoh_macros::unstable_doc] +impl> Wait for LayoutedPosixShmProviderBackendBuilder { + fn wait(self) -> ::To { PosixShmProviderBackend::new(self.layout.borrow()) } } diff --git a/commons/zenoh-shm/src/api/provider/shm_provider.rs b/commons/zenoh-shm/src/api/provider/shm_provider.rs index bab1588e0c..6276e39289 100644 --- a/commons/zenoh-shm/src/api/provider/shm_provider.rs +++ b/commons/zenoh-shm/src/api/provider/shm_provider.rs @@ -719,14 +719,23 @@ where backend: Backend, id: IDSource, } -impl ShmProviderBuilderBackendID +#[zenoh_macros::unstable_doc] +impl Resolvable for ShmProviderBuilderBackendID +where + IDSource: ProtocolIDSource, + Backend: ShmProviderBackend, +{ + type To = ShmProvider; +} + +#[zenoh_macros::unstable_doc] +impl Wait for ShmProviderBuilderBackendID where IDSource: ProtocolIDSource, Backend: ShmProviderBackend, { /// build ShmProvider - #[zenoh_macros::unstable_doc] - pub fn res(self) -> ShmProvider { + fn wait(self) -> ::To { ShmProvider::new(self.backend, self.id) } } diff --git a/commons/zenoh-shm/tests/posix_shm_provider.rs b/commons/zenoh-shm/tests/posix_shm_provider.rs index 60104be6cf..f0f7417340 100644 --- a/commons/zenoh-shm/tests/posix_shm_provider.rs +++ b/commons/zenoh-shm/tests/posix_shm_provider.rs @@ -12,6 +12,7 @@ // ZettaScale Zenoh Team, // +use zenoh_core::Wait; use zenoh_shm::api::{ client::shm_client::ShmClient, protocol_implementations::posix::{ @@ -31,7 +32,7 @@ fn posix_shm_provider_create() { let _backend = PosixShmProviderBackend::builder() .with_size(1024) .expect("Error creating Layout!") - .res() + .wait() .expect("Error creating PosixShmProviderBackend!"); } @@ -40,7 +41,7 @@ fn posix_shm_provider_alloc() { let backend = PosixShmProviderBackend::builder() .with_size(1024) .expect("Error creating Layout!") - .res() + .wait() .expect("Error creating PosixShmProviderBackend!"); let layout = MemoryLayout::new(100, AllocAlignment::default()).unwrap(); @@ -55,7 +56,7 @@ fn posix_shm_provider_open() { let backend = PosixShmProviderBackend::builder() .with_size(1024) .expect("Error creating Layout!") - .res() + .wait() .expect("Error creating PosixShmProviderBackend!"); let layout = MemoryLayout::new(100, AllocAlignment::default()).unwrap(); @@ -76,7 +77,7 @@ fn posix_shm_provider_allocator() { let backend = PosixShmProviderBackend::builder() .with_size(BUFFER_SIZE * BUFFER_NUM) .expect("Error creating Layout!") - .res() + .wait() .expect("Error creating PosixShmProviderBackend!"); let layout = MemoryLayout::new(BUFFER_SIZE, AllocAlignment::default()).unwrap(); diff --git a/examples/examples/z_alloc_shm.rs b/examples/examples/z_alloc_shm.rs index c955319e27..1f2f544a25 100644 --- a/examples/examples/z_alloc_shm.rs +++ b/examples/examples/z_alloc_shm.rs @@ -17,7 +17,7 @@ use zenoh::{ AllocAlignment, BlockOn, Deallocate, Defragment, GarbageCollect, PosixShmProviderBackend, ShmProviderBuilder, POSIX_PROTOCOL_ID, }, - Config, + Config, Wait, }; #[tokio::main] @@ -33,13 +33,13 @@ async fn run() -> ZResult<()> { let backend = PosixShmProviderBackend::builder() .with_size(65536) .unwrap() - .res() + .wait() .unwrap(); // ...and an SHM provider let provider = ShmProviderBuilder::builder() .protocol_id::() .backend(backend) - .res(); + .wait(); // There are two API-defined ways of making shm buffer allocations: direct and through the layout... diff --git a/examples/examples/z_bytes_shm.rs b/examples/examples/z_bytes_shm.rs index c30710214a..6ae69407d0 100644 --- a/examples/examples/z_bytes_shm.rs +++ b/examples/examples/z_bytes_shm.rs @@ -26,13 +26,13 @@ fn main() { let backend = PosixShmProviderBackend::builder() .with_size(4096) .unwrap() - .res() + .wait() .unwrap(); // ...and an SHM provider let provider = ShmProviderBuilder::builder() .protocol_id::() .backend(backend) - .res(); + .wait(); // Allocate an SHM buffer // NOTE: For allocation API please check z_alloc_shm.rs example diff --git a/examples/examples/z_get_shm.rs b/examples/examples/z_get_shm.rs index a3d8a22931..5c4a4f17fe 100644 --- a/examples/examples/z_get_shm.rs +++ b/examples/examples/z_get_shm.rs @@ -20,7 +20,7 @@ use zenoh::{ zshm, BlockOn, GarbageCollect, PosixShmProviderBackend, ShmProviderBuilder, POSIX_PROTOCOL_ID, }, - Config, + Config, Wait, }; use zenoh_examples::CommonArgs; @@ -42,13 +42,13 @@ async fn main() { let backend = PosixShmProviderBackend::builder() .with_size(N * 1024) .unwrap() - .res() + .wait() .unwrap(); // ...and an SHM provider let provider = ShmProviderBuilder::builder() .protocol_id::() .backend(backend) - .res(); + .wait(); // Allocate an SHM buffer // NOTE: For allocation API please check z_alloc_shm.rs example diff --git a/examples/examples/z_ping_shm.rs b/examples/examples/z_ping_shm.rs index bc948af4d0..3f0434e905 100644 --- a/examples/examples/z_ping_shm.rs +++ b/examples/examples/z_ping_shm.rs @@ -20,7 +20,7 @@ use zenoh::{ prelude::*, qos::CongestionControl, shm::{PosixShmProviderBackend, ShmProviderBuilder, POSIX_PROTOCOL_ID}, - Config, + Config, Wait, }; use zenoh_examples::CommonArgs; @@ -52,13 +52,13 @@ fn main() { let backend = PosixShmProviderBackend::builder() .with_size(size) .unwrap() - .res() + .wait() .unwrap(); // ...and an SHM provider let provider = ShmProviderBuilder::builder() .protocol_id::() .backend(backend) - .res(); + .wait(); // Allocate an SHM buffer // NOTE: For allocation API please check z_alloc_shm.rs example diff --git a/examples/examples/z_posix_shm_provider.rs b/examples/examples/z_posix_shm_provider.rs index 7c68d56bd3..ec7052f679 100644 --- a/examples/examples/z_posix_shm_provider.rs +++ b/examples/examples/z_posix_shm_provider.rs @@ -11,8 +11,12 @@ // Contributors: // ZettaScale Zenoh Team, // -use zenoh::shm::{ - AllocAlignment, MemoryLayout, PosixShmProviderBackend, ShmProviderBuilder, POSIX_PROTOCOL_ID, +use zenoh::{ + shm::{ + AllocAlignment, MemoryLayout, PosixShmProviderBackend, ShmProviderBuilder, + POSIX_PROTOCOL_ID, + }, + Wait, }; fn main() { @@ -34,7 +38,7 @@ fn main() { // Build a provider backend PosixShmProviderBackend::builder() .with_layout(provider_layout) - .res() + .wait() .unwrap() }; @@ -42,5 +46,5 @@ fn main() { let _shm_provider = ShmProviderBuilder::builder() .protocol_id::() .backend(backend) - .res(); + .wait(); } diff --git a/examples/examples/z_pub_shm.rs b/examples/examples/z_pub_shm.rs index 1fe89f9cf8..9c6311f59d 100644 --- a/examples/examples/z_pub_shm.rs +++ b/examples/examples/z_pub_shm.rs @@ -18,7 +18,7 @@ use zenoh::{ shm::{ BlockOn, GarbageCollect, PosixShmProviderBackend, ShmProviderBuilder, POSIX_PROTOCOL_ID, }, - Config, + Config, Wait, }; use zenoh_examples::CommonArgs; @@ -40,13 +40,13 @@ async fn main() -> Result<(), ZError> { let backend = PosixShmProviderBackend::builder() .with_size(N * 1024) .unwrap() - .res() + .wait() .unwrap(); // ...and an SHM provider let provider = ShmProviderBuilder::builder() .protocol_id::() .backend(backend) - .res(); + .wait(); let publisher = session.declare_publisher(&path).await.unwrap(); diff --git a/examples/examples/z_pub_shm_thr.rs b/examples/examples/z_pub_shm_thr.rs index c3385c0b94..699b6df341 100644 --- a/examples/examples/z_pub_shm_thr.rs +++ b/examples/examples/z_pub_shm_thr.rs @@ -17,7 +17,7 @@ use zenoh::{ prelude::*, qos::CongestionControl, shm::{PosixShmProviderBackend, ShmProviderBuilder, POSIX_PROTOCOL_ID}, - Config, + Config, Wait, }; use zenoh_examples::CommonArgs; @@ -34,13 +34,13 @@ async fn main() { let backend = PosixShmProviderBackend::builder() .with_size(sm_size) .unwrap() - .res() + .wait() .unwrap(); // ...and an SHM provider let provider = ShmProviderBuilder::builder() .protocol_id::() .backend(backend) - .res(); + .wait(); // Allocate an SHM buffer // NOTE: For allocation API please check z_alloc_shm.rs example diff --git a/examples/examples/z_queryable_shm.rs b/examples/examples/z_queryable_shm.rs index f1c65e51bf..a515671197 100644 --- a/examples/examples/z_queryable_shm.rs +++ b/examples/examples/z_queryable_shm.rs @@ -20,7 +20,7 @@ use zenoh::{ zshm, BlockOn, GarbageCollect, PosixShmProviderBackend, ShmProviderBuilder, POSIX_PROTOCOL_ID, }, - Config, + Config, Wait, }; use zenoh_examples::CommonArgs; @@ -42,13 +42,13 @@ async fn main() { let backend = PosixShmProviderBackend::builder() .with_size(N * 1024) .unwrap() - .res() + .wait() .unwrap(); // ...and an SHM provider let provider = ShmProviderBuilder::builder() .protocol_id::() .backend(backend) - .res(); + .wait(); println!("Declaring Queryable on '{key_expr}'..."); let queryable = session diff --git a/io/zenoh-transport/tests/unicast_shm.rs b/io/zenoh-transport/tests/unicast_shm.rs index 3310046736..db5f719665 100644 --- a/io/zenoh-transport/tests/unicast_shm.rs +++ b/io/zenoh-transport/tests/unicast_shm.rs @@ -24,7 +24,7 @@ mod tests { }; use zenoh_buffers::buffer::SplitBuffer; - use zenoh_core::ztimeout; + use zenoh_core::{ztimeout, Wait}; use zenoh_link::Link; use zenoh_protocol::{ core::{CongestionControl, Encoding, EndPoint, Priority, WhatAmI, ZenohIdProto}, @@ -161,12 +161,12 @@ mod tests { let backend = PosixShmProviderBackend::builder() .with_size(2 * MSG_SIZE) .unwrap() - .res() + .wait() .unwrap(); let shm01 = ShmProviderBuilder::builder() .protocol_id::() .backend(backend) - .res(); + .wait(); // Create a peer manager with shared-memory authenticator enabled let peer_shm01_handler = Arc::new(SHPeer::new(true)); diff --git a/zenoh/src/api/bytes.rs b/zenoh/src/api/bytes.rs index d8004bbcf0..3e00f0af61 100644 --- a/zenoh/src/api/bytes.rs +++ b/zenoh/src/api/bytes.rs @@ -3259,12 +3259,11 @@ mod tests { #[test] fn serializer() { - use std::borrow::Cow; - + #[cfg(feature = "shared-memory")] + use crate::zenoh_core::Wait; use rand::Rng; + use std::borrow::Cow; use zenoh_buffers::{ZBuf, ZSlice}; - #[cfg(feature = "shared-memory")] - use zenoh_core::Wait; use zenoh_protocol::core::Parameters; #[cfg(feature = "shared-memory")] use zenoh_shm::api::{ @@ -3439,13 +3438,13 @@ mod tests { let backend = PosixShmProviderBackend::builder() .with_size(4096) .unwrap() - .res() + .wait() .unwrap(); // ...and an SHM provider let provider = ShmProviderBuilder::builder() .protocol_id::() .backend(backend) - .res(); + .wait(); // Prepare a layout for allocations let layout = provider.alloc(1024).into_layout().unwrap(); diff --git a/zenoh/tests/bytes.rs b/zenoh/tests/bytes.rs index 34c9837d04..a8c9c7f17a 100644 --- a/zenoh/tests/bytes.rs +++ b/zenoh/tests/bytes.rs @@ -27,13 +27,13 @@ fn shm_bytes_single_buf() { let backend = PosixShmProviderBackend::builder() .with_size(4096) .unwrap() - .res() + .wait() .unwrap(); // ...and an SHM provider let provider = ShmProviderBuilder::builder() .protocol_id::() .backend(backend) - .res(); + .wait(); // Prepare a layout for allocations let layout = provider.alloc(1024).into_layout().unwrap(); diff --git a/zenoh/tests/shm.rs b/zenoh/tests/shm.rs index 3d5e785e1b..7b0c3aaaba 100644 --- a/zenoh/tests/shm.rs +++ b/zenoh/tests/shm.rs @@ -137,13 +137,13 @@ async fn test_session_pubsub(peer01: &Session, peer02: &Session, reliability: Re let backend = PosixShmProviderBackend::builder() .with_size(size * MSG_COUNT / 10) .unwrap() - .res() + .wait() .unwrap(); // ...and SHM provider let shm01 = ShmProviderBuilder::builder() .protocol_id::() .backend(backend) - .res(); + .wait(); // remember segment size that was allocated let shm_segment_size = shm01.available();