From 02b8a9b3c3b0237bd351869bc25afe2bc5bd3d49 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Mon, 26 Feb 2024 10:52:37 +0100 Subject: [PATCH 01/18] support for sleep api --- examples/z_liveliness.c | 8 +---- examples/z_pub.c | 8 +---- examples/z_pub_attachment.c | 8 +---- examples/z_pub_cache.c | 8 +---- examples/z_pub_shm.c | 8 +---- examples/z_pull.c | 8 +---- examples/z_query_sub.c | 8 +---- examples/z_queryable.c | 8 +---- examples/z_queryable_with_channels.c | 6 ---- examples/z_scout.c | 10 +----- examples/z_sub.c | 8 +---- examples/z_sub_attachment.c | 8 +---- examples/z_sub_liveliness.c | 8 +---- include/zenoh_commons.h | 3 ++ src/platform/mod.rs | 4 ++- src/platform/sleep.rs | 19 ++++++++++ tests/z_api_alignment_test.c | 48 +++++++++++-------------- tests/z_int_pub_cache_query_sub_test.c | 2 +- tests/z_int_pub_sub_attachment_test.c | 2 +- tests/z_int_queryable_attachment_test.c | 2 +- tests/z_int_queryable_test.c | 2 +- 21 files changed, 61 insertions(+), 125 deletions(-) create mode 100644 src/platform/sleep.rs diff --git a/examples/z_liveliness.c b/examples/z_liveliness.c index b21cc40bc..29dc51892 100644 --- a/examples/z_liveliness.c +++ b/examples/z_liveliness.c @@ -13,12 +13,6 @@ #include #include -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) -#include -#define sleep(x) Sleep(x * 1000) -#else -#include -#endif #include "zenoh.h" int main(int argc, char **argv) { @@ -63,7 +57,7 @@ int main(int argc, char **argv) { while (c != 'q') { c = getchar(); if (c == -1) { - sleep(1); + zp_sleep_s(1); } else if (c == 'd') { printf("Undeclaring liveliness token...\n"); z_drop(z_move(token)); diff --git a/examples/z_pub.c b/examples/z_pub.c index 73fd02287..1f0d7476b 100644 --- a/examples/z_pub.c +++ b/examples/z_pub.c @@ -15,12 +15,6 @@ #include #include "zenoh.h" -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) -#include -#define sleep(x) Sleep(x * 1000) -#else -#include -#endif void matching_status_handler(const zcu_matching_status_t *matching_status, void *arg) { if (matching_status->matching) { @@ -72,7 +66,7 @@ int main(int argc, char **argv) { char buf[256]; for (int idx = 0; 1; ++idx) { - sleep(1); + zp_sleep_s(1); sprintf(buf, "[%4d] %s", idx, value); printf("Putting Data ('%s': '%s')...\n", keyexpr, buf); z_publisher_put_options_t options = z_publisher_put_options_default(); diff --git a/examples/z_pub_attachment.c b/examples/z_pub_attachment.c index b75f245c3..877ad93be 100644 --- a/examples/z_pub_attachment.c +++ b/examples/z_pub_attachment.c @@ -15,12 +15,6 @@ #include #include "zenoh.h" -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) -#include -#define sleep(x) Sleep(x * 1000) -#else -#include -#endif int main(int argc, char **argv) { char *keyexpr = "demo/example/zenoh-c-pub"; @@ -69,7 +63,7 @@ int main(int argc, char **argv) { char buf[256]; char buf_ind[16]; for (int idx = 0; 1; ++idx) { - sleep(1); + zp_sleep_s(1); // add some other attachment value sprintf(buf_ind, "%d", idx); diff --git a/examples/z_pub_cache.c b/examples/z_pub_cache.c index 8c1d36221..6412ca7f1 100644 --- a/examples/z_pub_cache.c +++ b/examples/z_pub_cache.c @@ -15,12 +15,6 @@ #include #include "zenoh.h" -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) -#include -#define sleep(x) Sleep(x * 1000) -#else -#include -#endif int main(int argc, char **argv) { char *keyexpr = "demo/example/zenoh-c-pub"; @@ -66,7 +60,7 @@ int main(int argc, char **argv) { char buf[256]; for (int idx = 0; 1; ++idx) { - sleep(1); + zp_sleep_s(1); sprintf(buf, "[%4d] %s", idx, value); printf("Putting Data ('%s': '%s')...\n", keyexpr, buf); z_put(z_loan(s), z_keyexpr(keyexpr), (const uint8_t *)buf, strlen(buf), NULL); diff --git a/examples/z_pub_shm.c b/examples/z_pub_shm.c index f26c65c08..81856c49f 100644 --- a/examples/z_pub_shm.c +++ b/examples/z_pub_shm.c @@ -17,12 +17,6 @@ #include #include "zenoh.h" -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) -#include -#define sleep(x) Sleep(x * 1000) -#else -#include -#endif #define N 10 @@ -85,7 +79,7 @@ int main(int argc, char **argv) { snprintf(buf, 255, "[%4d] %s", idx, value); size_t len = strlen(buf); zc_shmbuf_set_length(&shmbuf, len); - sleep(1); + zp_sleep_s(1); printf("Putting Data ('%s': '%s')...\n", keyexpr, buf); z_publisher_put_options_t options = z_publisher_put_options_default(); options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL); diff --git a/examples/z_pull.c b/examples/z_pull.c index d7039e902..76d66d7fa 100644 --- a/examples/z_pull.c +++ b/examples/z_pull.c @@ -12,12 +12,6 @@ // ZettaScale Zenoh Team, // #include -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) -#include -#define sleep(x) Sleep(x * 1000) -#else -#include -#endif #include "zenoh.h" const char *kind_to_str(z_sample_kind_t kind); @@ -66,7 +60,7 @@ int main(int argc, char **argv) { while (c != 'q') { c = getchar(); if (c == -1) { - sleep(1); + zp_sleep_s(1); } else { z_subscriber_pull(z_loan(sub)); } diff --git a/examples/z_query_sub.c b/examples/z_query_sub.c index 680cfd973..7c2837345 100644 --- a/examples/z_query_sub.c +++ b/examples/z_query_sub.c @@ -12,12 +12,6 @@ // ZettaScale Zenoh Team, // #include -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) -#include -#define sleep(x) Sleep(x * 1000) -#else -#include -#endif #include "zenoh.h" const char *kind_to_str(z_sample_kind_t kind); @@ -68,7 +62,7 @@ int main(int argc, char **argv) { while (c != 'q') { c = getchar(); if (c == -1) { - sleep(1); + zp_sleep_s(1); } } diff --git a/examples/z_queryable.c b/examples/z_queryable.c index f74f5d355..32892412b 100644 --- a/examples/z_queryable.c +++ b/examples/z_queryable.c @@ -13,12 +13,6 @@ #include #include -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) -#include -#define sleep(x) Sleep(x * 1000) -#else -#include -#endif #include "zenoh.h" const char *expr = "demo/example/zenoh-c-queryable"; @@ -81,7 +75,7 @@ int main(int argc, char **argv) { while (c != 'q') { c = getchar(); if (c == -1) { - sleep(1); + zp_sleep_s(1); } } diff --git a/examples/z_queryable_with_channels.c b/examples/z_queryable_with_channels.c index 80c98d689..672ddd607 100644 --- a/examples/z_queryable_with_channels.c +++ b/examples/z_queryable_with_channels.c @@ -14,12 +14,6 @@ #include #include #include -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) -#include -#define sleep(x) Sleep(x * 1000) -#else -#include -#endif #include "zenoh.h" const char *expr = "demo/example/zenoh-c-queryable"; diff --git a/examples/z_scout.c b/examples/z_scout.c index ca5e8944b..f0201e41a 100644 --- a/examples/z_scout.c +++ b/examples/z_scout.c @@ -12,14 +12,6 @@ // ZettaScale Zenoh Team, #include - -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) -#include -#define sleep(x) Sleep(x * 1000) -#else -#include -#endif - #include "zenoh.h" void fprintpid(FILE *stream, z_id_t pid) { @@ -96,6 +88,6 @@ int main(int argc, char **argv) { z_owned_closure_hello_t closure = z_closure(callback, drop, context); printf("Scouting...\n"); z_scout(z_move(config), z_move(closure)); - sleep(1); + zp_sleep_s(1); return 0; } \ No newline at end of file diff --git a/examples/z_sub.c b/examples/z_sub.c index ccfb32825..1c22432d5 100644 --- a/examples/z_sub.c +++ b/examples/z_sub.c @@ -12,12 +12,6 @@ // ZettaScale Zenoh Team, // #include -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) -#include -#define sleep(x) Sleep(x * 1000) -#else -#include -#endif #include "zenoh.h" const char *kind_to_str(z_sample_kind_t kind); @@ -73,7 +67,7 @@ int main(int argc, char **argv) { while (c != 'q') { c = getchar(); if (c == -1) { - sleep(1); + zp_sleep_s(1); } } diff --git a/examples/z_sub_attachment.c b/examples/z_sub_attachment.c index 26cc95ed8..a7f2308c6 100644 --- a/examples/z_sub_attachment.c +++ b/examples/z_sub_attachment.c @@ -13,12 +13,6 @@ // #include #include -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) -#include -#define sleep(x) Sleep(x * 1000) -#else -#include -#endif #include "zenoh.h" const char *kind_to_str(z_sample_kind_t kind); @@ -84,7 +78,7 @@ int main(int argc, char **argv) { while (c != 'q') { c = getchar(); if (c == -1) { - sleep(1); + zp_sleep_s(1); } } diff --git a/examples/z_sub_liveliness.c b/examples/z_sub_liveliness.c index f67ac5a68..8146c2ff4 100644 --- a/examples/z_sub_liveliness.c +++ b/examples/z_sub_liveliness.c @@ -12,12 +12,6 @@ // ZettaScale Zenoh Team, // #include -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) -#include -#define sleep(x) Sleep(x * 1000) -#else -#include -#endif #include "zenoh.h" void data_handler(const z_sample_t *sample, void *arg) { @@ -76,7 +70,7 @@ int main(int argc, char **argv) { while (c != 'q') { c = getchar(); if (c == -1) { - sleep(1); + zp_sleep_s(1); } } diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index 2e0d04f06..9192ffeb6 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -2559,6 +2559,9 @@ ZENOHC_API int8_t zp_mutex_init(struct zp_mutex_t *m); ZENOHC_API int8_t zp_mutex_lock(struct zp_mutex_t *m); ZENOHC_API int8_t zp_mutex_try_lock(struct zp_mutex_t *m); ZENOHC_API int8_t zp_mutex_unlock(struct zp_mutex_t *m); +ZENOHC_API int8_t zp_sleep_ms(size_t time); +ZENOHC_API int8_t zp_sleep_s(size_t time); +ZENOHC_API int8_t zp_sleep_us(size_t time); ZENOHC_API int8_t zp_task_init(struct zp_task_t *task, const struct zp_task_attr_t *_attr, diff --git a/src/platform/mod.rs b/src/platform/mod.rs index c9f87a9c7..ca370a967 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -1,5 +1,5 @@ // -// Copyright (c) 2017, 2023 ZettaScale Technology. +// Copyright (c) 2017, 2024 ZettaScale Technology. // // This program and the accompanying materials are made available under the // terms of the Eclipse Public License 2.0 which is available at @@ -14,3 +14,5 @@ pub use synchronization::*; mod synchronization; +pub use sleep::*; +mod sleep; diff --git a/src/platform/sleep.rs b/src/platform/sleep.rs new file mode 100644 index 000000000..1c79ac393 --- /dev/null +++ b/src/platform/sleep.rs @@ -0,0 +1,19 @@ +use std::{thread, time}; + +#[no_mangle] +pub extern "C" fn zp_sleep_s(time: usize) -> i8 { + thread::sleep(time::Duration::from_secs(time as u64)); + 0 +} + +#[no_mangle] +pub extern "C" fn zp_sleep_ms(time: usize) -> i8 { + thread::sleep(time::Duration::from_millis(time as u64)); + 0 +} + +#[no_mangle] +pub extern "C" fn zp_sleep_us(time: usize) -> i8 { + thread::sleep(time::Duration::from_micros(time as u64)); + 0 +} diff --git a/tests/z_api_alignment_test.c b/tests/z_api_alignment_test.c index 98ac3bc94..5233314a2 100644 --- a/tests/z_api_alignment_test.c +++ b/tests/z_api_alignment_test.c @@ -17,14 +17,6 @@ #undef NDEBUG #include - -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__) -#include -#define sleep(x) Sleep(x * 1000) -#else -#include -#endif - #include "zenoh.h" #define SLEEP 1 @@ -135,7 +127,7 @@ int main(int argc, char **argv) { assert(_ret_int == -1); #endif - sleep(SLEEP); + zp_sleep_s(SLEEP); size_t keyexpr_len = strlen(URI); char *keyexpr_str = (char *)malloc(keyexpr_len + 1); @@ -157,7 +149,7 @@ int main(int argc, char **argv) { assert(strlen(URI) == keyexpr_len); #endif - sleep(SLEEP); + zp_sleep_s(SLEEP); z_owned_config_t _ret_config = z_config_new(); assert(z_check(_ret_config)); @@ -184,7 +176,7 @@ int main(int argc, char **argv) { #endif z_drop(z_move(_ret_sconfig)); - sleep(SLEEP); + zp_sleep_s(SLEEP); _ret_sconfig = z_scouting_config_from(z_loan(_ret_config)); z_owned_closure_hello_t _ret_closure_hello = z_closure(hello_handler, NULL, NULL); @@ -192,8 +184,8 @@ int main(int argc, char **argv) { assert(_ret_int8 == 0); assert(hellos == 1); - sleep(atoi(SCOUTING_TIMEOUT) / 1000); - sleep(SLEEP); + zp_sleep_s(atoi(SCOUTING_TIMEOUT) / 1000); + zp_sleep_s(SLEEP); z_owned_session_t s1 = z_open(z_move(_ret_config)); assert(z_check(s1)); @@ -207,13 +199,13 @@ int main(int argc, char **argv) { z_owned_closure_zid_t _ret_closure_zid = z_closure(zid_handler, NULL, NULL); _ret_int8 = z_info_peers_zid(z_loan(s1), z_move(_ret_closure_zid)); assert(_ret_int8 == 0); - sleep(SLEEP); + zp_sleep_s(SLEEP); assert(zids == 0); _ret_int8 = z_info_routers_zid(z_loan(s1), z_move(_ret_closure_zid)); assert(_ret_int8 == 0); - sleep(SLEEP); + zp_sleep_s(SLEEP); assert(zids == 1); #ifdef ZENOH_PICO @@ -223,7 +215,7 @@ int main(int argc, char **argv) { zp_start_lease_task(z_loan(s1), &_ret_lease_opt); #endif - sleep(SLEEP); + zp_sleep_s(SLEEP); _ret_config = z_config_default(); #ifdef ZENOH_PICO @@ -248,7 +240,7 @@ int main(int argc, char **argv) { zp_start_lease_task(z_loan(s2), NULL); #endif - sleep(SLEEP); + zp_sleep_s(SLEEP); z_session_t ls1 = z_loan(s1); z_owned_closure_sample_t _ret_closure_sample = z_closure(data_handler, NULL, &ls1); @@ -257,7 +249,7 @@ int main(int argc, char **argv) { z_declare_subscriber(z_loan(s2), z_keyexpr(keyexpr_str), z_move(_ret_closure_sample), &_ret_sub_opt); assert(z_check(_ret_sub)); - sleep(SLEEP); + zp_sleep_s(SLEEP); char s1_res[64]; sprintf(s1_res, "%s/chunk/%d", keyexpr_str, 1); @@ -271,14 +263,14 @@ int main(int argc, char **argv) { _ret_int8 = z_put(z_loan(s1), z_loan(_ret_expr), (const uint8_t *)value, strlen(value), &_ret_put_opt); assert(_ret_int8 == 0); - sleep(SLEEP); + zp_sleep_s(SLEEP); assert(datas == 1); z_delete_options_t _ret_delete_opt = z_delete_options_default(); _ret_int8 = z_delete(z_loan(s1), z_loan(_ret_expr), &_ret_delete_opt); assert(_ret_int8 == 0); - sleep(SLEEP); + zp_sleep_s(SLEEP); assert(datas == 2); _ret_int8 = z_undeclare_keyexpr(z_loan(s1), z_move(_ret_expr)); @@ -303,23 +295,23 @@ int main(int argc, char **argv) { _ret_int8 = z_publisher_put(z_loan(_ret_pub), (const uint8_t *)value, strlen(value), &_ret_pput_opt); assert(_ret_int8 == 0); - sleep(SLEEP); + zp_sleep_s(SLEEP); _ret_int8 = z_subscriber_pull(z_loan(_ret_psub)); assert(_ret_int8 == 0); - sleep(SLEEP); + zp_sleep_s(SLEEP); assert(datas == 3); z_publisher_delete_options_t _ret_pdelete_opt = z_publisher_delete_options_default(); _ret_int8 = z_publisher_delete(z_loan(_ret_pub), &_ret_pdelete_opt); - sleep(SLEEP); + zp_sleep_s(SLEEP); _ret_int8 = z_subscriber_pull(z_loan(_ret_psub)); assert(_ret_int8 == 0); - sleep(SLEEP); + zp_sleep_s(SLEEP); assert(datas == 4); _ret_int8 = z_undeclare_publisher(z_move(_ret_pub)); @@ -328,7 +320,7 @@ int main(int argc, char **argv) { _ret_int8 = z_undeclare_pull_subscriber(z_move(_ret_psub)); assert(_ret_int8 == 0); - sleep(SLEEP); + zp_sleep_s(SLEEP); z_owned_closure_query_t _ret_closure_query = z_closure(query_handler, NULL, &ls1); z_queryable_options_t _ret_qle_opt = z_queryable_options_default(); @@ -336,7 +328,7 @@ int main(int argc, char **argv) { z_declare_queryable(z_loan(s1), z_keyexpr(s1_res), z_move(_ret_closure_query), &_ret_qle_opt); assert(z_check(qle)); - sleep(SLEEP); + zp_sleep_s(SLEEP); z_session_t ls2 = z_loan(s2); z_owned_closure_reply_t _ret_closure_reply = z_closure(reply_handler, NULL, &ls2); @@ -350,7 +342,7 @@ int main(int argc, char **argv) { _ret_int8 = z_get(z_loan(s2), z_keyexpr(s1_res), "", z_move(_ret_closure_reply), &_ret_get_opt); assert(_ret_int8 == 0); - sleep(SLEEP); + zp_sleep_s(SLEEP); assert(queries == 1); assert(replies == 1); @@ -372,7 +364,7 @@ int main(int argc, char **argv) { _ret_int8 = z_close(z_move(s2)); assert(_ret_int8 == 0); - sleep(SLEEP * 5); + zp_sleep_s(SLEEP * 5); free(keyexpr_str); diff --git a/tests/z_int_pub_cache_query_sub_test.c b/tests/z_int_pub_cache_query_sub_test.c index 6674aec55..980d5d5d8 100644 --- a/tests/z_int_pub_cache_query_sub_test.c +++ b/tests/z_int_pub_cache_query_sub_test.c @@ -122,7 +122,7 @@ int run_subscriber() { } SEM_POST(sem_sub); - sleep(10); + zp_sleep_s(10); z_drop(z_move(sub)); z_close(z_move(s)); diff --git a/tests/z_int_pub_sub_attachment_test.c b/tests/z_int_pub_sub_attachment_test.c index 75ae88547..155fc6902 100644 --- a/tests/z_int_pub_sub_attachment_test.c +++ b/tests/z_int_pub_sub_attachment_test.c @@ -106,7 +106,7 @@ int run_subscriber() { } SEM_POST(sem); - sleep(10); + zp_sleep_s(10); z_undeclare_subscriber(z_move(sub)); z_close(z_move(s)); diff --git a/tests/z_int_queryable_attachment_test.c b/tests/z_int_queryable_attachment_test.c index b2f2a7ab8..c33d66191 100644 --- a/tests/z_int_queryable_attachment_test.c +++ b/tests/z_int_queryable_attachment_test.c @@ -76,7 +76,7 @@ int run_queryable() { } SEM_POST(sem); - sleep(10); + zp_sleep_s(10); z_drop(z_move(qable)); z_close(z_move(s)); diff --git a/tests/z_int_queryable_test.c b/tests/z_int_queryable_test.c index 4244af2c7..d9cc4ea92 100644 --- a/tests/z_int_queryable_test.c +++ b/tests/z_int_queryable_test.c @@ -59,7 +59,7 @@ int run_queryable() { } SEM_POST(sem); - sleep(10); + zp_sleep_s(10); z_drop(z_move(qable)); z_close(z_move(s)); From 89e1c0095698ccf88b97449217fccac7520a66d4 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Mon, 26 Feb 2024 19:04:21 +0100 Subject: [PATCH 02/18] support for time api --- Cargo.lock | 62 +++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + Cargo.toml.in | 1 + examples/z_ping.c | 19 ++++-------- examples/z_sub_thr.c | 25 ++++++---------- include/zenoh_commons.h | 8 ++++++ src/platform/clock.rs | 64 +++++++++++++++++++++++++++++++++++++++++ src/platform/mod.rs | 6 ++-- 8 files changed, 154 insertions(+), 32 deletions(-) create mode 100644 src/platform/clock.rs diff --git a/Cargo.lock b/Cargo.lock index 593220380..11783b2f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -55,6 +55,21 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anstream" version = "0.6.4" @@ -421,6 +436,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets 0.52.0", +] + [[package]] name = "cipher" version = "0.4.4" @@ -1017,6 +1046,29 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "idna" version = "0.4.0" @@ -2807,6 +2859,15 @@ dependencies = [ "windows_x86_64_msvc 0.34.0", ] +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.0", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -3033,6 +3094,7 @@ dependencies = [ "async-std", "async-trait", "cbindgen", + "chrono", "env_logger", "fs2", "futures", diff --git a/Cargo.toml b/Cargo.toml index 52deaa71c..b1d35e9c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,7 @@ maintenance = { status = "actively-developed" } [dependencies] async-std = "=1.12.0" async-trait = "0.1.66" +chrono = "0.4.34" env_logger = "0.10.0" futures = "0.3.26" json5 = "0.4.1" diff --git a/Cargo.toml.in b/Cargo.toml.in index d1eec11bd..083a49277 100644 --- a/Cargo.toml.in +++ b/Cargo.toml.in @@ -41,6 +41,7 @@ maintenance = { status = "actively-developed" } [dependencies] async-std = "=1.12.0" async-trait = "0.1.66" +chrono = "0.4.34" env_logger = "0.10.0" futures = "0.3.26" json5 = "0.4.1" diff --git a/examples/z_ping.c b/examples/z_ping.c index 84606f728..5a04fd530 100644 --- a/examples/z_ping.c +++ b/examples/z_ping.c @@ -2,7 +2,6 @@ #include #include #include -#include #include "zenoh.h" @@ -58,35 +57,27 @@ int main(int argc, char** argv) { zp_mutex_lock(&mutex); if (args.warmup_ms) { printf("Warming up for %dms...\n", args.warmup_ms); - struct timespec wmup_start, wmup_stop, wmup_timeout; - clock_gettime(CLOCK_MONOTONIC, &wmup_start); + zp_time_t warmup_start = zp_time_now(); + unsigned long elapsed_us = 0; while (elapsed_us < args.warmup_ms * 1000) { - clock_gettime(CLOCK_REALTIME, &wmup_timeout); - wmup_timeout.tv_sec += PING_TIMEOUT_SEC; z_publisher_put(z_loan(pub), data, args.size, NULL); int s = zp_condvar_wait(&cond, &mutex); if (s != 0) { handle_error_en(s, "zp_condvar_wait"); } - clock_gettime(CLOCK_MONOTONIC, &wmup_stop); - elapsed_us = - (1000000 * (wmup_stop.tv_sec - wmup_start.tv_sec) + (wmup_stop.tv_nsec - wmup_start.tv_nsec) / 1000); + elapsed_us = zp_time_elapsed_us(&warmup_start); } } - struct timespec t_start, t_stop, t_timeout; unsigned long* results = malloc(sizeof(unsigned long) * args.number_of_pings); for (int i = 0; i < args.number_of_pings; i++) { - clock_gettime(CLOCK_REALTIME, &t_timeout); - t_timeout.tv_sec += PING_TIMEOUT_SEC; - clock_gettime(CLOCK_MONOTONIC, &t_start); + zp_time_t measure_start = zp_time_now(); z_publisher_put(z_loan(pub), data, args.size, NULL); int s = zp_condvar_wait(&cond, &mutex); if (s != 0) { handle_error_en(s, "zp_condvar_wait"); } - clock_gettime(CLOCK_MONOTONIC, &t_stop); - results[i] = (1000000 * (t_stop.tv_sec - t_start.tv_sec) + (t_stop.tv_nsec - t_start.tv_nsec) / 1000); + results[i] = zp_time_elapsed_us(&measure_start); } for (int i = 0; i < args.number_of_pings; i++) { printf("%d bytes: seq=%d rtt=%luµs, lat=%luµs\n", args.size, i, results[i], results[i] / 2); diff --git a/examples/z_sub_thr.c b/examples/z_sub_thr.c index d82b6ea81..4a8c2f6d0 100644 --- a/examples/z_sub_thr.c +++ b/examples/z_sub_thr.c @@ -12,7 +12,6 @@ // ZettaScale Zenoh Team, // #include -#include #include "zenoh.h" @@ -21,46 +20,40 @@ typedef struct { volatile unsigned long count; volatile unsigned long finished_rounds; - struct timespec start; - struct timespec first_start; + zp_time_t start; + zp_time_t first_start; + bool started; } z_stats_t; z_stats_t *z_stats_make() { z_stats_t *stats = malloc(sizeof(z_stats_t)); stats->count = 0; stats->finished_rounds = 0; - stats->first_start.tv_nsec = 0; + stats->started = false; return stats; } -static inline double get_elapsed_s(const struct timespec *start, const struct timespec *end) { - return (double)(end->tv_sec - start->tv_sec) + (double)(end->tv_nsec - start->tv_nsec) / 1.0E9; -} - void on_sample(const z_sample_t *sample, void *context) { z_stats_t *stats = (z_stats_t *)context; if (stats->count == 0) { - clock_gettime(CLOCK_MONOTONIC, &stats->start); - if (stats->first_start.tv_nsec == 0) { + stats->start = zp_time_now(); + if (!stats->started) { stats->first_start = stats->start; + stats->started = true; } stats->count++; } else if (stats->count < N) { stats->count++; } else { - struct timespec end; - clock_gettime(CLOCK_MONOTONIC, &end); stats->finished_rounds++; - printf("%f msg/s\n", (double)N / get_elapsed_s(&stats->start, &end)); + printf("%f msg/s\n", 1000.0 * N / zp_time_elapsed_ms(&stats->start)); stats->count = 0; } } void drop_stats(void *context) { const z_stats_t *stats = (z_stats_t *)context; const unsigned long sent_messages = N * stats->finished_rounds + stats->count; - struct timespec end; - clock_gettime(CLOCK_MONOTONIC, &end); - double elapsed_s = get_elapsed_s(&stats->first_start, &end); + double elapsed_s = zp_time_elapsed_s(&stats->first_start); printf("Stats being dropped after unsubscribing: sent %ld messages over %f seconds (%f msg/s)\n", sent_messages, elapsed_s, (double)sent_messages / elapsed_s); free(context); diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index 9192ffeb6..6d10f4d52 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -981,6 +981,9 @@ typedef struct zp_task_t { typedef struct zp_task_attr_t { size_t _0; } zp_task_attr_t; +typedef struct zp_time_t { + size_t _0[2]; +} zp_time_t; ZENOHC_API extern const unsigned int Z_ROUTER; ZENOHC_API extern const unsigned int Z_PEER; ZENOHC_API extern const unsigned int Z_CLIENT; @@ -2568,3 +2571,8 @@ int8_t zp_task_init(struct zp_task_t *task, void (*fun)(void *arg), void *arg); ZENOHC_API int8_t zp_task_join(struct zp_task_t *task); +ZENOHC_API size_t zp_time_elapsed_ms(const struct zp_time_t *time); +ZENOHC_API size_t zp_time_elapsed_s(const struct zp_time_t *time); +ZENOHC_API size_t zp_time_elapsed_us(const struct zp_time_t *time); +ZENOHC_API struct zp_time_t zp_time_now(void); +ZENOHC_API const char *zp_time_now_as_str(const char *buf, size_t len); diff --git a/src/platform/clock.rs b/src/platform/clock.rs new file mode 100644 index 000000000..75f461517 --- /dev/null +++ b/src/platform/clock.rs @@ -0,0 +1,64 @@ +use std::{cmp::min, slice, time::{Duration, Instant, SystemTime}}; +use libc::c_char; +use chrono::{Local, DateTime}; + +use crate::{impl_guarded_transmute, GuardedTransmute}; + +// TODO: properly define alignment for every architecture +#[repr(C)] +#[derive(Clone, Copy)] +pub struct zp_time_t([usize; 2]); + +impl_guarded_transmute!(zp_time_t, Instant); +impl_guarded_transmute!(Instant, zp_time_t); + + +#[no_mangle] +pub extern "C" fn zp_time_now() -> zp_time_t { + let t = Instant::now(); + t.transmute() +} + +#[no_mangle] +pub unsafe extern "C" fn zp_time_now_as_str(buf: *const c_char, len: usize) -> *const c_char { + if len == 0 { + return buf; + } + let datetime:DateTime = SystemTime::now().into(); + let s = datetime.format("%Y-%m-%dT%H:%M:%SZ").to_string(); + let sb = s.as_bytes(); + let max_len = min(len - 1, s.len()); + let b = slice::from_raw_parts_mut(buf as *mut u8, max_len + 1); + b[0..max_len].copy_from_slice(&sb[0..max_len]); + b[max_len] = 0; + buf +} + + + +unsafe fn get_elapsed(time: *const zp_time_t) -> Duration { + if time.is_null() { + return Duration::new(0, 0); + } + let ttime = (*time).transmute(); + let ret = ttime.elapsed(); + #[allow(forgetting_copy_types)] + std::mem::forget(ttime); + ret +} + +#[no_mangle] +pub unsafe extern "C" fn zp_time_elapsed_s(time: *const zp_time_t) -> usize { + return get_elapsed(time).as_secs() as usize; +} + + +#[no_mangle] +pub unsafe extern "C" fn zp_time_elapsed_ms(time: *const zp_time_t) -> usize { + return get_elapsed(time).as_millis() as usize; +} + +#[no_mangle] +pub unsafe extern "C" fn zp_time_elapsed_us(time: *const zp_time_t) -> usize { + return get_elapsed(time).as_micros() as usize; +} \ No newline at end of file diff --git a/src/platform/mod.rs b/src/platform/mod.rs index ca370a967..48c992742 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -12,7 +12,9 @@ // ZettaScale Zenoh team, // -pub use synchronization::*; -mod synchronization; +pub use clock::*; +mod clock; pub use sleep::*; mod sleep; +pub use synchronization::*; +mod synchronization; \ No newline at end of file From 8468d5684ee81f05f0994a77439c14887ad71b18 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Mon, 26 Feb 2024 19:16:21 +0100 Subject: [PATCH 03/18] clippy and fmt fixes --- src/platform/clock.rs | 27 ++++++++++++++++----------- src/platform/mod.rs | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/platform/clock.rs b/src/platform/clock.rs index 75f461517..f39284d89 100644 --- a/src/platform/clock.rs +++ b/src/platform/clock.rs @@ -1,6 +1,10 @@ -use std::{cmp::min, slice, time::{Duration, Instant, SystemTime}}; +use chrono::{DateTime, Local}; use libc::c_char; -use chrono::{Local, DateTime}; +use std::{ + cmp::min, + slice, + time::{Duration, Instant, SystemTime}, +}; use crate::{impl_guarded_transmute, GuardedTransmute}; @@ -12,7 +16,6 @@ pub struct zp_time_t([usize; 2]); impl_guarded_transmute!(zp_time_t, Instant); impl_guarded_transmute!(Instant, zp_time_t); - #[no_mangle] pub extern "C" fn zp_time_now() -> zp_time_t { let t = Instant::now(); @@ -20,11 +23,12 @@ pub extern "C" fn zp_time_now() -> zp_time_t { } #[no_mangle] +#[allow(clippy::missing_safety_doc)] pub unsafe extern "C" fn zp_time_now_as_str(buf: *const c_char, len: usize) -> *const c_char { if len == 0 { return buf; } - let datetime:DateTime = SystemTime::now().into(); + let datetime: DateTime = SystemTime::now().into(); let s = datetime.format("%Y-%m-%dT%H:%M:%SZ").to_string(); let sb = s.as_bytes(); let max_len = min(len - 1, s.len()); @@ -34,8 +38,7 @@ pub unsafe extern "C" fn zp_time_now_as_str(buf: *const c_char, len: usize) -> * buf } - - +#[allow(clippy::missing_safety_doc)] unsafe fn get_elapsed(time: *const zp_time_t) -> Duration { if time.is_null() { return Duration::new(0, 0); @@ -48,17 +51,19 @@ unsafe fn get_elapsed(time: *const zp_time_t) -> Duration { } #[no_mangle] +#[allow(clippy::missing_safety_doc)] pub unsafe extern "C" fn zp_time_elapsed_s(time: *const zp_time_t) -> usize { - return get_elapsed(time).as_secs() as usize; + get_elapsed(time).as_secs() as usize } - #[no_mangle] +#[allow(clippy::missing_safety_doc)] pub unsafe extern "C" fn zp_time_elapsed_ms(time: *const zp_time_t) -> usize { - return get_elapsed(time).as_millis() as usize; + get_elapsed(time).as_millis() as usize } #[no_mangle] +#[allow(clippy::missing_safety_doc)] pub unsafe extern "C" fn zp_time_elapsed_us(time: *const zp_time_t) -> usize { - return get_elapsed(time).as_micros() as usize; -} \ No newline at end of file + get_elapsed(time).as_micros() as usize +} diff --git a/src/platform/mod.rs b/src/platform/mod.rs index 48c992742..03864b829 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -17,4 +17,4 @@ mod clock; pub use sleep::*; mod sleep; pub use synchronization::*; -mod synchronization; \ No newline at end of file +mod synchronization; From c3339560aeaafb01b2e61082836414c063a7d5f5 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Mon, 26 Feb 2024 20:55:38 +0100 Subject: [PATCH 04/18] fix zp_time_t size --- include/zenoh_commons.h | 2 +- src/platform/clock.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index 6d10f4d52..dfc539221 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -982,7 +982,7 @@ typedef struct zp_task_attr_t { size_t _0; } zp_task_attr_t; typedef struct zp_time_t { - size_t _0[2]; + uint64_t _0[2]; } zp_time_t; ZENOHC_API extern const unsigned int Z_ROUTER; ZENOHC_API extern const unsigned int Z_PEER; diff --git a/src/platform/clock.rs b/src/platform/clock.rs index f39284d89..4db6dc6cc 100644 --- a/src/platform/clock.rs +++ b/src/platform/clock.rs @@ -8,10 +8,10 @@ use std::{ use crate::{impl_guarded_transmute, GuardedTransmute}; -// TODO: properly define alignment for every architecture +// TODO: properly define size/alignment for every architecture #[repr(C)] #[derive(Clone, Copy)] -pub struct zp_time_t([usize; 2]); +pub struct zp_time_t([u64; 2]); impl_guarded_transmute!(zp_time_t, Instant); impl_guarded_transmute!(Instant, zp_time_t); From 7f340766e98496f8243125f9c93578f3a25e0500 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 27 Feb 2024 17:07:12 +0100 Subject: [PATCH 05/18] conditional for zp_time_t struct for x86_64-apple --- cbindgen.toml | 1 + include/zenoh_commons.h | 7 +++++++ src/platform/clock.rs | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/cbindgen.toml b/cbindgen.toml index f0704fe81..067b4b716 100644 --- a/cbindgen.toml +++ b/cbindgen.toml @@ -57,6 +57,7 @@ usize_is_size_t = true "target_arch = aarch64" = "TARGET_ARCH_AARCH64" "target_arch = x86_64" = "TARGET_ARCH_X86_64" "target_arch = arm" = "TARGET_ARCH_ARM" +"target_vendor = apple" = "TARGET_VENDOR_APPLE" [export] include = [] diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index dfc539221..295cef0ca 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -981,9 +981,16 @@ typedef struct zp_task_t { typedef struct zp_task_attr_t { size_t _0; } zp_task_attr_t; +#if (defined(TARGET_ARCH_X86_64) && defined(TARGET_VENDOR_APPLE)) +typedef struct zp_time_t { + uint64_t _0[1]; +} zp_time_t; +#endif +#if !(defined(TARGET_ARCH_X86_64) && defined(TARGET_VENDOR_APPLE)) typedef struct zp_time_t { uint64_t _0[2]; } zp_time_t; +#endif ZENOHC_API extern const unsigned int Z_ROUTER; ZENOHC_API extern const unsigned int Z_PEER; ZENOHC_API extern const unsigned int Z_CLIENT; diff --git a/src/platform/clock.rs b/src/platform/clock.rs index 4db6dc6cc..d43d4346b 100644 --- a/src/platform/clock.rs +++ b/src/platform/clock.rs @@ -9,6 +9,12 @@ use std::{ use crate::{impl_guarded_transmute, GuardedTransmute}; // TODO: properly define size/alignment for every architecture +#[cfg(all(target_arch = "x86_64", target_vendor = "apple"))] +#[repr(C)] +#[derive(Clone, Copy)] +pub struct zp_time_t([u64; 1]); + +#[cfg(not(all(target_arch = "x86_64", target_vendor = "apple")))] #[repr(C)] #[derive(Clone, Copy)] pub struct zp_time_t([u64; 2]); From 53180e9c339a22c921ed8187f6c7990be38447d9 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 27 Feb 2024 18:28:37 +0100 Subject: [PATCH 06/18] corrected zp_time_t to store only time difference from some initial Instant --- Cargo.lock | 1 + Cargo.toml | 1 + Cargo.toml.in | 1 + cbindgen.toml | 1 - include/zenoh_commons.h | 15 ++++--------- src/platform/clock.rs | 48 ++++++++++++++++++----------------------- 6 files changed, 28 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 11783b2f3..c681dcc53 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3099,6 +3099,7 @@ dependencies = [ "fs2", "futures", "json5", + "lazy_static", "libc", "log", "rand", diff --git a/Cargo.toml b/Cargo.toml index b1d35e9c0..95867f95f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,7 @@ chrono = "0.4.34" env_logger = "0.10.0" futures = "0.3.26" json5 = "0.4.1" +lazy_static = "1.4.0" libc = "0.2.139" log = "0.4.17" rand = "0.8.5" diff --git a/Cargo.toml.in b/Cargo.toml.in index 083a49277..f434df3a1 100644 --- a/Cargo.toml.in +++ b/Cargo.toml.in @@ -45,6 +45,7 @@ chrono = "0.4.34" env_logger = "0.10.0" futures = "0.3.26" json5 = "0.4.1" +lazy_static = "1.4.0" libc = "0.2.139" log = "0.4.17" rand = "0.8.5" diff --git a/cbindgen.toml b/cbindgen.toml index 067b4b716..f0704fe81 100644 --- a/cbindgen.toml +++ b/cbindgen.toml @@ -57,7 +57,6 @@ usize_is_size_t = true "target_arch = aarch64" = "TARGET_ARCH_AARCH64" "target_arch = x86_64" = "TARGET_ARCH_X86_64" "target_arch = arm" = "TARGET_ARCH_ARM" -"target_vendor = apple" = "TARGET_VENDOR_APPLE" [export] include = [] diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index 295cef0ca..f8b0060ee 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -981,16 +981,9 @@ typedef struct zp_task_t { typedef struct zp_task_attr_t { size_t _0; } zp_task_attr_t; -#if (defined(TARGET_ARCH_X86_64) && defined(TARGET_VENDOR_APPLE)) typedef struct zp_time_t { - uint64_t _0[1]; + double t; } zp_time_t; -#endif -#if !(defined(TARGET_ARCH_X86_64) && defined(TARGET_VENDOR_APPLE)) -typedef struct zp_time_t { - uint64_t _0[2]; -} zp_time_t; -#endif ZENOHC_API extern const unsigned int Z_ROUTER; ZENOHC_API extern const unsigned int Z_PEER; ZENOHC_API extern const unsigned int Z_CLIENT; @@ -2578,8 +2571,8 @@ int8_t zp_task_init(struct zp_task_t *task, void (*fun)(void *arg), void *arg); ZENOHC_API int8_t zp_task_join(struct zp_task_t *task); -ZENOHC_API size_t zp_time_elapsed_ms(const struct zp_time_t *time); -ZENOHC_API size_t zp_time_elapsed_s(const struct zp_time_t *time); -ZENOHC_API size_t zp_time_elapsed_us(const struct zp_time_t *time); +ZENOHC_API uint64_t zp_time_elapsed_ms(const struct zp_time_t *time); +ZENOHC_API uint64_t zp_time_elapsed_s(const struct zp_time_t *time); +ZENOHC_API uint64_t zp_time_elapsed_us(const struct zp_time_t *time); ZENOHC_API struct zp_time_t zp_time_now(void); ZENOHC_API const char *zp_time_now_as_str(const char *buf, size_t len); diff --git a/src/platform/clock.rs b/src/platform/clock.rs index d43d4346b..ac64bedc3 100644 --- a/src/platform/clock.rs +++ b/src/platform/clock.rs @@ -3,29 +3,27 @@ use libc::c_char; use std::{ cmp::min, slice, - time::{Duration, Instant, SystemTime}, + time::{Instant, SystemTime}, }; -use crate::{impl_guarded_transmute, GuardedTransmute}; +use lazy_static::lazy_static; -// TODO: properly define size/alignment for every architecture -#[cfg(all(target_arch = "x86_64", target_vendor = "apple"))] -#[repr(C)] -#[derive(Clone, Copy)] -pub struct zp_time_t([u64; 1]); +lazy_static! { + /// This is an example for using doc comment attributes + static ref INSTANT_BASE: Instant = Instant::now(); +} -#[cfg(not(all(target_arch = "x86_64", target_vendor = "apple")))] #[repr(C)] #[derive(Clone, Copy)] -pub struct zp_time_t([u64; 2]); - -impl_guarded_transmute!(zp_time_t, Instant); -impl_guarded_transmute!(Instant, zp_time_t); +pub struct zp_time_t { + t: f64 +} #[no_mangle] pub extern "C" fn zp_time_now() -> zp_time_t { - let t = Instant::now(); - t.transmute() + zp_time_t { + t: INSTANT_BASE.elapsed().as_secs_f64() + } } #[no_mangle] @@ -45,31 +43,27 @@ pub unsafe extern "C" fn zp_time_now_as_str(buf: *const c_char, len: usize) -> * } #[allow(clippy::missing_safety_doc)] -unsafe fn get_elapsed(time: *const zp_time_t) -> Duration { +unsafe fn get_elapsed_seconds(time: *const zp_time_t) -> f64 { if time.is_null() { - return Duration::new(0, 0); + return 0.0; } - let ttime = (*time).transmute(); - let ret = ttime.elapsed(); - #[allow(forgetting_copy_types)] - std::mem::forget(ttime); - ret + zp_time_now().t - (*time).t } #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_time_elapsed_s(time: *const zp_time_t) -> usize { - get_elapsed(time).as_secs() as usize +pub unsafe extern "C" fn zp_time_elapsed_s(time: *const zp_time_t) -> u64 { + get_elapsed_seconds(time) as u64 } #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_time_elapsed_ms(time: *const zp_time_t) -> usize { - get_elapsed(time).as_millis() as usize +pub unsafe extern "C" fn zp_time_elapsed_ms(time: *const zp_time_t) -> u64 { + (get_elapsed_seconds(time) * 1000.0) as u64 } #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_time_elapsed_us(time: *const zp_time_t) -> usize { - get_elapsed(time).as_micros() as usize +pub unsafe extern "C" fn zp_time_elapsed_us(time: *const zp_time_t) -> u64 { + (get_elapsed_seconds(time) * 1000000.0) as u64 } From 7cc0427c6b6790a70aaccfab1bf8b5113a1a7582 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 27 Feb 2024 18:31:18 +0100 Subject: [PATCH 07/18] fmt --- src/platform/clock.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platform/clock.rs b/src/platform/clock.rs index ac64bedc3..608a9d188 100644 --- a/src/platform/clock.rs +++ b/src/platform/clock.rs @@ -16,13 +16,13 @@ lazy_static! { #[repr(C)] #[derive(Clone, Copy)] pub struct zp_time_t { - t: f64 + t: f64, } #[no_mangle] pub extern "C" fn zp_time_now() -> zp_time_t { zp_time_t { - t: INSTANT_BASE.elapsed().as_secs_f64() + t: INSTANT_BASE.elapsed().as_secs_f64(), } } @@ -47,7 +47,7 @@ unsafe fn get_elapsed_seconds(time: *const zp_time_t) -> f64 { if time.is_null() { return 0.0; } - zp_time_now().t - (*time).t + zp_time_now().t - (*time).t } #[no_mangle] From 0d28425a8bc418d563039e66cd72fb93be0c6fdb Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 27 Feb 2024 18:54:54 +0100 Subject: [PATCH 08/18] rename zp_time... -> zp_clock...; implement zp_time... functionality based on system clock --- examples/z_ping.c | 8 ++--- examples/z_sub_thr.c | 10 +++---- include/zenoh_commons.h | 15 ++++++++++ src/platform/clock.rs | 66 ++++++++++++++++++++++++++++++++++------- 4 files changed, 79 insertions(+), 20 deletions(-) diff --git a/examples/z_ping.c b/examples/z_ping.c index 5a04fd530..718b67054 100644 --- a/examples/z_ping.c +++ b/examples/z_ping.c @@ -57,7 +57,7 @@ int main(int argc, char** argv) { zp_mutex_lock(&mutex); if (args.warmup_ms) { printf("Warming up for %dms...\n", args.warmup_ms); - zp_time_t warmup_start = zp_time_now(); + zp_clock_t warmup_start = zp_clock_now(); unsigned long elapsed_us = 0; while (elapsed_us < args.warmup_ms * 1000) { @@ -66,18 +66,18 @@ int main(int argc, char** argv) { if (s != 0) { handle_error_en(s, "zp_condvar_wait"); } - elapsed_us = zp_time_elapsed_us(&warmup_start); + elapsed_us = zp_clock_elapsed_us(&warmup_start); } } unsigned long* results = malloc(sizeof(unsigned long) * args.number_of_pings); for (int i = 0; i < args.number_of_pings; i++) { - zp_time_t measure_start = zp_time_now(); + zp_clock_t measure_start = zp_clock_now(); z_publisher_put(z_loan(pub), data, args.size, NULL); int s = zp_condvar_wait(&cond, &mutex); if (s != 0) { handle_error_en(s, "zp_condvar_wait"); } - results[i] = zp_time_elapsed_us(&measure_start); + results[i] = zp_clock_elapsed_us(&measure_start); } for (int i = 0; i < args.number_of_pings; i++) { printf("%d bytes: seq=%d rtt=%luµs, lat=%luµs\n", args.size, i, results[i], results[i] / 2); diff --git a/examples/z_sub_thr.c b/examples/z_sub_thr.c index 4a8c2f6d0..766d4be4c 100644 --- a/examples/z_sub_thr.c +++ b/examples/z_sub_thr.c @@ -20,8 +20,8 @@ typedef struct { volatile unsigned long count; volatile unsigned long finished_rounds; - zp_time_t start; - zp_time_t first_start; + zp_clock_t start; + zp_clock_t first_start; bool started; } z_stats_t; @@ -36,7 +36,7 @@ z_stats_t *z_stats_make() { void on_sample(const z_sample_t *sample, void *context) { z_stats_t *stats = (z_stats_t *)context; if (stats->count == 0) { - stats->start = zp_time_now(); + stats->start = zp_clock_now(); if (!stats->started) { stats->first_start = stats->start; stats->started = true; @@ -46,14 +46,14 @@ void on_sample(const z_sample_t *sample, void *context) { stats->count++; } else { stats->finished_rounds++; - printf("%f msg/s\n", 1000.0 * N / zp_time_elapsed_ms(&stats->start)); + printf("%f msg/s\n", 1000.0 * N / zp_clock_elapsed_ms(&stats->start)); stats->count = 0; } } void drop_stats(void *context) { const z_stats_t *stats = (z_stats_t *)context; const unsigned long sent_messages = N * stats->finished_rounds + stats->count; - double elapsed_s = zp_time_elapsed_s(&stats->first_start); + double elapsed_s = zp_clock_elapsed_s(&stats->first_start); printf("Stats being dropped after unsubscribing: sent %ld messages over %f seconds (%f msg/s)\n", sent_messages, elapsed_s, (double)sent_messages / elapsed_s); free(context); diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index f8b0060ee..ec6371d56 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -957,6 +957,13 @@ typedef struct ze_querying_subscriber_options_t { typedef struct ze_querying_subscriber_t { const struct ze_owned_querying_subscriber_t *_0; } ze_querying_subscriber_t; +/** + * Clock + * Uses monothonic clock + */ +typedef struct zp_clock_t { + double t; +} zp_clock_t; /** * Condvar * @@ -981,6 +988,10 @@ typedef struct zp_task_t { typedef struct zp_task_attr_t { size_t _0; } zp_task_attr_t; +/** + * Time + * Uses system clock + */ typedef struct zp_time_t { double t; } zp_time_t; @@ -2553,6 +2564,10 @@ int8_t ze_undeclare_publication_cache(struct ze_owned_publication_cache_t *pub_c */ ZENOHC_API int8_t ze_undeclare_querying_subscriber(struct ze_owned_querying_subscriber_t *sub); +ZENOHC_API uint64_t zp_clock_elapsed_ms(const struct zp_clock_t *time); +ZENOHC_API uint64_t zp_clock_elapsed_s(const struct zp_clock_t *time); +ZENOHC_API uint64_t zp_clock_elapsed_us(const struct zp_clock_t *time); +ZENOHC_API struct zp_clock_t zp_clock_now(void); ZENOHC_API int8_t zp_condvar_free(struct zp_condvar_t *cv); ZENOHC_API int8_t zp_condvar_init(struct zp_condvar_t *cv); ZENOHC_API int8_t zp_condvar_signal(struct zp_condvar_t *cv); diff --git a/src/platform/clock.rs b/src/platform/clock.rs index 608a9d188..ae082ac51 100644 --- a/src/platform/clock.rs +++ b/src/platform/clock.rs @@ -3,27 +3,62 @@ use libc::c_char; use std::{ cmp::min, slice, - time::{Instant, SystemTime}, + time::{Duration, Instant, SystemTime, UNIX_EPOCH}, }; use lazy_static::lazy_static; lazy_static! { /// This is an example for using doc comment attributes - static ref INSTANT_BASE: Instant = Instant::now(); + static ref CLOCK_BASE: Instant = Instant::now(); } +/// Clock +/// Uses monothonic clock #[repr(C)] #[derive(Clone, Copy)] -pub struct zp_time_t { +pub struct zp_clock_t { t: f64, } #[no_mangle] -pub extern "C" fn zp_time_now() -> zp_time_t { - zp_time_t { - t: INSTANT_BASE.elapsed().as_secs_f64(), +pub extern "C" fn zp_clock_now() -> zp_clock_t { + zp_clock_t { + t: CLOCK_BASE.elapsed().as_secs_f64(), + } +} +#[allow(clippy::missing_safety_doc)] +unsafe fn get_elapsed_seconds(time: *const zp_clock_t) -> f64 { + if time.is_null() { + return 0.0; } + zp_clock_now().t - (*time).t +} + +#[no_mangle] +#[allow(clippy::missing_safety_doc)] +pub unsafe extern "C" fn zp_clock_elapsed_s(time: *const zp_clock_t) -> u64 { + get_elapsed_seconds(time) as u64 +} + +#[no_mangle] +#[allow(clippy::missing_safety_doc)] +pub unsafe extern "C" fn zp_clock_elapsed_ms(time: *const zp_clock_t) -> u64 { + (get_elapsed_seconds(time) * 1000.0) as u64 +} + +#[no_mangle] +#[allow(clippy::missing_safety_doc)] +pub unsafe extern "C" fn zp_clock_elapsed_us(time: *const zp_clock_t) -> u64 { + (get_elapsed_seconds(time) * 1000000.0) as u64 +} + +/// Time +/// Uses system clock +#[repr(C)] +#[derive(Clone, Copy)] +pub struct zp_time_t { + t: f64, } #[no_mangle] @@ -42,28 +77,37 @@ pub unsafe extern "C" fn zp_time_now_as_str(buf: *const c_char, len: usize) -> * buf } +#[no_mangle] +pub extern "C" fn zp_time_now() -> zp_time_t { + zp_time_t { + t: SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap_or(Duration::new(0, 0)) + .as_secs_f64(), + } +} #[allow(clippy::missing_safety_doc)] -unsafe fn get_elapsed_seconds(time: *const zp_time_t) -> f64 { +unsafe fn get_elapsed_seconds_system_clock(time: *const zp_time_t) -> f64 { if time.is_null() { return 0.0; } - zp_time_now().t - (*time).t + 0.0f64.max(zp_time_now().t - (*time).t) } #[no_mangle] #[allow(clippy::missing_safety_doc)] pub unsafe extern "C" fn zp_time_elapsed_s(time: *const zp_time_t) -> u64 { - get_elapsed_seconds(time) as u64 + get_elapsed_seconds_system_clock(time) as u64 } #[no_mangle] #[allow(clippy::missing_safety_doc)] pub unsafe extern "C" fn zp_time_elapsed_ms(time: *const zp_time_t) -> u64 { - (get_elapsed_seconds(time) * 1000.0) as u64 + (get_elapsed_seconds_system_clock(time) * 1000.0) as u64 } #[no_mangle] #[allow(clippy::missing_safety_doc)] pub unsafe extern "C" fn zp_time_elapsed_us(time: *const zp_time_t) -> u64 { - (get_elapsed_seconds(time) * 1000000.0) as u64 + (get_elapsed_seconds_system_clock(time) * 1000000.0) as u64 } From 583c8493f8986a8b1f233653fe07ab4dc64b3020 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Wed, 28 Feb 2024 10:02:50 +0100 Subject: [PATCH 09/18] typo fix --- include/zenoh_commons.h | 2 +- src/platform/clock.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index ec6371d56..41e824d15 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -959,7 +959,7 @@ typedef struct ze_querying_subscriber_t { } ze_querying_subscriber_t; /** * Clock - * Uses monothonic clock + * Uses monotonic clock */ typedef struct zp_clock_t { double t; diff --git a/src/platform/clock.rs b/src/platform/clock.rs index ae082ac51..b5c17ffe0 100644 --- a/src/platform/clock.rs +++ b/src/platform/clock.rs @@ -14,7 +14,7 @@ lazy_static! { } /// Clock -/// Uses monothonic clock +/// Uses monotonic clock #[repr(C)] #[derive(Clone, Copy)] pub struct zp_clock_t { From bbbf0ba6c689c63c13ff745edd2ad5fecadce966 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Wed, 28 Feb 2024 09:58:01 +0100 Subject: [PATCH 10/18] replace zp_ prefix with z_ --- examples/z_ping.c | 24 +++---- include/zenoh_commons.h | 107 ++++++++++++++++++-------------- src/platform/synchronization.rs | 70 ++++++++++----------- 3 files changed, 107 insertions(+), 94 deletions(-) diff --git a/examples/z_ping.c b/examples/z_ping.c index 718b67054..6b82b0ace 100644 --- a/examples/z_ping.c +++ b/examples/z_ping.c @@ -13,11 +13,11 @@ #define handle_error_en(en, msg) \ do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) -zp_condvar_t cond; -zp_mutex_t mutex; +z_condvar_t cond; +z_mutex_t mutex; -void callback(const z_sample_t* sample, void* context) { zp_condvar_signal(&cond); } -void drop(void* context) { zp_condvar_free(&cond); } +void callback(const z_sample_t* sample, void* context) { z_condvar_signal(&cond); } +void drop(void* context) { z_condvar_free(&cond); } struct args_t { unsigned int size; // -s @@ -41,8 +41,8 @@ int main(int argc, char** argv) { DEFAULT_PKT_SIZE, DEFAULT_PING_NB, DEFAULT_WARMUP_MS); return 1; } - zp_mutex_init(&mutex); - zp_condvar_init(&cond); + z_mutex_init(&mutex); + z_condvar_init(&cond); z_owned_config_t config = args.config_path ? zc_config_from_file(args.config_path) : z_config_default(); z_owned_session_t session = z_open(z_move(config)); z_keyexpr_t ping = z_keyexpr_unchecked("test/ping"); @@ -54,7 +54,7 @@ int main(int argc, char** argv) { for (int i = 0; i < args.size; i++) { data[i] = i % 10; } - zp_mutex_lock(&mutex); + z_mutex_lock(&mutex); if (args.warmup_ms) { printf("Warming up for %dms...\n", args.warmup_ms); zp_clock_t warmup_start = zp_clock_now(); @@ -62,9 +62,9 @@ int main(int argc, char** argv) { unsigned long elapsed_us = 0; while (elapsed_us < args.warmup_ms * 1000) { z_publisher_put(z_loan(pub), data, args.size, NULL); - int s = zp_condvar_wait(&cond, &mutex); + int s = z_condvar_wait(&cond, &mutex); if (s != 0) { - handle_error_en(s, "zp_condvar_wait"); + handle_error_en(s, "z_condvar_wait"); } elapsed_us = zp_clock_elapsed_us(&warmup_start); } @@ -73,16 +73,16 @@ int main(int argc, char** argv) { for (int i = 0; i < args.number_of_pings; i++) { zp_clock_t measure_start = zp_clock_now(); z_publisher_put(z_loan(pub), data, args.size, NULL); - int s = zp_condvar_wait(&cond, &mutex); + int s = z_condvar_wait(&cond, &mutex); if (s != 0) { - handle_error_en(s, "zp_condvar_wait"); + handle_error_en(s, "z_condvar_wait"); } results[i] = zp_clock_elapsed_us(&measure_start); } for (int i = 0; i < args.number_of_pings; i++) { printf("%d bytes: seq=%d rtt=%luµs, lat=%luµs\n", args.size, i, results[i], results[i] / 2); } - zp_mutex_unlock(&mutex); + z_mutex_unlock(&mutex); free(results); free(data); z_drop(z_move(sub)); diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index 41e824d15..68003a0aa 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -462,6 +462,20 @@ typedef struct z_owned_closure_zid_t { void (*call)(const struct z_id_t*, void*); void (*drop)(void*); } z_owned_closure_zid_t; +/** + * Condvar + * + */ +typedef struct z_condvar_t { + size_t _0; +} z_condvar_t; +/** + * Mutex + * + */ +typedef struct z_mutex_t { + size_t _0; +} z_mutex_t; /** * An owned zenoh configuration. * @@ -788,6 +802,16 @@ typedef struct z_owned_scouting_config_t { typedef struct z_subscriber_t { const struct z_owned_subscriber_t *_0; } z_subscriber_t; +/** + * Task + * + */ +typedef struct z_task_t { + size_t _0; +} z_task_t; +typedef struct z_task_attr_t { + size_t _0; +} z_task_attr_t; /** * The options for `zc_liveliness_declare_token` */ @@ -957,44 +981,30 @@ typedef struct ze_querying_subscriber_options_t { typedef struct ze_querying_subscriber_t { const struct ze_owned_querying_subscriber_t *_0; } ze_querying_subscriber_t; -/** - * Clock - * Uses monotonic clock - */ -typedef struct zp_clock_t { - double t; -} zp_clock_t; /** * Condvar * */ -typedef struct zp_condvar_t { +typedef struct z_condvar_t { size_t _0; -} zp_condvar_t; +} z_condvar_t; /** * Mutex * */ -typedef struct zp_mutex_t { +typedef struct z_mutex_t { size_t _0; -} zp_mutex_t; +} z_mutex_t; /** * Task * */ -typedef struct zp_task_t { +typedef struct z_task_t { size_t _0; -} zp_task_t; -typedef struct zp_task_attr_t { +} z_task_t; +typedef struct z_task_attr_t { size_t _0; -} zp_task_attr_t; -/** - * Time - * Uses system clock - */ -typedef struct zp_time_t { - double t; -} zp_time_t; +} z_task_attr_t; ZENOHC_API extern const unsigned int Z_ROUTER; ZENOHC_API extern const unsigned int Z_PEER; ZENOHC_API extern const unsigned int Z_CLIENT; @@ -1228,6 +1238,10 @@ ZENOHC_API void z_closure_zid_drop(struct z_owned_closure_zid_t *closure); * Constructs a null safe-to-drop value of 'z_owned_closure_zid_t' type */ ZENOHC_API struct z_owned_closure_zid_t z_closure_zid_null(void); +ZENOHC_API int8_t z_condvar_free(struct z_condvar_t *cv); +ZENOHC_API int8_t z_condvar_init(struct z_condvar_t *cv); +ZENOHC_API int8_t z_condvar_signal(struct z_condvar_t *cv); +ZENOHC_API int8_t z_condvar_wait(struct z_condvar_t *cv, struct z_mutex_t *m); /** * Returns ``true`` if `config` is valid. */ @@ -1645,6 +1659,11 @@ ZENOHC_API struct z_owned_str_t z_keyexpr_to_string(struct z_keyexpr_t keyexpr); */ ZENOHC_API struct z_keyexpr_t z_keyexpr_unchecked(const char *name); +ZENOHC_API int8_t z_mutex_free(struct z_mutex_t *m); +ZENOHC_API int8_t z_mutex_init(struct z_mutex_t *m); +ZENOHC_API int8_t z_mutex_lock(struct z_mutex_t *m); +ZENOHC_API int8_t z_mutex_try_lock(struct z_mutex_t *m); +ZENOHC_API int8_t z_mutex_unlock(struct z_mutex_t *m); /** * Opens a zenoh session. Should the session opening fail, `z_check` ing the returned value will return `false`. */ @@ -2042,6 +2061,12 @@ ZENOHC_API struct z_subscriber_options_t z_subscriber_options_default(void); * sub: The :c:type:`z_owned_pull_subscriber_t` to pull from. */ ZENOHC_API int8_t z_subscriber_pull(struct z_pull_subscriber_t sub); +ZENOHC_API +int8_t z_task_init(struct z_task_t *task, + const struct z_task_attr_t *_attr, + void (*fun)(void *arg), + void *arg); +ZENOHC_API int8_t z_task_join(struct z_task_t *task); /** * Returns ``true`` if `ts` is a valid timestamp */ @@ -2564,30 +2589,18 @@ int8_t ze_undeclare_publication_cache(struct ze_owned_publication_cache_t *pub_c */ ZENOHC_API int8_t ze_undeclare_querying_subscriber(struct ze_owned_querying_subscriber_t *sub); -ZENOHC_API uint64_t zp_clock_elapsed_ms(const struct zp_clock_t *time); -ZENOHC_API uint64_t zp_clock_elapsed_s(const struct zp_clock_t *time); -ZENOHC_API uint64_t zp_clock_elapsed_us(const struct zp_clock_t *time); -ZENOHC_API struct zp_clock_t zp_clock_now(void); -ZENOHC_API int8_t zp_condvar_free(struct zp_condvar_t *cv); -ZENOHC_API int8_t zp_condvar_init(struct zp_condvar_t *cv); -ZENOHC_API int8_t zp_condvar_signal(struct zp_condvar_t *cv); -ZENOHC_API int8_t zp_condvar_wait(struct zp_condvar_t *cv, struct zp_mutex_t *m); -ZENOHC_API int8_t zp_mutex_free(struct zp_mutex_t *m); -ZENOHC_API int8_t zp_mutex_init(struct zp_mutex_t *m); -ZENOHC_API int8_t zp_mutex_lock(struct zp_mutex_t *m); -ZENOHC_API int8_t zp_mutex_try_lock(struct zp_mutex_t *m); -ZENOHC_API int8_t zp_mutex_unlock(struct zp_mutex_t *m); -ZENOHC_API int8_t zp_sleep_ms(size_t time); -ZENOHC_API int8_t zp_sleep_s(size_t time); -ZENOHC_API int8_t zp_sleep_us(size_t time); -ZENOHC_API -int8_t zp_task_init(struct zp_task_t *task, - const struct zp_task_attr_t *_attr, +ZENOHC_API int8_t z_condvar_free(struct z_condvar_t *cv); +ZENOHC_API int8_t z_condvar_init(struct z_condvar_t *cv); +ZENOHC_API int8_t z_condvar_signal(struct z_condvar_t *cv); +ZENOHC_API int8_t z_condvar_wait(struct z_condvar_t *cv, struct zp_mutex_t *m); +ZENOHC_API int8_t z_mutex_free(struct z_mutex_t *m); +ZENOHC_API int8_t z_mutex_init(struct z_mutex_t *m); +ZENOHC_API int8_t z_mutex_lock(struct z_mutex_t *m); +ZENOHC_API int8_t z_mutex_try_lock(struct z_mutex_t *m); +ZENOHC_API int8_t z_mutex_unlock(struct z_mutex_t *m); +ZENOHC_API +int8_t z_task_init(struct z_task_t *task, + const struct z_task_attr_t *_attr, void (*fun)(void *arg), void *arg); -ZENOHC_API int8_t zp_task_join(struct zp_task_t *task); -ZENOHC_API uint64_t zp_time_elapsed_ms(const struct zp_time_t *time); -ZENOHC_API uint64_t zp_time_elapsed_s(const struct zp_time_t *time); -ZENOHC_API uint64_t zp_time_elapsed_us(const struct zp_time_t *time); -ZENOHC_API struct zp_time_t zp_time_now(void); -ZENOHC_API const char *zp_time_now_as_str(const char *buf, size_t len); +ZENOHC_API int8_t zp_task_join(struct z_task_t *task); diff --git a/src/platform/synchronization.rs b/src/platform/synchronization.rs index 1b8af1ea9..1973e6d65 100644 --- a/src/platform/synchronization.rs +++ b/src/platform/synchronization.rs @@ -7,23 +7,23 @@ use libc::c_void; use crate::{impl_guarded_transmute, GuardedTransmute}; -pub struct ZPMutex<'a> { +pub struct ZMutex<'a> { mutex: Mutex<()>, lock: Option>, } -pub struct ZPMutexPtr { - data: Option>>, +pub struct ZMutexPtr { + data: Option>>, } /// Mutex /// #[repr(C)] #[derive(Clone, Copy)] -pub struct zp_mutex_t(usize); +pub struct z_mutex_t(usize); -impl_guarded_transmute!(zp_mutex_t, ZPMutexPtr); -impl_guarded_transmute!(ZPMutexPtr, zp_mutex_t); +impl_guarded_transmute!(z_mutex_t, ZMutexPtr); +impl_guarded_transmute!(ZMutexPtr, z_mutex_t); const EBUSY: i8 = -1; const EINVAL: i8 = -2; @@ -32,12 +32,12 @@ const EPOISON: i8 = -10; #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_mutex_init(m: *mut zp_mutex_t) -> i8 { +pub unsafe extern "C" fn z_mutex_init(m: *mut z_mutex_t) -> i8 { if m.is_null() { return EINVAL; } - let t = ZPMutexPtr { - data: Some(Box::new(ZPMutex { + let t = ZMutexPtr { + data: Some(Box::new(ZMutex { mutex: Mutex::new(()), lock: None, })), @@ -48,7 +48,7 @@ pub unsafe extern "C" fn zp_mutex_init(m: *mut zp_mutex_t) -> i8 { #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_mutex_free(m: *mut zp_mutex_t) -> i8 { +pub unsafe extern "C" fn z_mutex_free(m: *mut z_mutex_t) -> i8 { if m.is_null() { return EINVAL; } @@ -61,7 +61,7 @@ pub unsafe extern "C" fn zp_mutex_free(m: *mut zp_mutex_t) -> i8 { #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_mutex_lock(m: *mut zp_mutex_t) -> i8 { +pub unsafe extern "C" fn z_mutex_lock(m: *mut z_mutex_t) -> i8 { if m.is_null() { return EINVAL; } @@ -86,7 +86,7 @@ pub unsafe extern "C" fn zp_mutex_lock(m: *mut zp_mutex_t) -> i8 { #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_mutex_unlock(m: *mut zp_mutex_t) -> i8 { +pub unsafe extern "C" fn z_mutex_unlock(m: *mut z_mutex_t) -> i8 { if m.is_null() { return EINVAL; } @@ -106,7 +106,7 @@ pub unsafe extern "C" fn zp_mutex_unlock(m: *mut zp_mutex_t) -> i8 { #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_mutex_try_lock(m: *mut zp_mutex_t) -> i8 { +pub unsafe extern "C" fn z_mutex_try_lock(m: *mut z_mutex_t) -> i8 { if m.is_null() { return EINVAL; } @@ -129,7 +129,7 @@ pub unsafe extern "C" fn zp_mutex_try_lock(m: *mut zp_mutex_t) -> i8 { ret } -struct ZPCondvarPtr { +struct ZCondvarPtr { data: Option>, } @@ -137,18 +137,18 @@ struct ZPCondvarPtr { /// #[repr(C)] #[derive(Clone, Copy)] -pub struct zp_condvar_t(usize); +pub struct z_condvar_t(usize); -impl_guarded_transmute!(zp_condvar_t, ZPCondvarPtr); -impl_guarded_transmute!(ZPCondvarPtr, zp_condvar_t); +impl_guarded_transmute!(z_condvar_t, ZCondvarPtr); +impl_guarded_transmute!(ZCondvarPtr, z_condvar_t); #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_condvar_init(cv: *mut zp_condvar_t) -> i8 { +pub unsafe extern "C" fn z_condvar_init(cv: *mut z_condvar_t) -> i8 { if cv.is_null() { return EINVAL; } - let t: ZPCondvarPtr = ZPCondvarPtr { + let t: ZCondvarPtr = ZCondvarPtr { data: Some(Box::new(Condvar::new())), }; *cv = t.transmute(); @@ -157,7 +157,7 @@ pub unsafe extern "C" fn zp_condvar_init(cv: *mut zp_condvar_t) -> i8 { #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_condvar_free(cv: *mut zp_condvar_t) -> i8 { +pub unsafe extern "C" fn z_condvar_free(cv: *mut z_condvar_t) -> i8 { if cv.is_null() { return EINVAL; } @@ -172,7 +172,7 @@ pub unsafe extern "C" fn zp_condvar_free(cv: *mut zp_condvar_t) -> i8 { #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_condvar_signal(cv: *mut zp_condvar_t) -> i8 { +pub unsafe extern "C" fn z_condvar_signal(cv: *mut z_condvar_t) -> i8 { if cv.is_null() { return EINVAL; } @@ -187,7 +187,7 @@ pub unsafe extern "C" fn zp_condvar_signal(cv: *mut zp_condvar_t) -> i8 { #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_condvar_wait(cv: *mut zp_condvar_t, m: *mut zp_mutex_t) -> i8 { +pub unsafe extern "C" fn z_condvar_wait(cv: *mut z_condvar_t, m: *mut z_mutex_t) -> i8 { if cv.is_null() { return EINVAL; } @@ -213,26 +213,26 @@ pub unsafe extern "C" fn zp_condvar_wait(cv: *mut zp_condvar_t, m: *mut zp_mutex 0 } -struct ZPTask { +struct ZTask { join_handle: JoinHandle<()>, } -struct ZPTaskPtr { - data: Option>, +struct ZTaskPtr { + data: Option>, } /// Task /// #[repr(C)] #[derive(Clone, Copy)] -pub struct zp_task_t(usize); +pub struct z_task_t(usize); #[repr(C)] #[derive(Clone, Copy)] -pub struct zp_task_attr_t(usize); +pub struct z_task_attr_t(usize); -impl_guarded_transmute!(zp_task_t, ZPTaskPtr); -impl_guarded_transmute!(ZPTaskPtr, zp_task_t); +impl_guarded_transmute!(z_task_t, ZTaskPtr); +impl_guarded_transmute!(ZTaskPtr, z_task_t); struct FunArgPair { fun: unsafe extern "C" fn(arg: *mut c_void), @@ -249,9 +249,9 @@ unsafe impl Send for FunArgPair {} #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_task_init( - task: *mut zp_task_t, - _attr: *const zp_task_attr_t, +pub unsafe extern "C" fn z_task_init( + task: *mut z_task_t, + _attr: *const z_task_attr_t, fun: unsafe extern "C" fn(arg: *mut c_void), arg: *mut c_void, ) -> i8 { @@ -259,12 +259,12 @@ pub unsafe extern "C" fn zp_task_init( return EINVAL; } - let mut ttask = ZPTaskPtr { data: None }; + let mut ttask = ZTaskPtr { data: None }; let fun_arg_pair = FunArgPair { fun, arg }; let mut ret = 0; match thread::Builder::new().spawn(move || fun_arg_pair.call()) { - Ok(join_handle) => ttask.data = Some(Box::new(ZPTask { join_handle })), + Ok(join_handle) => ttask.data = Some(Box::new(ZTask { join_handle })), Err(_) => ret = EAGAIN, } *task = ttask.transmute(); @@ -273,7 +273,7 @@ pub unsafe extern "C" fn zp_task_init( #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_task_join(task: *mut zp_task_t) -> i8 { +pub unsafe extern "C" fn z_task_join(task: *mut z_task_t) -> i8 { if task.is_null() { return EINVAL; } From 1da2801ee9f9eceb297b1a1e95dcc47e0ec182fc Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Wed, 28 Feb 2024 12:05:33 +0100 Subject: [PATCH 11/18] set error values to correspond to the ones from GNU pthreads --- src/platform/synchronization.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/platform/synchronization.rs b/src/platform/synchronization.rs index 1973e6d65..73ae823c6 100644 --- a/src/platform/synchronization.rs +++ b/src/platform/synchronization.rs @@ -25,10 +25,11 @@ pub struct z_mutex_t(usize); impl_guarded_transmute!(z_mutex_t, ZMutexPtr); impl_guarded_transmute!(ZMutexPtr, z_mutex_t); -const EBUSY: i8 = -1; -const EINVAL: i8 = -2; -const EAGAIN: i8 = -3; -const EPOISON: i8 = -10; +// try to use the same error codes as in GNU pthreads +const EBUSY: i8 = 16; +const EINVAL: i8 = 22; +const EAGAIN: i8 = 11; +const EPOISON: i8 = 22; // same as EINVAL #[no_mangle] #[allow(clippy::missing_safety_doc)] From 74c42b82554b4a7ab64dd06f4fee438824ba9682 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Wed, 28 Feb 2024 15:11:44 +0100 Subject: [PATCH 12/18] fix error codes sign to be negative --- src/platform/synchronization.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/platform/synchronization.rs b/src/platform/synchronization.rs index 73ae823c6..dbd9d94b8 100644 --- a/src/platform/synchronization.rs +++ b/src/platform/synchronization.rs @@ -25,11 +25,12 @@ pub struct z_mutex_t(usize); impl_guarded_transmute!(z_mutex_t, ZMutexPtr); impl_guarded_transmute!(ZMutexPtr, z_mutex_t); -// try to use the same error codes as in GNU pthreads -const EBUSY: i8 = 16; -const EINVAL: i8 = 22; -const EAGAIN: i8 = 11; -const EPOISON: i8 = 22; // same as EINVAL +// using the same error codes as in GNU pthreads, but with negative sign +// due to convention to return negative values on error +const EBUSY: i8 = -16; +const EINVAL: i8 = -22; +const EAGAIN: i8 = -11; +const EPOISON: i8 = -22; // same as EINVAL #[no_mangle] #[allow(clippy::missing_safety_doc)] From a229066c578fba2a0b8af3287c4afb3782106d63 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Wed, 28 Feb 2024 15:36:37 +0100 Subject: [PATCH 13/18] replace zp_ prefix with z_ --- examples/z_liveliness.c | 2 +- examples/z_ping.c | 8 +-- examples/z_pub.c | 2 +- examples/z_pub_attachment.c | 2 +- examples/z_pub_cache.c | 2 +- examples/z_pub_shm.c | 2 +- examples/z_pull.c | 2 +- examples/z_query_sub.c | 2 +- examples/z_queryable.c | 2 +- examples/z_scout.c | 2 +- examples/z_sub.c | 2 +- examples/z_sub_attachment.c | 2 +- examples/z_sub_liveliness.c | 2 +- examples/z_sub_thr.c | 10 ++-- include/zenoh_commons.h | 65 ++++++++++--------------- src/platform/clock.rs | 34 ++++++------- src/platform/sleep.rs | 6 +-- tests/z_api_alignment_test.c | 40 +++++++-------- tests/z_int_pub_cache_query_sub_test.c | 2 +- tests/z_int_pub_sub_attachment_test.c | 2 +- tests/z_int_queryable_attachment_test.c | 2 +- tests/z_int_queryable_test.c | 2 +- 22 files changed, 91 insertions(+), 104 deletions(-) diff --git a/examples/z_liveliness.c b/examples/z_liveliness.c index 29dc51892..4191b0496 100644 --- a/examples/z_liveliness.c +++ b/examples/z_liveliness.c @@ -57,7 +57,7 @@ int main(int argc, char **argv) { while (c != 'q') { c = getchar(); if (c == -1) { - zp_sleep_s(1); + z_sleep_s(1); } else if (c == 'd') { printf("Undeclaring liveliness token...\n"); z_drop(z_move(token)); diff --git a/examples/z_ping.c b/examples/z_ping.c index 6b82b0ace..7f213ef2d 100644 --- a/examples/z_ping.c +++ b/examples/z_ping.c @@ -57,7 +57,7 @@ int main(int argc, char** argv) { z_mutex_lock(&mutex); if (args.warmup_ms) { printf("Warming up for %dms...\n", args.warmup_ms); - zp_clock_t warmup_start = zp_clock_now(); + z_clock_t warmup_start = z_clock_now(); unsigned long elapsed_us = 0; while (elapsed_us < args.warmup_ms * 1000) { @@ -66,18 +66,18 @@ int main(int argc, char** argv) { if (s != 0) { handle_error_en(s, "z_condvar_wait"); } - elapsed_us = zp_clock_elapsed_us(&warmup_start); + elapsed_us = z_clock_elapsed_us(&warmup_start); } } unsigned long* results = malloc(sizeof(unsigned long) * args.number_of_pings); for (int i = 0; i < args.number_of_pings; i++) { - zp_clock_t measure_start = zp_clock_now(); + z_clock_t measure_start = z_clock_now(); z_publisher_put(z_loan(pub), data, args.size, NULL); int s = z_condvar_wait(&cond, &mutex); if (s != 0) { handle_error_en(s, "z_condvar_wait"); } - results[i] = zp_clock_elapsed_us(&measure_start); + results[i] = z_clock_elapsed_us(&measure_start); } for (int i = 0; i < args.number_of_pings; i++) { printf("%d bytes: seq=%d rtt=%luµs, lat=%luµs\n", args.size, i, results[i], results[i] / 2); diff --git a/examples/z_pub.c b/examples/z_pub.c index 1f0d7476b..543cba694 100644 --- a/examples/z_pub.c +++ b/examples/z_pub.c @@ -66,7 +66,7 @@ int main(int argc, char **argv) { char buf[256]; for (int idx = 0; 1; ++idx) { - zp_sleep_s(1); + z_sleep_s(1); sprintf(buf, "[%4d] %s", idx, value); printf("Putting Data ('%s': '%s')...\n", keyexpr, buf); z_publisher_put_options_t options = z_publisher_put_options_default(); diff --git a/examples/z_pub_attachment.c b/examples/z_pub_attachment.c index 877ad93be..a24133e91 100644 --- a/examples/z_pub_attachment.c +++ b/examples/z_pub_attachment.c @@ -63,7 +63,7 @@ int main(int argc, char **argv) { char buf[256]; char buf_ind[16]; for (int idx = 0; 1; ++idx) { - zp_sleep_s(1); + z_sleep_s(1); // add some other attachment value sprintf(buf_ind, "%d", idx); diff --git a/examples/z_pub_cache.c b/examples/z_pub_cache.c index 6412ca7f1..770bf9d93 100644 --- a/examples/z_pub_cache.c +++ b/examples/z_pub_cache.c @@ -60,7 +60,7 @@ int main(int argc, char **argv) { char buf[256]; for (int idx = 0; 1; ++idx) { - zp_sleep_s(1); + z_sleep_s(1); sprintf(buf, "[%4d] %s", idx, value); printf("Putting Data ('%s': '%s')...\n", keyexpr, buf); z_put(z_loan(s), z_keyexpr(keyexpr), (const uint8_t *)buf, strlen(buf), NULL); diff --git a/examples/z_pub_shm.c b/examples/z_pub_shm.c index 81856c49f..10970bf62 100644 --- a/examples/z_pub_shm.c +++ b/examples/z_pub_shm.c @@ -79,7 +79,7 @@ int main(int argc, char **argv) { snprintf(buf, 255, "[%4d] %s", idx, value); size_t len = strlen(buf); zc_shmbuf_set_length(&shmbuf, len); - zp_sleep_s(1); + z_sleep_s(1); printf("Putting Data ('%s': '%s')...\n", keyexpr, buf); z_publisher_put_options_t options = z_publisher_put_options_default(); options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL); diff --git a/examples/z_pull.c b/examples/z_pull.c index 76d66d7fa..0af23f7e2 100644 --- a/examples/z_pull.c +++ b/examples/z_pull.c @@ -60,7 +60,7 @@ int main(int argc, char **argv) { while (c != 'q') { c = getchar(); if (c == -1) { - zp_sleep_s(1); + z_sleep_s(1); } else { z_subscriber_pull(z_loan(sub)); } diff --git a/examples/z_query_sub.c b/examples/z_query_sub.c index 7c2837345..15564be7c 100644 --- a/examples/z_query_sub.c +++ b/examples/z_query_sub.c @@ -62,7 +62,7 @@ int main(int argc, char **argv) { while (c != 'q') { c = getchar(); if (c == -1) { - zp_sleep_s(1); + z_sleep_s(1); } } diff --git a/examples/z_queryable.c b/examples/z_queryable.c index 32892412b..9d6ec7702 100644 --- a/examples/z_queryable.c +++ b/examples/z_queryable.c @@ -75,7 +75,7 @@ int main(int argc, char **argv) { while (c != 'q') { c = getchar(); if (c == -1) { - zp_sleep_s(1); + z_sleep_s(1); } } diff --git a/examples/z_scout.c b/examples/z_scout.c index f0201e41a..fda8e64b0 100644 --- a/examples/z_scout.c +++ b/examples/z_scout.c @@ -88,6 +88,6 @@ int main(int argc, char **argv) { z_owned_closure_hello_t closure = z_closure(callback, drop, context); printf("Scouting...\n"); z_scout(z_move(config), z_move(closure)); - zp_sleep_s(1); + z_sleep_s(1); return 0; } \ No newline at end of file diff --git a/examples/z_sub.c b/examples/z_sub.c index 1c22432d5..867c1277e 100644 --- a/examples/z_sub.c +++ b/examples/z_sub.c @@ -67,7 +67,7 @@ int main(int argc, char **argv) { while (c != 'q') { c = getchar(); if (c == -1) { - zp_sleep_s(1); + z_sleep_s(1); } } diff --git a/examples/z_sub_attachment.c b/examples/z_sub_attachment.c index a7f2308c6..58b0afd81 100644 --- a/examples/z_sub_attachment.c +++ b/examples/z_sub_attachment.c @@ -78,7 +78,7 @@ int main(int argc, char **argv) { while (c != 'q') { c = getchar(); if (c == -1) { - zp_sleep_s(1); + z_sleep_s(1); } } diff --git a/examples/z_sub_liveliness.c b/examples/z_sub_liveliness.c index 8146c2ff4..36bf64515 100644 --- a/examples/z_sub_liveliness.c +++ b/examples/z_sub_liveliness.c @@ -70,7 +70,7 @@ int main(int argc, char **argv) { while (c != 'q') { c = getchar(); if (c == -1) { - zp_sleep_s(1); + z_sleep_s(1); } } diff --git a/examples/z_sub_thr.c b/examples/z_sub_thr.c index 766d4be4c..0c2e24b17 100644 --- a/examples/z_sub_thr.c +++ b/examples/z_sub_thr.c @@ -20,8 +20,8 @@ typedef struct { volatile unsigned long count; volatile unsigned long finished_rounds; - zp_clock_t start; - zp_clock_t first_start; + z_clock_t start; + z_clock_t first_start; bool started; } z_stats_t; @@ -36,7 +36,7 @@ z_stats_t *z_stats_make() { void on_sample(const z_sample_t *sample, void *context) { z_stats_t *stats = (z_stats_t *)context; if (stats->count == 0) { - stats->start = zp_clock_now(); + stats->start = z_clock_now(); if (!stats->started) { stats->first_start = stats->start; stats->started = true; @@ -46,14 +46,14 @@ void on_sample(const z_sample_t *sample, void *context) { stats->count++; } else { stats->finished_rounds++; - printf("%f msg/s\n", 1000.0 * N / zp_clock_elapsed_ms(&stats->start)); + printf("%f msg/s\n", 1000.0 * N / z_clock_elapsed_ms(&stats->start)); stats->count = 0; } } void drop_stats(void *context) { const z_stats_t *stats = (z_stats_t *)context; const unsigned long sent_messages = N * stats->finished_rounds + stats->count; - double elapsed_s = zp_clock_elapsed_s(&stats->first_start); + double elapsed_s = z_clock_elapsed_s(&stats->first_start); printf("Stats being dropped after unsubscribing: sent %ld messages over %f seconds (%f msg/s)\n", sent_messages, elapsed_s, (double)sent_messages / elapsed_s); free(context); diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index 68003a0aa..16d19aa5d 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -198,6 +198,13 @@ typedef struct z_owned_bytes_map_t { uint64_t _0[2]; size_t _1[4]; } z_owned_bytes_map_t; +/** + * Clock + * Uses monotonic clock + */ +typedef struct z_clock_t { + double t; +} z_clock_t; /** * Represents a Zenoh ID. * @@ -812,6 +819,13 @@ typedef struct z_task_t { typedef struct z_task_attr_t { size_t _0; } z_task_attr_t; +/** + * Time + * Uses system clock + */ +typedef struct z_time_t { + double t; +} z_time_t; /** * The options for `zc_liveliness_declare_token` */ @@ -981,30 +995,6 @@ typedef struct ze_querying_subscriber_options_t { typedef struct ze_querying_subscriber_t { const struct ze_owned_querying_subscriber_t *_0; } ze_querying_subscriber_t; -/** - * Condvar - * - */ -typedef struct z_condvar_t { - size_t _0; -} z_condvar_t; -/** - * Mutex - * - */ -typedef struct z_mutex_t { - size_t _0; -} z_mutex_t; -/** - * Task - * - */ -typedef struct z_task_t { - size_t _0; -} z_task_t; -typedef struct z_task_attr_t { - size_t _0; -} z_task_attr_t; ZENOHC_API extern const unsigned int Z_ROUTER; ZENOHC_API extern const unsigned int Z_PEER; ZENOHC_API extern const unsigned int Z_CLIENT; @@ -1147,6 +1137,10 @@ ZENOHC_API struct z_bytes_t z_bytes_null(void); * Constructs a `len` bytes long view starting at `start`. */ ZENOHC_API struct z_bytes_t z_bytes_wrap(const uint8_t *start, size_t len); +ZENOHC_API uint64_t z_clock_elapsed_ms(const struct z_clock_t *time); +ZENOHC_API uint64_t z_clock_elapsed_s(const struct z_clock_t *time); +ZENOHC_API uint64_t z_clock_elapsed_us(const struct z_clock_t *time); +ZENOHC_API struct z_clock_t z_clock_now(void); /** * Closes a zenoh session. This drops and invalidates `session` for double-drop safety. * @@ -2005,6 +1999,9 @@ struct z_session_t z_session_loan(const struct z_owned_session_t *s); * Constructs a null safe-to-drop value of 'z_owned_session_t' type */ ZENOHC_API struct z_owned_session_t z_session_null(void); +ZENOHC_API int8_t z_sleep_ms(size_t time); +ZENOHC_API int8_t z_sleep_s(size_t time); +ZENOHC_API int8_t z_sleep_us(size_t time); /** * Returns ``true`` if `strs` is valid. */ @@ -2067,6 +2064,11 @@ int8_t z_task_init(struct z_task_t *task, void (*fun)(void *arg), void *arg); ZENOHC_API int8_t z_task_join(struct z_task_t *task); +ZENOHC_API uint64_t z_time_elapsed_ms(const struct z_time_t *time); +ZENOHC_API uint64_t z_time_elapsed_s(const struct z_time_t *time); +ZENOHC_API uint64_t z_time_elapsed_us(const struct z_time_t *time); +ZENOHC_API struct z_time_t z_time_now(void); +ZENOHC_API const char *z_time_now_as_str(const char *buf, size_t len); /** * Returns ``true`` if `ts` is a valid timestamp */ @@ -2589,18 +2591,3 @@ int8_t ze_undeclare_publication_cache(struct ze_owned_publication_cache_t *pub_c */ ZENOHC_API int8_t ze_undeclare_querying_subscriber(struct ze_owned_querying_subscriber_t *sub); -ZENOHC_API int8_t z_condvar_free(struct z_condvar_t *cv); -ZENOHC_API int8_t z_condvar_init(struct z_condvar_t *cv); -ZENOHC_API int8_t z_condvar_signal(struct z_condvar_t *cv); -ZENOHC_API int8_t z_condvar_wait(struct z_condvar_t *cv, struct zp_mutex_t *m); -ZENOHC_API int8_t z_mutex_free(struct z_mutex_t *m); -ZENOHC_API int8_t z_mutex_init(struct z_mutex_t *m); -ZENOHC_API int8_t z_mutex_lock(struct z_mutex_t *m); -ZENOHC_API int8_t z_mutex_try_lock(struct z_mutex_t *m); -ZENOHC_API int8_t z_mutex_unlock(struct z_mutex_t *m); -ZENOHC_API -int8_t z_task_init(struct z_task_t *task, - const struct z_task_attr_t *_attr, - void (*fun)(void *arg), - void *arg); -ZENOHC_API int8_t zp_task_join(struct z_task_t *task); diff --git a/src/platform/clock.rs b/src/platform/clock.rs index b5c17ffe0..ab5e3dab6 100644 --- a/src/platform/clock.rs +++ b/src/platform/clock.rs @@ -17,39 +17,39 @@ lazy_static! { /// Uses monotonic clock #[repr(C)] #[derive(Clone, Copy)] -pub struct zp_clock_t { +pub struct z_clock_t { t: f64, } #[no_mangle] -pub extern "C" fn zp_clock_now() -> zp_clock_t { - zp_clock_t { +pub extern "C" fn z_clock_now() -> z_clock_t { + z_clock_t { t: CLOCK_BASE.elapsed().as_secs_f64(), } } #[allow(clippy::missing_safety_doc)] -unsafe fn get_elapsed_seconds(time: *const zp_clock_t) -> f64 { +unsafe fn get_elapsed_seconds(time: *const z_clock_t) -> f64 { if time.is_null() { return 0.0; } - zp_clock_now().t - (*time).t + z_clock_now().t - (*time).t } #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_clock_elapsed_s(time: *const zp_clock_t) -> u64 { +pub unsafe extern "C" fn z_clock_elapsed_s(time: *const z_clock_t) -> u64 { get_elapsed_seconds(time) as u64 } #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_clock_elapsed_ms(time: *const zp_clock_t) -> u64 { +pub unsafe extern "C" fn z_clock_elapsed_ms(time: *const z_clock_t) -> u64 { (get_elapsed_seconds(time) * 1000.0) as u64 } #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_clock_elapsed_us(time: *const zp_clock_t) -> u64 { +pub unsafe extern "C" fn z_clock_elapsed_us(time: *const z_clock_t) -> u64 { (get_elapsed_seconds(time) * 1000000.0) as u64 } @@ -57,13 +57,13 @@ pub unsafe extern "C" fn zp_clock_elapsed_us(time: *const zp_clock_t) -> u64 { /// Uses system clock #[repr(C)] #[derive(Clone, Copy)] -pub struct zp_time_t { +pub struct z_time_t { t: f64, } #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_time_now_as_str(buf: *const c_char, len: usize) -> *const c_char { +pub unsafe extern "C" fn z_time_now_as_str(buf: *const c_char, len: usize) -> *const c_char { if len == 0 { return buf; } @@ -78,8 +78,8 @@ pub unsafe extern "C" fn zp_time_now_as_str(buf: *const c_char, len: usize) -> * } #[no_mangle] -pub extern "C" fn zp_time_now() -> zp_time_t { - zp_time_t { +pub extern "C" fn z_time_now() -> z_time_t { + z_time_t { t: SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap_or(Duration::new(0, 0)) @@ -87,27 +87,27 @@ pub extern "C" fn zp_time_now() -> zp_time_t { } } #[allow(clippy::missing_safety_doc)] -unsafe fn get_elapsed_seconds_system_clock(time: *const zp_time_t) -> f64 { +unsafe fn get_elapsed_seconds_system_clock(time: *const z_time_t) -> f64 { if time.is_null() { return 0.0; } - 0.0f64.max(zp_time_now().t - (*time).t) + 0.0f64.max(z_time_now().t - (*time).t) } #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_time_elapsed_s(time: *const zp_time_t) -> u64 { +pub unsafe extern "C" fn z_time_elapsed_s(time: *const z_time_t) -> u64 { get_elapsed_seconds_system_clock(time) as u64 } #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_time_elapsed_ms(time: *const zp_time_t) -> u64 { +pub unsafe extern "C" fn z_time_elapsed_ms(time: *const z_time_t) -> u64 { (get_elapsed_seconds_system_clock(time) * 1000.0) as u64 } #[no_mangle] #[allow(clippy::missing_safety_doc)] -pub unsafe extern "C" fn zp_time_elapsed_us(time: *const zp_time_t) -> u64 { +pub unsafe extern "C" fn z_time_elapsed_us(time: *const z_time_t) -> u64 { (get_elapsed_seconds_system_clock(time) * 1000000.0) as u64 } diff --git a/src/platform/sleep.rs b/src/platform/sleep.rs index 1c79ac393..b2f3e4dd7 100644 --- a/src/platform/sleep.rs +++ b/src/platform/sleep.rs @@ -1,19 +1,19 @@ use std::{thread, time}; #[no_mangle] -pub extern "C" fn zp_sleep_s(time: usize) -> i8 { +pub extern "C" fn z_sleep_s(time: usize) -> i8 { thread::sleep(time::Duration::from_secs(time as u64)); 0 } #[no_mangle] -pub extern "C" fn zp_sleep_ms(time: usize) -> i8 { +pub extern "C" fn z_sleep_ms(time: usize) -> i8 { thread::sleep(time::Duration::from_millis(time as u64)); 0 } #[no_mangle] -pub extern "C" fn zp_sleep_us(time: usize) -> i8 { +pub extern "C" fn z_sleep_us(time: usize) -> i8 { thread::sleep(time::Duration::from_micros(time as u64)); 0 } diff --git a/tests/z_api_alignment_test.c b/tests/z_api_alignment_test.c index 5233314a2..a113e2b5c 100644 --- a/tests/z_api_alignment_test.c +++ b/tests/z_api_alignment_test.c @@ -127,7 +127,7 @@ int main(int argc, char **argv) { assert(_ret_int == -1); #endif - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); size_t keyexpr_len = strlen(URI); char *keyexpr_str = (char *)malloc(keyexpr_len + 1); @@ -149,7 +149,7 @@ int main(int argc, char **argv) { assert(strlen(URI) == keyexpr_len); #endif - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); z_owned_config_t _ret_config = z_config_new(); assert(z_check(_ret_config)); @@ -176,7 +176,7 @@ int main(int argc, char **argv) { #endif z_drop(z_move(_ret_sconfig)); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); _ret_sconfig = z_scouting_config_from(z_loan(_ret_config)); z_owned_closure_hello_t _ret_closure_hello = z_closure(hello_handler, NULL, NULL); @@ -184,8 +184,8 @@ int main(int argc, char **argv) { assert(_ret_int8 == 0); assert(hellos == 1); - zp_sleep_s(atoi(SCOUTING_TIMEOUT) / 1000); - zp_sleep_s(SLEEP); + z_sleep_s(atoi(SCOUTING_TIMEOUT) / 1000); + z_sleep_s(SLEEP); z_owned_session_t s1 = z_open(z_move(_ret_config)); assert(z_check(s1)); @@ -199,13 +199,13 @@ int main(int argc, char **argv) { z_owned_closure_zid_t _ret_closure_zid = z_closure(zid_handler, NULL, NULL); _ret_int8 = z_info_peers_zid(z_loan(s1), z_move(_ret_closure_zid)); assert(_ret_int8 == 0); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); assert(zids == 0); _ret_int8 = z_info_routers_zid(z_loan(s1), z_move(_ret_closure_zid)); assert(_ret_int8 == 0); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); assert(zids == 1); #ifdef ZENOH_PICO @@ -215,7 +215,7 @@ int main(int argc, char **argv) { zp_start_lease_task(z_loan(s1), &_ret_lease_opt); #endif - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); _ret_config = z_config_default(); #ifdef ZENOH_PICO @@ -240,7 +240,7 @@ int main(int argc, char **argv) { zp_start_lease_task(z_loan(s2), NULL); #endif - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); z_session_t ls1 = z_loan(s1); z_owned_closure_sample_t _ret_closure_sample = z_closure(data_handler, NULL, &ls1); @@ -249,7 +249,7 @@ int main(int argc, char **argv) { z_declare_subscriber(z_loan(s2), z_keyexpr(keyexpr_str), z_move(_ret_closure_sample), &_ret_sub_opt); assert(z_check(_ret_sub)); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); char s1_res[64]; sprintf(s1_res, "%s/chunk/%d", keyexpr_str, 1); @@ -263,14 +263,14 @@ int main(int argc, char **argv) { _ret_int8 = z_put(z_loan(s1), z_loan(_ret_expr), (const uint8_t *)value, strlen(value), &_ret_put_opt); assert(_ret_int8 == 0); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); assert(datas == 1); z_delete_options_t _ret_delete_opt = z_delete_options_default(); _ret_int8 = z_delete(z_loan(s1), z_loan(_ret_expr), &_ret_delete_opt); assert(_ret_int8 == 0); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); assert(datas == 2); _ret_int8 = z_undeclare_keyexpr(z_loan(s1), z_move(_ret_expr)); @@ -295,23 +295,23 @@ int main(int argc, char **argv) { _ret_int8 = z_publisher_put(z_loan(_ret_pub), (const uint8_t *)value, strlen(value), &_ret_pput_opt); assert(_ret_int8 == 0); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); _ret_int8 = z_subscriber_pull(z_loan(_ret_psub)); assert(_ret_int8 == 0); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); assert(datas == 3); z_publisher_delete_options_t _ret_pdelete_opt = z_publisher_delete_options_default(); _ret_int8 = z_publisher_delete(z_loan(_ret_pub), &_ret_pdelete_opt); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); _ret_int8 = z_subscriber_pull(z_loan(_ret_psub)); assert(_ret_int8 == 0); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); assert(datas == 4); _ret_int8 = z_undeclare_publisher(z_move(_ret_pub)); @@ -320,7 +320,7 @@ int main(int argc, char **argv) { _ret_int8 = z_undeclare_pull_subscriber(z_move(_ret_psub)); assert(_ret_int8 == 0); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); z_owned_closure_query_t _ret_closure_query = z_closure(query_handler, NULL, &ls1); z_queryable_options_t _ret_qle_opt = z_queryable_options_default(); @@ -328,7 +328,7 @@ int main(int argc, char **argv) { z_declare_queryable(z_loan(s1), z_keyexpr(s1_res), z_move(_ret_closure_query), &_ret_qle_opt); assert(z_check(qle)); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); z_session_t ls2 = z_loan(s2); z_owned_closure_reply_t _ret_closure_reply = z_closure(reply_handler, NULL, &ls2); @@ -342,7 +342,7 @@ int main(int argc, char **argv) { _ret_int8 = z_get(z_loan(s2), z_keyexpr(s1_res), "", z_move(_ret_closure_reply), &_ret_get_opt); assert(_ret_int8 == 0); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); assert(queries == 1); assert(replies == 1); @@ -364,7 +364,7 @@ int main(int argc, char **argv) { _ret_int8 = z_close(z_move(s2)); assert(_ret_int8 == 0); - zp_sleep_s(SLEEP * 5); + z_sleep_s(SLEEP * 5); free(keyexpr_str); diff --git a/tests/z_int_pub_cache_query_sub_test.c b/tests/z_int_pub_cache_query_sub_test.c index 980d5d5d8..82c27b97f 100644 --- a/tests/z_int_pub_cache_query_sub_test.c +++ b/tests/z_int_pub_cache_query_sub_test.c @@ -122,7 +122,7 @@ int run_subscriber() { } SEM_POST(sem_sub); - zp_sleep_s(10); + z_sleep_s(10); z_drop(z_move(sub)); z_close(z_move(s)); diff --git a/tests/z_int_pub_sub_attachment_test.c b/tests/z_int_pub_sub_attachment_test.c index 155fc6902..c7f502a59 100644 --- a/tests/z_int_pub_sub_attachment_test.c +++ b/tests/z_int_pub_sub_attachment_test.c @@ -106,7 +106,7 @@ int run_subscriber() { } SEM_POST(sem); - zp_sleep_s(10); + z_sleep_s(10); z_undeclare_subscriber(z_move(sub)); z_close(z_move(s)); diff --git a/tests/z_int_queryable_attachment_test.c b/tests/z_int_queryable_attachment_test.c index c33d66191..ce1ac9f42 100644 --- a/tests/z_int_queryable_attachment_test.c +++ b/tests/z_int_queryable_attachment_test.c @@ -76,7 +76,7 @@ int run_queryable() { } SEM_POST(sem); - zp_sleep_s(10); + z_sleep_s(10); z_drop(z_move(qable)); z_close(z_move(s)); diff --git a/tests/z_int_queryable_test.c b/tests/z_int_queryable_test.c index d9cc4ea92..2999451c4 100644 --- a/tests/z_int_queryable_test.c +++ b/tests/z_int_queryable_test.c @@ -59,7 +59,7 @@ int run_queryable() { } SEM_POST(sem); - zp_sleep_s(10); + z_sleep_s(10); z_drop(z_move(qable)); z_close(z_move(s)); From 2f9058096a1af480e781f630dbd3ad2fb15d7ed2 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Wed, 28 Feb 2024 16:42:00 +0100 Subject: [PATCH 14/18] merge fix --- examples/z_ping.c | 6 +++--- include/zenoh_commons.h | 14 -------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/examples/z_ping.c b/examples/z_ping.c index 44b5a4d09..fdc08f71d 100644 --- a/examples/z_ping.c +++ b/examples/z_ping.c @@ -82,9 +82,9 @@ int main(int argc, char** argv) { for (int i = 0; i < args.number_of_pings; i++) { printf("%d bytes: seq=%d rtt=%luµs, lat=%luµs\n", args.size, i, results[i], results[i] / 2); } - zp_mutex_unlock(&mutex); - free(results); - free(data); + z_mutex_unlock(&mutex); + z_free(results); + z_free(data); z_drop(z_move(sub)); z_drop(z_move(pub)); z_close(z_move(session)); diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index ab0898242..e0557abfb 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -491,20 +491,6 @@ typedef struct z_condvar_t { typedef struct z_mutex_t { size_t _0; } z_mutex_t; -/** - * Condvar - * - */ -typedef struct z_condvar_t { - size_t _0; -} z_condvar_t; -/** - * Mutex - * - */ -typedef struct z_mutex_t { - size_t _0; -} z_mutex_t; /** * An owned zenoh configuration. * From 6bce28301da93fb59c9d20105adcfb21eeeaf2ef Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Wed, 28 Feb 2024 18:35:53 +0100 Subject: [PATCH 15/18] use u64 to store time instead of double --- include/zenoh_commons.h | 4 ++-- src/platform/clock.rs | 47 ++++++++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index e0557abfb..d6e5d4eb3 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -203,7 +203,7 @@ typedef struct z_owned_bytes_map_t { * Uses monotonic clock */ typedef struct z_clock_t { - double t; + uint64_t t; } z_clock_t; /** * Represents a Zenoh ID. @@ -832,7 +832,7 @@ typedef struct z_task_attr_t { * Uses system clock */ typedef struct z_time_t { - double t; + uint64_t t; } z_time_t; /** * The options for `zc_liveliness_declare_token` diff --git a/src/platform/clock.rs b/src/platform/clock.rs index ab5e3dab6..7cb5532f9 100644 --- a/src/platform/clock.rs +++ b/src/platform/clock.rs @@ -8,8 +8,11 @@ use std::{ use lazy_static::lazy_static; +// Use initial time stored in static variable as a reference time, +// to be able to return number of ns passed since. +// This is to avoid wrapping Instant into a c type and not +// have to account for its platform-dependent size and alignment. lazy_static! { - /// This is an example for using doc comment attributes static ref CLOCK_BASE: Instant = Instant::now(); } @@ -18,39 +21,44 @@ lazy_static! { #[repr(C)] #[derive(Clone, Copy)] pub struct z_clock_t { - t: f64, + t: u64, } #[no_mangle] pub extern "C" fn z_clock_now() -> z_clock_t { z_clock_t { - t: CLOCK_BASE.elapsed().as_secs_f64(), + t: CLOCK_BASE.elapsed().as_nanos() as u64, } } #[allow(clippy::missing_safety_doc)] -unsafe fn get_elapsed_seconds(time: *const z_clock_t) -> f64 { +unsafe fn get_elapsed_nanos(time: *const z_clock_t) -> u64 { if time.is_null() { - return 0.0; + return 0; + } + let now_t = z_clock_now().t; + if now_t > (*time).t { + return now_t - (*time).t; + } else { + return 0; } - z_clock_now().t - (*time).t } #[no_mangle] #[allow(clippy::missing_safety_doc)] pub unsafe extern "C" fn z_clock_elapsed_s(time: *const z_clock_t) -> u64 { - get_elapsed_seconds(time) as u64 + get_elapsed_nanos(time) / 1_000_000_000 } #[no_mangle] #[allow(clippy::missing_safety_doc)] pub unsafe extern "C" fn z_clock_elapsed_ms(time: *const z_clock_t) -> u64 { - (get_elapsed_seconds(time) * 1000.0) as u64 + get_elapsed_nanos(time) / 1_000_000 } #[no_mangle] #[allow(clippy::missing_safety_doc)] pub unsafe extern "C" fn z_clock_elapsed_us(time: *const z_clock_t) -> u64 { - (get_elapsed_seconds(time) * 1000000.0) as u64 + get_elapsed_nanos(time) / 1_000 } /// Time @@ -58,7 +66,7 @@ pub unsafe extern "C" fn z_clock_elapsed_us(time: *const z_clock_t) -> u64 { #[repr(C)] #[derive(Clone, Copy)] pub struct z_time_t { - t: f64, + t: u64, } #[no_mangle] @@ -83,31 +91,36 @@ pub extern "C" fn z_time_now() -> z_time_t { t: SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap_or(Duration::new(0, 0)) - .as_secs_f64(), + .as_nanos() as u64, } } #[allow(clippy::missing_safety_doc)] -unsafe fn get_elapsed_seconds_system_clock(time: *const z_time_t) -> f64 { +unsafe fn get_elapsed_nanos_system_clock(time: *const z_time_t) -> u64 { if time.is_null() { - return 0.0; + return 0; + } + let now_t = z_time_now().t; + if now_t > (*time).t { + return now_t - (*time).t; + } else { + return 0; } - 0.0f64.max(z_time_now().t - (*time).t) } #[no_mangle] #[allow(clippy::missing_safety_doc)] pub unsafe extern "C" fn z_time_elapsed_s(time: *const z_time_t) -> u64 { - get_elapsed_seconds_system_clock(time) as u64 + get_elapsed_nanos_system_clock(time) / 1_000_000_000 } #[no_mangle] #[allow(clippy::missing_safety_doc)] pub unsafe extern "C" fn z_time_elapsed_ms(time: *const z_time_t) -> u64 { - (get_elapsed_seconds_system_clock(time) * 1000.0) as u64 + get_elapsed_nanos_system_clock(time) / 1_000_000 } #[no_mangle] #[allow(clippy::missing_safety_doc)] pub unsafe extern "C" fn z_time_elapsed_us(time: *const z_time_t) -> u64 { - (get_elapsed_seconds_system_clock(time) * 1000000.0) as u64 + get_elapsed_nanos_system_clock(time) / 1_000 } From 6561fdc5157e8a8e5edf2a19467c9e866343979c Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Wed, 28 Feb 2024 18:44:41 +0100 Subject: [PATCH 16/18] clippy fix --- src/platform/clock.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/platform/clock.rs b/src/platform/clock.rs index 7cb5532f9..c7ed67de7 100644 --- a/src/platform/clock.rs +++ b/src/platform/clock.rs @@ -37,9 +37,9 @@ unsafe fn get_elapsed_nanos(time: *const z_clock_t) -> u64 { } let now_t = z_clock_now().t; if now_t > (*time).t { - return now_t - (*time).t; + now_t - (*time).t } else { - return 0; + 0 } } @@ -101,9 +101,9 @@ unsafe fn get_elapsed_nanos_system_clock(time: *const z_time_t) -> u64 { } let now_t = z_time_now().t; if now_t > (*time).t { - return now_t - (*time).t; + now_t - (*time).t } else { - return 0; + 0 } } From 3ffe9cadf12fb0c1f17cdadf6a02316c14f8eb6b Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Thu, 29 Feb 2024 10:35:35 +0100 Subject: [PATCH 17/18] keep base time instant reference in z_clock_t --- Cargo.lock | 50 ++++++++++++++++++++--------------------- include/zenoh_commons.h | 1 + src/platform/clock.rs | 7 +++++- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8f5719a4e..fe07a0503 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3033,7 +3033,7 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "zenoh" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "async-global-executor", "async-std", @@ -3083,7 +3083,7 @@ dependencies = [ [[package]] name = "zenoh-buffers" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "zenoh-collections", ] @@ -3115,7 +3115,7 @@ dependencies = [ [[package]] name = "zenoh-codec" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "log", "serde", @@ -3128,12 +3128,12 @@ dependencies = [ [[package]] name = "zenoh-collections" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" [[package]] name = "zenoh-config" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "flume", "json5", @@ -3152,7 +3152,7 @@ dependencies = [ [[package]] name = "zenoh-core" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "async-std", "lazy_static", @@ -3162,7 +3162,7 @@ dependencies = [ [[package]] name = "zenoh-crypto" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "aes", "hmac", @@ -3175,7 +3175,7 @@ dependencies = [ [[package]] name = "zenoh-ext" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "async-std", "bincode", @@ -3195,7 +3195,7 @@ dependencies = [ [[package]] name = "zenoh-keyexpr" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "hashbrown 0.14.0", "keyed-set", @@ -3209,7 +3209,7 @@ dependencies = [ [[package]] name = "zenoh-link" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "async-std", "async-trait", @@ -3228,7 +3228,7 @@ dependencies = [ [[package]] name = "zenoh-link-commons" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "async-std", "async-trait", @@ -3249,7 +3249,7 @@ dependencies = [ [[package]] name = "zenoh-link-quic" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "async-rustls", "async-std", @@ -3275,7 +3275,7 @@ dependencies = [ [[package]] name = "zenoh-link-tcp" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "async-std", "async-trait", @@ -3291,7 +3291,7 @@ dependencies = [ [[package]] name = "zenoh-link-tls" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "async-rustls", "async-std", @@ -3316,7 +3316,7 @@ dependencies = [ [[package]] name = "zenoh-link-udp" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "async-std", "async-trait", @@ -3335,7 +3335,7 @@ dependencies = [ [[package]] name = "zenoh-link-unixsock_stream" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "async-std", "async-trait", @@ -3353,7 +3353,7 @@ dependencies = [ [[package]] name = "zenoh-link-ws" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "async-std", "async-trait", @@ -3373,7 +3373,7 @@ dependencies = [ [[package]] name = "zenoh-macros" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "proc-macro2", "quote", @@ -3386,7 +3386,7 @@ dependencies = [ [[package]] name = "zenoh-plugin-trait" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "const_format", "libloading", @@ -3402,7 +3402,7 @@ dependencies = [ [[package]] name = "zenoh-protocol" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "const_format", "hex", @@ -3418,7 +3418,7 @@ dependencies = [ [[package]] name = "zenoh-result" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "anyhow", ] @@ -3426,7 +3426,7 @@ dependencies = [ [[package]] name = "zenoh-shm" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "bincode", "log", @@ -3439,7 +3439,7 @@ dependencies = [ [[package]] name = "zenoh-sync" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "async-std", "event-listener 4.0.0", @@ -3454,7 +3454,7 @@ dependencies = [ [[package]] name = "zenoh-transport" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "async-executor", "async-global-executor", @@ -3486,7 +3486,7 @@ dependencies = [ [[package]] name = "zenoh-util" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#7d9d684cf953f9f813eb320812eaf95f767ef200" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" dependencies = [ "async-std", "async-trait", diff --git a/include/zenoh_commons.h b/include/zenoh_commons.h index d6e5d4eb3..75410f80a 100644 --- a/include/zenoh_commons.h +++ b/include/zenoh_commons.h @@ -204,6 +204,7 @@ typedef struct z_owned_bytes_map_t { */ typedef struct z_clock_t { uint64_t t; + const void *t_base; } z_clock_t; /** * Represents a Zenoh ID. diff --git a/src/platform/clock.rs b/src/platform/clock.rs index c7ed67de7..3f2c91c17 100644 --- a/src/platform/clock.rs +++ b/src/platform/clock.rs @@ -2,6 +2,7 @@ use chrono::{DateTime, Local}; use libc::c_char; use std::{ cmp::min, + os::raw::c_void, slice, time::{Duration, Instant, SystemTime, UNIX_EPOCH}, }; @@ -22,12 +23,14 @@ lazy_static! { #[derive(Clone, Copy)] pub struct z_clock_t { t: u64, + t_base: *const c_void, } #[no_mangle] pub extern "C" fn z_clock_now() -> z_clock_t { z_clock_t { t: CLOCK_BASE.elapsed().as_nanos() as u64, + t_base: &CLOCK_BASE as *const CLOCK_BASE as *const c_void, } } #[allow(clippy::missing_safety_doc)] @@ -35,7 +38,9 @@ unsafe fn get_elapsed_nanos(time: *const z_clock_t) -> u64 { if time.is_null() { return 0; } - let now_t = z_clock_now().t; + let now_t = (*((*time).t_base as *const CLOCK_BASE)) + .elapsed() + .as_nanos() as u64; if now_t > (*time).t { now_t - (*time).t } else { From 870bc064a0d15aec3893ad129d21870045dc54ae Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Wed, 6 Mar 2024 10:13:25 +0100 Subject: [PATCH 18/18] cargo.lock update --- Cargo.lock | 333 +++++++++++------------------------------------------ 1 file changed, 69 insertions(+), 264 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fe07a0503..9d60a060b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -70,54 +70,6 @@ dependencies = [ "libc", ] -[[package]] -name = "anstream" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b84bf0a05bbb2a83e5eb6fa36bb6e87baa08193c35ff52bbf6b38d8af2890e46" - -[[package]] -name = "anstyle-parse" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" -dependencies = [ - "windows-sys 0.48.0", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" -dependencies = [ - "anstyle", - "windows-sys 0.52.0", -] - [[package]] name = "anyhow" version = "1.0.75" @@ -225,7 +177,7 @@ dependencies = [ "futures-lite", "rustix 0.37.25", "signal-hook", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -408,7 +360,7 @@ version = "0.24.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b922faaf31122819ec80c4047cc684c6979a087366c069611e33649bf98e18d" dependencies = [ - "clap 3.2.25", + "clap", "heck", "indexmap 1.9.3", "log", @@ -447,7 +399,7 @@ dependencies = [ "js-sys", "num-traits", "wasm-bindgen", - "windows-targets 0.52.0", + "windows-targets 0.52.4", ] [[package]] @@ -468,47 +420,13 @@ checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "atty", "bitflags 1.3.2", - "clap_lex 0.2.4", + "clap_lex", "indexmap 1.9.3", "strsim", "termcolor", "textwrap", ] -[[package]] -name = "clap" -version = "4.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfaff671f6b22ca62406885ece523383b9b64022e341e53e009a62ebc47a45f2" -dependencies = [ - "clap_builder", - "clap_derive", -] - -[[package]] -name = "clap_builder" -version = "4.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a216b506622bb1d316cd51328dce24e07bdff4a6128a47c7e7fad11878d5adbb" -dependencies = [ - "anstream", - "anstyle", - "clap_lex 0.6.0", - "strsim", -] - -[[package]] -name = "clap_derive" -version = "4.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn 2.0.33", -] - [[package]] name = "clap_lex" version = "0.2.4" @@ -518,18 +436,6 @@ dependencies = [ "os_str_bytes", ] -[[package]] -name = "clap_lex" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" - -[[package]] -name = "colorchoice" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" - [[package]] name = "concurrent-queue" version = "2.2.0" @@ -656,7 +562,7 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -692,7 +598,7 @@ checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" dependencies = [ "errno-dragonfly", "libc", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -935,12 +841,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "glob" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" - [[package]] name = "gloo-timers" version = "0.2.6" @@ -999,12 +899,6 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - [[package]] name = "hmac" version = "0.12.1" @@ -1020,7 +914,7 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -1125,7 +1019,7 @@ checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ "hermit-abi 0.3.2", "libc", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -1145,7 +1039,7 @@ checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi 0.3.2", "rustix 0.38.21", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -1223,7 +1117,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d580318f95776505201b28cf98eb1fa5e4be3b689633ba6a3e6cd880ff22d8cb" dependencies = [ "cfg-if", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -1304,7 +1198,7 @@ checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", "wasi", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -1561,20 +1455,6 @@ dependencies = [ "spki", ] -[[package]] -name = "pnet" -version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "130c5b738eeda2dc5796fe2671e49027e6935e817ab51b930a36ec9e6a206a64" -dependencies = [ - "ipnetwork", - "pnet_base", - "pnet_datalink", - "pnet_packet", - "pnet_sys", - "pnet_transport", -] - [[package]] name = "pnet_base" version = "0.34.0" @@ -1597,39 +1477,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "pnet_macros" -version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "688b17499eee04a0408aca0aa5cba5fc86401d7216de8a63fdf7a4c227871804" -dependencies = [ - "proc-macro2", - "quote", - "regex", - "syn 2.0.33", -] - -[[package]] -name = "pnet_macros_support" -version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eea925b72f4bd37f8eab0f221bbe4c78b63498350c983ffa9dd4bcde7e030f56" -dependencies = [ - "pnet_base", -] - -[[package]] -name = "pnet_packet" -version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a005825396b7fe7a38a8e288dbc342d5034dac80c15212436424fef8ea90ba" -dependencies = [ - "glob", - "pnet_base", - "pnet_macros", - "pnet_macros_support", -] - [[package]] name = "pnet_sys" version = "0.34.0" @@ -1640,18 +1487,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "pnet_transport" -version = "0.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2637e14d7de974ee2f74393afccbc8704f3e54e6eb31488715e72481d1662cc3" -dependencies = [ - "libc", - "pnet_base", - "pnet_packet", - "pnet_sys", -] - [[package]] name = "polling" version = "2.8.0" @@ -1665,7 +1500,7 @@ dependencies = [ "libc", "log", "pin-project-lite", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -1734,7 +1569,7 @@ dependencies = [ "libc", "socket2 0.5.4", "tracing", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -1860,7 +1695,7 @@ dependencies = [ "libc", "spin 0.9.8", "untrusted 0.9.0", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -1927,7 +1762,7 @@ dependencies = [ "io-lifetimes", "libc", "linux-raw-sys 0.3.8", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -1940,7 +1775,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.4.13", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -2038,7 +1873,7 @@ version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" dependencies = [ - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -2290,7 +2125,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e" dependencies = [ "libc", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -2380,7 +2215,7 @@ dependencies = [ "fastrand 2.0.1", "redox_syscall 0.4.1", "rustix 0.38.21", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -2456,7 +2291,7 @@ dependencies = [ "pin-project-lite", "socket2 0.5.4", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -2652,12 +2487,6 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" -[[package]] -name = "utf8parse" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" - [[package]] name = "uuid" version = "1.4.1" @@ -2865,7 +2694,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.0", + "windows-targets 0.52.4", ] [[package]] @@ -2877,15 +2706,6 @@ dependencies = [ "windows-targets 0.48.5", ] -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.0", -] - [[package]] name = "windows-targets" version = "0.48.5" @@ -2903,17 +2723,17 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" dependencies = [ - "windows_aarch64_gnullvm 0.52.0", - "windows_aarch64_msvc 0.52.0", - "windows_i686_gnu 0.52.0", - "windows_i686_msvc 0.52.0", - "windows_x86_64_gnu 0.52.0", - "windows_x86_64_gnullvm 0.52.0", - "windows_x86_64_msvc 0.52.0", + "windows_aarch64_gnullvm 0.52.4", + "windows_aarch64_msvc 0.52.4", + "windows_i686_gnu 0.52.4", + "windows_i686_msvc 0.52.4", + "windows_x86_64_gnu 0.52.4", + "windows_x86_64_gnullvm 0.52.4", + "windows_x86_64_msvc 0.52.4", ] [[package]] @@ -2924,9 +2744,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" [[package]] name = "windows_aarch64_msvc" @@ -2942,9 +2762,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" [[package]] name = "windows_i686_gnu" @@ -2960,9 +2780,9 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" [[package]] name = "windows_i686_msvc" @@ -2978,9 +2798,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" [[package]] name = "windows_x86_64_gnu" @@ -2996,9 +2816,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" [[package]] name = "windows_x86_64_gnullvm" @@ -3008,9 +2828,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" [[package]] name = "windows_x86_64_msvc" @@ -3026,14 +2846,14 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.0" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" [[package]] name = "zenoh" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "async-global-executor", "async-std", @@ -3046,7 +2866,6 @@ dependencies = [ "form_urlencoded", "futures", "git-version", - "hex", "lazy_static", "log", "ordered-float", @@ -3083,7 +2902,7 @@ dependencies = [ [[package]] name = "zenoh-buffers" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "zenoh-collections", ] @@ -3115,7 +2934,7 @@ dependencies = [ [[package]] name = "zenoh-codec" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "log", "serde", @@ -3128,12 +2947,12 @@ dependencies = [ [[package]] name = "zenoh-collections" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" [[package]] name = "zenoh-config" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "flume", "json5", @@ -3152,7 +2971,7 @@ dependencies = [ [[package]] name = "zenoh-core" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "async-std", "lazy_static", @@ -3162,7 +2981,7 @@ dependencies = [ [[package]] name = "zenoh-crypto" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "aes", "hmac", @@ -3175,7 +2994,7 @@ dependencies = [ [[package]] name = "zenoh-ext" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "async-std", "bincode", @@ -3195,7 +3014,7 @@ dependencies = [ [[package]] name = "zenoh-keyexpr" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "hashbrown 0.14.0", "keyed-set", @@ -3209,7 +3028,7 @@ dependencies = [ [[package]] name = "zenoh-link" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "async-std", "async-trait", @@ -3228,15 +3047,13 @@ dependencies = [ [[package]] name = "zenoh-link-commons" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "async-std", "async-trait", "flume", "log", - "lz4_flex", "serde", - "typenum", "zenoh-buffers", "zenoh-codec", "zenoh-core", @@ -3249,7 +3066,7 @@ dependencies = [ [[package]] name = "zenoh-link-quic" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "async-rustls", "async-std", @@ -3275,7 +3092,7 @@ dependencies = [ [[package]] name = "zenoh-link-tcp" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "async-std", "async-trait", @@ -3291,7 +3108,7 @@ dependencies = [ [[package]] name = "zenoh-link-tls" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "async-rustls", "async-std", @@ -3316,7 +3133,7 @@ dependencies = [ [[package]] name = "zenoh-link-udp" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "async-std", "async-trait", @@ -3335,7 +3152,7 @@ dependencies = [ [[package]] name = "zenoh-link-unixsock_stream" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "async-std", "async-trait", @@ -3353,7 +3170,7 @@ dependencies = [ [[package]] name = "zenoh-link-ws" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "async-std", "async-trait", @@ -3373,20 +3190,18 @@ dependencies = [ [[package]] name = "zenoh-macros" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "proc-macro2", "quote", - "rustc_version", "syn 2.0.33", - "unzip-n", "zenoh-keyexpr", ] [[package]] name = "zenoh-plugin-trait" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "const_format", "libloading", @@ -3402,14 +3217,12 @@ dependencies = [ [[package]] name = "zenoh-protocol" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "const_format", - "hex", "rand", "serde", "uhlc", - "uuid", "zenoh-buffers", "zenoh-keyexpr", "zenoh-result", @@ -3418,7 +3231,7 @@ dependencies = [ [[package]] name = "zenoh-result" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "anyhow", ] @@ -3426,9 +3239,8 @@ dependencies = [ [[package]] name = "zenoh-shm" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ - "bincode", "log", "serde", "shared_memory", @@ -3439,11 +3251,10 @@ dependencies = [ [[package]] name = "zenoh-sync" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "async-std", "event-listener 4.0.0", - "flume", "futures", "tokio", "zenoh-buffers", @@ -3454,7 +3265,7 @@ dependencies = [ [[package]] name = "zenoh-transport" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "async-executor", "async-global-executor", @@ -3486,27 +3297,21 @@ dependencies = [ [[package]] name = "zenoh-util" version = "0.11.0-dev" -source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#01ae772100f416da1b6dc023cedf2760f3e5e0eb" +source = "git+https://github.com/eclipse-zenoh/zenoh.git?branch=main#f2e99b6fe07bf7899a458e0a16bfe85e3cdebca6" dependencies = [ "async-std", "async-trait", - "clap 4.4.11", - "const_format", "flume", - "futures", - "hex", "home", "humantime", "lazy_static", "libc", "libloading", "log", - "pnet", "pnet_datalink", "shellexpand", "winapi", "zenoh-core", - "zenoh-protocol", "zenoh-result", ]