From 2688a6b92b306a9a255854c64d2f00b41b11c910 Mon Sep 17 00:00:00 2001 From: yellowhatter Date: Tue, 28 May 2024 17:05:10 +0300 Subject: [PATCH] async allocation API --- Cargo.lock | 54 +++++++-------- Cargo.toml | 8 +-- Cargo.toml.in | 8 +-- NOTICE.md | 2 +- build-resources/opaque-types/Cargo.lock | 42 ++++++------ build-resources/opaque-types/Cargo.toml | 4 +- include/zenoh_commons.h | 50 ++++++++------ src/shm/provider/alloc_layout.rs | 36 ++++------ src/shm/provider/alloc_layout_impl.rs | 68 ++++++++++++++++++- src/shm/provider/shared_memory_provider.rs | 9 +-- .../provider/shared_memory_provider_impl.rs | 33 ++++----- 11 files changed, 183 insertions(+), 131 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 18487c169..8d42252b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3352,7 +3352,7 @@ dependencies = [ [[package]] name = "zenoh" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "ahash", "async-trait", @@ -3408,7 +3408,7 @@ dependencies = [ [[package]] name = "zenoh-buffers" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "zenoh-collections", ] @@ -3444,7 +3444,7 @@ dependencies = [ [[package]] name = "zenoh-codec" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "serde", "tracing", @@ -3457,12 +3457,12 @@ dependencies = [ [[package]] name = "zenoh-collections" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" [[package]] name = "zenoh-config" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "flume", "json5", @@ -3482,7 +3482,7 @@ dependencies = [ [[package]] name = "zenoh-core" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "async-global-executor", "lazy_static", @@ -3494,7 +3494,7 @@ dependencies = [ [[package]] name = "zenoh-crypto" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "aes", "hmac", @@ -3507,7 +3507,7 @@ dependencies = [ [[package]] name = "zenoh-ext" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "bincode", "flume", @@ -3526,7 +3526,7 @@ dependencies = [ [[package]] name = "zenoh-keyexpr" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "hashbrown 0.14.5", "keyed-set", @@ -3540,7 +3540,7 @@ dependencies = [ [[package]] name = "zenoh-link" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "async-trait", "zenoh-config", @@ -3558,7 +3558,7 @@ dependencies = [ [[package]] name = "zenoh-link-commons" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "async-trait", "flume", @@ -3582,7 +3582,7 @@ dependencies = [ [[package]] name = "zenoh-link-quic" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "async-trait", "base64 0.21.7", @@ -3613,7 +3613,7 @@ dependencies = [ [[package]] name = "zenoh-link-tcp" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "async-trait", "tokio", @@ -3631,7 +3631,7 @@ dependencies = [ [[package]] name = "zenoh-link-tls" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "async-trait", "base64 0.21.7", @@ -3660,7 +3660,7 @@ dependencies = [ [[package]] name = "zenoh-link-udp" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "async-trait", "socket2 0.5.7", @@ -3681,7 +3681,7 @@ dependencies = [ [[package]] name = "zenoh-link-unixsock_stream" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "async-trait", "futures", @@ -3701,7 +3701,7 @@ dependencies = [ [[package]] name = "zenoh-link-ws" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "async-trait", "futures-util", @@ -3722,7 +3722,7 @@ dependencies = [ [[package]] name = "zenoh-macros" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "proc-macro2", "quote", @@ -3733,7 +3733,7 @@ dependencies = [ [[package]] name = "zenoh-plugin-trait" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "const_format", "libloading", @@ -3749,7 +3749,7 @@ dependencies = [ [[package]] name = "zenoh-protocol" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "const_format", "rand", @@ -3764,7 +3764,7 @@ dependencies = [ [[package]] name = "zenoh-result" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "anyhow", ] @@ -3772,7 +3772,7 @@ dependencies = [ [[package]] name = "zenoh-runtime" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "futures", "lazy_static", @@ -3787,7 +3787,7 @@ dependencies = [ [[package]] name = "zenoh-shm" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "async-trait", "bincode", @@ -3811,7 +3811,7 @@ dependencies = [ [[package]] name = "zenoh-sync" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "event-listener 4.0.3", "futures", @@ -3825,7 +3825,7 @@ dependencies = [ [[package]] name = "zenoh-task" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "futures", "tokio", @@ -3838,7 +3838,7 @@ dependencies = [ [[package]] name = "zenoh-transport" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "async-trait", "flume", @@ -3871,7 +3871,7 @@ dependencies = [ [[package]] name = "zenoh-util" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "async-std", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 72ca2499f..4784d519e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,10 +54,10 @@ spin = "0.9.5" unwrap-infallible = "0.1.5" const_format = "0.2.32" # shared-memory enabled for zenoh even if zenoh-c "shared-memory" feature is disabled. This is to make "std::mem::transmute" work for `ZSLice` -zenoh = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "dev/1.0.0", features = ["shared-memory", "unstable"], default-features = false } -zenoh-protocol = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "dev/1.0.0", features = ["shared-memory"] } -zenoh-util = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "dev/1.0.0" } -zenoh-ext = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "dev/1.0.0", features = ["unstable"] } +zenoh = { version = "0.11.0-dev", git = "https://github.com/ZettaScaleLabs/zenoh.git", branch = "fix_shm_async_api", features = ["shared-memory", "unstable"], default-features = false } +zenoh-protocol = { version = "0.11.0-dev", git = "https://github.com/ZettaScaleLabs/zenoh.git", branch = "fix_shm_async_api", features = ["shared-memory"] } +zenoh-util = { version = "0.11.0-dev", git = "https://github.com/ZettaScaleLabs/zenoh.git", branch = "fix_shm_async_api" } +zenoh-ext = { version = "0.11.0-dev", git = "https://github.com/ZettaScaleLabs/zenoh.git", branch = "fix_shm_async_api", features = ["unstable"] } [build-dependencies] diff --git a/Cargo.toml.in b/Cargo.toml.in index a980ee4d7..934bbad88 100644 --- a/Cargo.toml.in +++ b/Cargo.toml.in @@ -54,10 +54,10 @@ spin = "0.9.5" unwrap-infallible = "0.1.5" const_format = "0.2.32" # shared-memory enabled for zenoh even if zenoh-c "shared-memory" feature is disabled. This is to make "std::mem::transmute" work for `ZSLice` -zenoh = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "dev/1.0.0", features = ["shared-memory", "unstable"], default-features = false } -zenoh-protocol = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "dev/1.0.0", features = ["shared-memory"] } -zenoh-util = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "dev/1.0.0" } -zenoh-ext = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "dev/1.0.0", features = ["unstable"] } +zenoh = { version = "0.11.0-dev", git = "https://github.com/ZettaScaleLabs/zenoh.git", branch = "fix_shm_async_api", features = ["shared-memory", "unstable"], default-features = false } +zenoh-protocol = { version = "0.11.0-dev", git = "https://github.com/ZettaScaleLabs/zenoh.git", branch = "fix_shm_async_api", features = ["shared-memory"] } +zenoh-util = { version = "0.11.0-dev", git = "https://github.com/ZettaScaleLabs/zenoh.git", branch = "fix_shm_async_api" } +zenoh-ext = { version = "0.11.0-dev", git = "https://github.com/ZettaScaleLabs/zenoh.git", branch = "fix_shm_async_api", features = ["unstable"] } [build-dependencies] diff --git a/NOTICE.md b/NOTICE.md index 819ce8ae2..d3c09d72a 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -28,7 +28,7 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 The project maintains the following source code repositories: - * https://github.com/eclipse-zenoh/zenoh.git + * https://github.com/ZettaScaleLabs/zenoh.git * https://github.com/eclipse-zenoh/zenoh-c.git * https://github.com/eclipse-zenoh/zenoh-java.git * https://github.com/eclipse-zenoh/zenoh-go.git diff --git a/build-resources/opaque-types/Cargo.lock b/build-resources/opaque-types/Cargo.lock index a8e264bfe..758f43985 100644 --- a/build-resources/opaque-types/Cargo.lock +++ b/build-resources/opaque-types/Cargo.lock @@ -2606,7 +2606,7 @@ dependencies = [ [[package]] name = "zenoh" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "ahash", "async-trait", @@ -2662,7 +2662,7 @@ dependencies = [ [[package]] name = "zenoh-buffers" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "zenoh-collections", ] @@ -2670,7 +2670,7 @@ dependencies = [ [[package]] name = "zenoh-codec" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "serde", "tracing", @@ -2683,12 +2683,12 @@ dependencies = [ [[package]] name = "zenoh-collections" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" [[package]] name = "zenoh-config" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "flume", "json5", @@ -2708,7 +2708,7 @@ dependencies = [ [[package]] name = "zenoh-core" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "async-global-executor", "lazy_static", @@ -2720,7 +2720,7 @@ dependencies = [ [[package]] name = "zenoh-crypto" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "aes", "hmac", @@ -2733,7 +2733,7 @@ dependencies = [ [[package]] name = "zenoh-ext" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "bincode", "flume", @@ -2752,7 +2752,7 @@ dependencies = [ [[package]] name = "zenoh-keyexpr" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "hashbrown 0.14.3", "keyed-set", @@ -2766,7 +2766,7 @@ dependencies = [ [[package]] name = "zenoh-link" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "async-trait", "zenoh-config", @@ -2778,7 +2778,7 @@ dependencies = [ [[package]] name = "zenoh-link-commons" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "async-trait", "flume", @@ -2802,7 +2802,7 @@ dependencies = [ [[package]] name = "zenoh-macros" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "proc-macro2", "quote", @@ -2813,7 +2813,7 @@ dependencies = [ [[package]] name = "zenoh-plugin-trait" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "const_format", "libloading", @@ -2829,7 +2829,7 @@ dependencies = [ [[package]] name = "zenoh-protocol" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "const_format", "rand", @@ -2844,7 +2844,7 @@ dependencies = [ [[package]] name = "zenoh-result" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "anyhow", ] @@ -2852,7 +2852,7 @@ dependencies = [ [[package]] name = "zenoh-runtime" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "futures", "lazy_static", @@ -2867,7 +2867,7 @@ dependencies = [ [[package]] name = "zenoh-shm" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "async-trait", "bincode", @@ -2891,7 +2891,7 @@ dependencies = [ [[package]] name = "zenoh-sync" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "event-listener 4.0.3", "futures", @@ -2905,7 +2905,7 @@ dependencies = [ [[package]] name = "zenoh-task" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "futures", "tokio", @@ -2918,7 +2918,7 @@ dependencies = [ [[package]] name = "zenoh-transport" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "async-trait", "flume", @@ -2950,7 +2950,7 @@ dependencies = [ [[package]] name = "zenoh-util" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=dev/1.0.0#61743569cf9cd79d9840ae9a82b1ee63f16edcbe" +source = "git+https://github.com/ZettaScaleLabs/zenoh.git?branch=fix_shm_async_api#2bcfe1fbc148bf5a7f88b88d2d9667f2eb1e986b" dependencies = [ "async-std", "async-trait", diff --git a/build-resources/opaque-types/Cargo.toml b/build-resources/opaque-types/Cargo.toml index 4df34126d..65e26f35e 100644 --- a/build-resources/opaque-types/Cargo.toml +++ b/build-resources/opaque-types/Cargo.toml @@ -7,6 +7,6 @@ edition = "2021" [dependencies] # shared-memory enabled for zenoh even if zenoh-c "shared-memory" feature is disabled. This is to make "std::mem::transmute" work for `ZSLice` -zenoh = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "dev/1.0.0", features = ["shared-memory", "unstable"], default-features = false } -zenoh-ext = { version = "0.11.0-dev", git = "https://github.com/eclipse-zenoh/zenoh.git", branch = "dev/1.0.0", features = ["unstable"] } +zenoh = { version = "0.11.0-dev", git = "https://github.com/ZettaScaleLabs/zenoh.git", branch = "fix_shm_async_api", features = ["shared-memory", "unstable"], default-features = false } +zenoh-ext = { version = "0.11.0-dev", git = "https://github.com/ZettaScaleLabs/zenoh.git", branch = "fix_shm_async_api", features = ["unstable"] } const_format = "0.2.32" diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index 8c83dd90e..d0e18f764 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -261,6 +261,28 @@ typedef struct ALIGN(8) z_loaned_shared_memory_provider_t { typedef struct z_alloc_alignment_t { uint8_t pow; } z_alloc_alignment_t; +typedef struct zc_threadsafe_context_data_t { + void *ptr; +} zc_threadsafe_context_data_t; +/** + * A tread-safe droppable context. + * Contexts are idiomatically used in C together with callback interfaces to deliver associated state + * information to each callback. + * + * This is a thread-safe context - the associated callbacks may be executed concurrently with the same + * zc_context_t instance. In other words, all the callbacks associated with this context data MUST be + * thread-safe. + * + * Once moved to zenoh-c ownership, this context is guaranteed to execute delete_fn when deleted.The + * delete_fn is guaranteed to be executed only once at some point of time after the last associated + * callback call returns. + * NOTE: if user doesn't pass the instance of this context to zenoh-c, the delete_fn callback won't + * be executed. + */ +typedef struct zc_threadsafe_context_t { + struct zc_threadsafe_context_data_t context; + void (*delete_fn)(void*); +} zc_threadsafe_context_t; /** * A loaned BufAllocResult */ @@ -1051,28 +1073,6 @@ typedef struct z_scout_options_t { */ enum z_whatami_t zc_what; } z_scout_options_t; -typedef struct zc_threadsafe_context_data_t { - void *ptr; -} zc_threadsafe_context_data_t; -/** - * A tread-safe droppable context. - * Contexts are idiomatically used in C together with callback interfaces to deliver associated state - * information to each callback. - * - * This is a thread-safe context - the associated callbacks may be executed concurrently with the same - * zc_context_t instance. In other words, all the callbacks associated with this context data MUST be - * thread-safe. - * - * Once moved to zenoh-c ownership, this context is guaranteed to execute delete_fn when deleted.The - * delete_fn is guaranteed to be executed only once at some point of time after the last associated - * callback call returns. - * NOTE: if user doesn't pass the instance of this context to zenoh-c, the delete_fn callback won't - * be executed. - */ -typedef struct zc_threadsafe_context_t { - struct zc_threadsafe_context_data_t context; - void (*delete_fn)(void*); -} zc_threadsafe_context_t; /** * A callbacks for SharedMemorySegment */ @@ -1394,6 +1394,12 @@ z_error_t z_alloc_layout_new(struct z_owned_alloc_layout_t *this_, * Constructs Alloc Layout in its gravestone value. */ ZENOHC_API void z_alloc_layout_null(struct z_owned_alloc_layout_t *this_); +ZENOHC_API +z_error_t z_alloc_layout_threadsafe_alloc_gc_defrag_async(struct z_owned_buf_alloc_result_t *out_result, + const struct z_loaned_alloc_layout_t *layout, + struct zc_threadsafe_context_t result_context, + void (*result_callback)(void*, + struct z_owned_buf_alloc_result_t*)); /** * Returns ``true`` if `this` is valid. */ diff --git a/src/shm/provider/alloc_layout.rs b/src/shm/provider/alloc_layout.rs index 2ba39fbcd..53287a377 100644 --- a/src/shm/provider/alloc_layout.rs +++ b/src/shm/provider/alloc_layout.rs @@ -15,7 +15,7 @@ use std::mem::MaybeUninit; use crate::{ - context::ThreadsafeContext, + context::{zc_threadsafe_context_t, ThreadsafeContext}, errors::z_error_t, shm::protocol_implementations::posix::posix_shared_memory_provider::PosixAllocLayout, transmute::{ @@ -23,6 +23,7 @@ use crate::{ }, z_owned_buf_alloc_result_t, }; +use libc::c_void; use zenoh::shm::{ AllocLayout, BlockOn, Deallocate, Defragment, DynamicProtocolID, GarbageCollect, JustAlloc, }; @@ -30,7 +31,7 @@ use zenoh::shm::{ use crate::context::Context; use super::{ - alloc_layout_impl::{alloc, alloc_layout_new}, + alloc_layout_impl::{alloc, alloc_async, alloc_layout_new}, shared_memory_provider::z_loaned_shared_memory_provider_t, shared_memory_provider_backend::DynamicSharedMemoryProviderBackend, types::z_alloc_alignment_t, @@ -155,33 +156,20 @@ pub extern "C" fn z_alloc_layout_alloc_gc_defrag_blocking( alloc::>>(out_result, layout); } -/* #[no_mangle] pub extern "C" fn z_alloc_layout_threadsafe_alloc_gc_defrag_async( - out_result: &mut MaybeUninit, - layout: &'static z_loaned_alloc_layout_threadsafe_t, + out_result: &'static mut MaybeUninit, + layout: &'static z_loaned_alloc_layout_t, result_context: zc_threadsafe_context_t, result_callback: unsafe extern "C" fn( *mut c_void, &mut MaybeUninit, ), -) { - let layout = layout.transmute_ref(); - let a = layout - .alloc() - .with_policy::>>(); - - let result_context: ThreadsafeContext = result_context.into(); - //todo: this should be ported to tokio with executor argument support - async_std::task::spawn(async move { - let result = a.await; - - Inplace::init( - (out_result as *mut MaybeUninit).transmute_uninit_ptr(), - Some(result), - ); - - (result_callback)(result_context.get(), out_result); - }); +) -> z_error_t { + alloc_async::>>( + out_result, + layout, + result_context, + result_callback, + ) } -*/ diff --git a/src/shm/provider/alloc_layout_impl.rs b/src/shm/provider/alloc_layout_impl.rs index 7e395a538..bf10806e5 100644 --- a/src/shm/provider/alloc_layout_impl.rs +++ b/src/shm/provider/alloc_layout_impl.rs @@ -14,14 +14,23 @@ use std::mem::MaybeUninit; +use libc::c_void; use zenoh::prelude::*; use zenoh::shm::AllocPolicy; use crate::{ - errors::{z_error_t, Z_EINVAL, Z_OK}, transmute::{Inplace, TransmuteCopy, TransmuteFromHandle, TransmuteUninitPtr}, z_owned_buf_alloc_result_t + context::{zc_threadsafe_context_t, DroppableContext, ThreadsafeContext}, + errors::{z_error_t, Z_EINVAL, Z_OK}, + transmute::{Inplace, TransmuteCopy, TransmuteFromHandle, TransmuteUninitPtr}, + z_owned_buf_alloc_result_t, }; -use super::{alloc_layout::{z_loaned_alloc_layout_t, z_owned_alloc_layout_t, CSHMLayout}, shared_memory_provider::z_loaned_shared_memory_provider_t, types::z_alloc_alignment_t}; +use super::{ + alloc_layout::{z_loaned_alloc_layout_t, z_owned_alloc_layout_t, CSHMLayout}, + shared_memory_provider::z_loaned_shared_memory_provider_t, + shared_memory_provider_backend::DynamicSharedMemoryProviderBackend, + types::z_alloc_alignment_t, +}; pub(crate) fn alloc_layout_new( this: *mut MaybeUninit, @@ -92,3 +101,58 @@ pub(crate) fn alloc( }; Inplace::init(out_result.transmute_uninit_ptr(), Some(result)); } + +pub(crate) fn alloc_async( + out_result: &'static mut MaybeUninit, + layout: &'static z_loaned_alloc_layout_t, + result_context: zc_threadsafe_context_t, + result_callback: unsafe extern "C" fn( + *mut c_void, + &mut MaybeUninit, + ), +) -> z_error_t { + match layout.transmute_ref() { + super::alloc_layout::CSHMLayout::Posix(layout) => { + alloc_async_impl::< + Policy, + StaticProtocolID, + PosixSharedMemoryProviderBackend, + >(out_result, layout, result_context, result_callback); + Z_OK + } + super::alloc_layout::CSHMLayout::Dynamic(_) => Z_EINVAL, + super::alloc_layout::CSHMLayout::DynamicThreadsafe(layout) => { + alloc_async_impl::< + Policy, + DynamicProtocolID, + DynamicSharedMemoryProviderBackend, + >(out_result, layout, result_context, result_callback); + Z_OK + } + } +} + +pub fn alloc_async_impl< + Policy: AsyncAllocPolicy, + IDSource: ProtocolIDSource, + Backend: SharedMemoryProviderBackend + Send + Sync, +>( + out_result: &'static mut MaybeUninit, + layout: &'static AllocLayout<'static, IDSource, Backend>, + result_context: zc_threadsafe_context_t, + result_callback: unsafe extern "C" fn( + *mut c_void, + &mut MaybeUninit, + ), +) { + let result_context: ThreadsafeContext = result_context.into(); + //todo: this should be ported to tokio with executor argument support + async_std::task::spawn(async move { + let result = layout.alloc().with_policy::().await; + Inplace::init( + (out_result as *mut MaybeUninit).transmute_uninit_ptr(), + Some(result), + ); + unsafe { (result_callback)(result_context.get(), out_result) }; + }); +} diff --git a/src/shm/provider/shared_memory_provider.rs b/src/shm/provider/shared_memory_provider.rs index 85380127d..9d7bf0d65 100644 --- a/src/shm/provider/shared_memory_provider.rs +++ b/src/shm/provider/shared_memory_provider.rs @@ -12,7 +12,7 @@ // ZettaScale Zenoh Team, // -use std::{mem::MaybeUninit, sync::atomic::AtomicPtr}; +use std::mem::MaybeUninit; use libc::c_void; use zenoh::shm::{ @@ -38,7 +38,9 @@ use super::{ shared_memory_provider_backend::{ zc_shared_memory_provider_backend_callbacks_t, DynamicSharedMemoryProviderBackend, }, - shared_memory_provider_impl::{alloc, alloc_async, available, defragment, garbage_collect, map}, + shared_memory_provider_impl::{ + alloc, alloc_async, available, defragment, garbage_collect, map, + }, types::z_alloc_alignment_t, }; @@ -212,7 +214,7 @@ pub extern "C" fn z_shared_memory_provider_alloc_gc_defrag_blocking( #[no_mangle] pub extern "C" fn z_shared_memory_provider_alloc_gc_defrag_async( - out_result: *mut MaybeUninit, + out_result: &'static mut MaybeUninit, provider: &'static z_loaned_shared_memory_provider_t, size: usize, alignment: z_alloc_alignment_t, @@ -223,7 +225,6 @@ pub extern "C" fn z_shared_memory_provider_alloc_gc_defrag_async( *mut MaybeUninit, ), ) -> z_error_t { - let out_result = AtomicPtr::new(out_result); alloc_async::>>( out_result, provider, diff --git a/src/shm/provider/shared_memory_provider_impl.rs b/src/shm/provider/shared_memory_provider_impl.rs index e872110d6..fde99f889 100644 --- a/src/shm/provider/shared_memory_provider_impl.rs +++ b/src/shm/provider/shared_memory_provider_impl.rs @@ -14,7 +14,6 @@ use libc::c_void; use std::mem::MaybeUninit; -use std::sync::atomic::AtomicPtr; use zenoh::prelude::*; use zenoh::shm::{AllocPolicy, AsyncAllocPolicy, SharedMemoryProvider}; @@ -58,7 +57,7 @@ pub(crate) fn alloc( } pub(crate) fn alloc_async( - out_result: AtomicPtr>, + out_result: &'static mut MaybeUninit, provider: &'static z_loaned_shared_memory_provider_t, size: usize, alignment: z_alloc_alignment_t, @@ -134,12 +133,8 @@ pub(crate) fn garbage_collect(provider: &z_loaned_shared_memory_provider_t) { pub(crate) fn available(provider: &z_loaned_shared_memory_provider_t) -> usize { match provider.transmute_ref() { - super::shared_memory_provider::CSHMProvider::Posix(provider) => { - provider.available() - } - super::shared_memory_provider::CSHMProvider::Dynamic(provider) => { - provider.available() - } + super::shared_memory_provider::CSHMProvider::Posix(provider) => provider.available(), + super::shared_memory_provider::CSHMProvider::Dynamic(provider) => provider.available(), super::shared_memory_provider::CSHMProvider::DynamicThreadsafe(provider) => { provider.available() } @@ -198,7 +193,7 @@ pub(crate) fn alloc_async_impl< TProtocolID: ProtocolIDSource, TBackend: SharedMemoryProviderBackend + Send + Sync, >( - out_result: AtomicPtr>, + out_result: &'static mut MaybeUninit, provider: &'static SharedMemoryProvider, size: usize, alignment: z_alloc_alignment_t, @@ -211,17 +206,15 @@ pub(crate) fn alloc_async_impl< ) { //todo: this should be ported to tokio with executor argument support async_std::task::spawn(async move { - // todo: fix compilation error! - - //let result = provider - // .alloc(size) - // .with_alignment(alignment.into()) - // .with_policy::() - // .await; - // - //let error = parse_result(out_result.into_inner(), result); - // - //unsafe { (result_callback)(result_context.get(), error, out_result.into_inner()); } + let result = provider + .alloc(size) + .with_alignment(alignment.transmute_copy()) + .with_policy::() + .await; + let error = parse_result(out_result, result); + unsafe { + (result_callback)(result_context.get(), error, out_result); + } }); }