diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c32d9bb1..46c7a6a37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -215,6 +215,7 @@ target_include_directories(${Libname} PUBLIC ${PROJECT_SOURCE_DIR}/include) file(GLOB_RECURSE Sources "src/api/*.c" "src/collections/*.c" + "src/deprecated/*.c" "src/link/*.c" "src/net/*.c" "src/protocol/*.c" diff --git a/docs/requirements.txt b/docs/requirements.txt index 670562c3e..a5a4b5f60 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,4 +1,4 @@ -sphinx==4.5.0 -sphinx_c_autodoc -sphinx_rtd_theme -clang==14 +sphinx==7.2.6 +sphinx_c_autodoc==1.3.0 +sphinx_rtd_theme==2.0.0 +clang==14.0 diff --git a/examples/freertos_plus_tcp/z_get.c b/examples/freertos_plus_tcp/z_get.c index 6abd0175e..09c1d3507 100644 --- a/examples/freertos_plus_tcp/z_get.c +++ b/examples/freertos_plus_tcp/z_get.c @@ -76,7 +76,7 @@ void app_main(void) { } while (1) { - zp_sleep_s(5); + z_sleep_s(5); printf("Sending Query '%s'...\n", KEYEXPR); z_get_options_t opts = z_get_options_default(); if (strcmp(VALUE, "") != 0) { diff --git a/examples/freertos_plus_tcp/z_pub.c b/examples/freertos_plus_tcp/z_pub.c index c2d8ca55b..abb4594f4 100644 --- a/examples/freertos_plus_tcp/z_pub.c +++ b/examples/freertos_plus_tcp/z_pub.c @@ -48,7 +48,7 @@ void app_main(void) { static StackType_t read_task_stack[1000]; static StaticTask_t read_task_buffer; - zp_task_attr_t read_task_attr = { + z_task_attr_t read_task_attr = { .name = "ZenohReadTask", .priority = 10, .stack_depth = 1000, @@ -62,7 +62,7 @@ void app_main(void) { static StackType_t lease_task_stack[1000]; static StaticTask_t lease_task_buffer; - zp_task_attr_t lease_task_attr = { + z_task_attr_t lease_task_attr = { .name = "ZenohLeaseTask", .priority = 10, .stack_depth = 1000, @@ -89,7 +89,7 @@ void app_main(void) { char *buf = (char *)pvPortMalloc(256); for (int idx = 0; 1; ++idx) { - zp_sleep_s(1); + z_sleep_s(1); snprintf(buf, 256, "[%4d] %s", idx, VALUE); printf("Putting Data ('%s': '%s')...\n", KEYEXPR, buf); diff --git a/examples/freertos_plus_tcp/z_pub_st.c b/examples/freertos_plus_tcp/z_pub_st.c index 49b7761eb..03311e25c 100644 --- a/examples/freertos_plus_tcp/z_pub_st.c +++ b/examples/freertos_plus_tcp/z_pub_st.c @@ -53,15 +53,15 @@ void app_main(void) { } char *buf = (char *)pvPortMalloc(256); - zp_clock_t now = zp_clock_now(); + z_clock_t now = z_clock_now(); for (int idx = 0; 1;) { - if (zp_clock_elapsed_ms(&now) > 1000) { + if (z_clock_elapsed_ms(&now) > 1000) { snprintf(buf, 256, "[%4d] %s", idx, VALUE); printf("Putting Data ('%s': '%s')...\n", KEYEXPR, buf); z_publisher_put(z_loan(pub), (const uint8_t *)buf, strlen(buf), NULL); ++idx; - now = zp_clock_now(); + now = z_clock_now(); } zp_read(z_loan(s), NULL); diff --git a/examples/freertos_plus_tcp/z_pull.c b/examples/freertos_plus_tcp/z_pull.c index b8f5c5ee8..af7839902 100644 --- a/examples/freertos_plus_tcp/z_pull.c +++ b/examples/freertos_plus_tcp/z_pull.c @@ -66,7 +66,7 @@ void app_main(void) { } while (1) { - zp_sleep_s(5); + z_sleep_s(5); printf("Pulling data from '%s'...\n", KEYEXPR); z_subscriber_pull(z_loan(sub)); } diff --git a/examples/freertos_plus_tcp/z_put.c b/examples/freertos_plus_tcp/z_put.c index 898d0e9b8..1253af540 100644 --- a/examples/freertos_plus_tcp/z_put.c +++ b/examples/freertos_plus_tcp/z_put.c @@ -68,7 +68,7 @@ void app_main(void) { } while (1) { - zp_sleep_s(1); + z_sleep_s(1); } // Clean up diff --git a/examples/freertos_plus_tcp/z_queryable.c b/examples/freertos_plus_tcp/z_queryable.c index 0d9ce87e4..49a925ced 100644 --- a/examples/freertos_plus_tcp/z_queryable.c +++ b/examples/freertos_plus_tcp/z_queryable.c @@ -80,7 +80,7 @@ void app_main(void) { } while (1) { - zp_sleep_s(5); + z_sleep_s(5); } z_undeclare_queryable(z_move(qable)); diff --git a/examples/freertos_plus_tcp/z_sub.c b/examples/freertos_plus_tcp/z_sub.c index 91395e59f..3bae862b4 100644 --- a/examples/freertos_plus_tcp/z_sub.c +++ b/examples/freertos_plus_tcp/z_sub.c @@ -66,7 +66,7 @@ void app_main(void) { } while (1) { - zp_sleep_s(5); + z_sleep_s(5); } z_undeclare_subscriber(z_move(sub)); diff --git a/examples/mbed/z_get.cpp b/examples/mbed/z_get.cpp index 21e77c33d..905ac4e1c 100644 --- a/examples/mbed/z_get.cpp +++ b/examples/mbed/z_get.cpp @@ -72,7 +72,7 @@ int main(int argc, char **argv) { zp_start_lease_task(z_session_loan(&s), NULL); while (1) { - zp_sleep_s(5); + z_sleep_s(5); printf("Sending Query '%s'...\n", KEYEXPR); z_get_options_t opts = z_get_options_default(); if (strcmp(VALUE, "") != 0) { diff --git a/examples/mbed/z_pub.cpp b/examples/mbed/z_pub.cpp index 7ef9f1dc4..0fb939071 100644 --- a/examples/mbed/z_pub.cpp +++ b/examples/mbed/z_pub.cpp @@ -68,7 +68,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(z_publisher_loan(&pub), (const uint8_t *)buf, strlen(buf), NULL); diff --git a/examples/mbed/z_pull.cpp b/examples/mbed/z_pull.cpp index 4bcd33ed5..d6b82c1d0 100644 --- a/examples/mbed/z_pull.cpp +++ b/examples/mbed/z_pull.cpp @@ -75,7 +75,7 @@ int main(int argc, char **argv) { printf("OK!\n"); while (1) { - zp_sleep_s(5); + z_sleep_s(5); printf("Pulling data from '%s'...\n", KEYEXPR); z_subscriber_pull(z_pull_subscriber_loan(&sub)); } diff --git a/examples/mbed/z_queryable.cpp b/examples/mbed/z_queryable.cpp index b2f597d58..08ade9084 100644 --- a/examples/mbed/z_queryable.cpp +++ b/examples/mbed/z_queryable.cpp @@ -80,7 +80,7 @@ int main(int argc, char **argv) { printf("Zenoh setup finished!\n"); while (1) { - zp_sleep_s(5); + z_sleep_s(5); } printf("Closing Zenoh Session..."); diff --git a/examples/mbed/z_sub.cpp b/examples/mbed/z_sub.cpp index 62ac126d3..0b3cbdd47 100644 --- a/examples/mbed/z_sub.cpp +++ b/examples/mbed/z_sub.cpp @@ -75,7 +75,7 @@ int main(int argc, char **argv) { printf("OK!\n"); while (1) { - zp_sleep_s(5); + z_sleep_s(5); } printf("Closing Zenoh Session..."); diff --git a/examples/unix/c11/z_ping.c b/examples/unix/c11/z_ping.c index 564cbc365..f4da4dd18 100644 --- a/examples/unix/c11/z_ping.c +++ b/examples/unix/c11/z_ping.c @@ -27,17 +27,17 @@ #define DEFAULT_PING_NB 100 #define DEFAULT_WARMUP_MS 1000 -static zp_condvar_t cond; -static zp_mutex_t mutex; +static z_condvar_t cond; +static z_mutex_t mutex; void callback(const z_sample_t* sample, void* context) { (void)sample; (void)context; - zp_condvar_signal(&cond); + z_condvar_signal(&cond); } void drop(void* context) { (void)context; - zp_condvar_free(&cond); + z_condvar_free(&cond); } struct args_t { @@ -61,8 +61,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 = z_config_default(); z_owned_session_t session = z_open(z_move(config)); if (!z_check(session)) { @@ -92,34 +92,34 @@ int main(int argc, char** argv) { return -1; } - uint8_t* data = zp_malloc(args.size); + uint8_t* data = z_malloc(args.size); for (unsigned int i = 0; i < args.size; i++) { data[i] = (uint8_t)(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(); + z_clock_t warmup_start = z_clock_now(); unsigned long elapsed_us = 0; while (elapsed_us < args.warmup_ms * 1000) { z_publisher_put(z_loan(pub), data, args.size, NULL); - zp_condvar_wait(&cond, &mutex); - elapsed_us = zp_clock_elapsed_us(&warmup_start); + z_condvar_wait(&cond, &mutex); + elapsed_us = z_clock_elapsed_us(&warmup_start); } } - unsigned long* results = zp_malloc(sizeof(unsigned long) * args.number_of_pings); + unsigned long* results = z_malloc(sizeof(unsigned long) * args.number_of_pings); for (unsigned 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); - zp_condvar_wait(&cond, &mutex); - results[i] = zp_clock_elapsed_us(&measure_start); + z_condvar_wait(&cond, &mutex); + results[i] = z_clock_elapsed_us(&measure_start); } for (unsigned 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); - zp_free(results); - zp_free(data); + z_mutex_unlock(&mutex); + z_free(results); + z_free(data); z_drop(z_move(pub)); z_drop(z_move(sub)); diff --git a/examples/unix/c11/z_sub_thr.c b/examples/unix/c11/z_sub_thr.c index 39e3e894a..485ba9575 100644 --- a/examples/unix/c11/z_sub_thr.c +++ b/examples/unix/c11/z_sub_thr.c @@ -24,8 +24,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; } z_stats_t; #if Z_FEATURE_SUBSCRIPTION == 1 @@ -44,14 +44,14 @@ void on_sample(const z_sample_t *sample, void *context) { stats->count++; // Start set measurement if (stats->count == 1) { - stats->start = zp_clock_now(); + stats->start = z_clock_now(); if (stats->first_start.tv_nsec == 0) { stats->first_start = stats->start; } } else if (stats->count >= PACKET_NB) { // Stop set measurement stats->finished_rounds++; - unsigned long elapsed_ms = zp_clock_elapsed_ms(&stats->start); + unsigned long elapsed_ms = z_clock_elapsed_ms(&stats->start); printf("Received %d msg in %lu ms (%.1f msg/s)\n", PACKET_NB, elapsed_ms, (double)(PACKET_NB * 1000) / (double)elapsed_ms); stats->count = 0; @@ -60,7 +60,7 @@ void on_sample(const z_sample_t *sample, void *context) { void drop_stats(void *context) { z_stats_t *stats = (z_stats_t *)context; - unsigned long elapsed_ms = zp_clock_elapsed_ms(&stats->first_start); + unsigned long elapsed_ms = z_clock_elapsed_ms(&stats->first_start); const unsigned long sent_messages = PACKET_NB * stats->finished_rounds + stats->count; printf("Stats after unsubscribing: received %ld messages over %lu miliseconds (%.1f msg/s)\n", sent_messages, elapsed_ms, (double)(sent_messages * 1000) / (double)elapsed_ms); @@ -106,7 +106,7 @@ int main(int argc, char **argv) { } // Wait for everything to settle printf("End of test\n"); - zp_sleep_s(1); + z_sleep_s(1); // Clean up z_undeclare_subscriber(z_move(sub)); zp_stop_read_task(z_loan(s)); diff --git a/examples/unix/c99/z_ping.c b/examples/unix/c99/z_ping.c index 3bcafece7..673943898 100644 --- a/examples/unix/c99/z_ping.c +++ b/examples/unix/c99/z_ping.c @@ -28,17 +28,17 @@ #define DEFAULT_PING_NB 100 #define DEFAULT_WARMUP_MS 1000 -static zp_condvar_t cond; -static zp_mutex_t mutex; +static z_condvar_t cond; +static z_mutex_t mutex; void callback(const z_sample_t* sample, void* context) { (void)sample; (void)context; - zp_condvar_signal(&cond); + z_condvar_signal(&cond); } void drop(void* context) { (void)context; - zp_condvar_free(&cond); + z_condvar_free(&cond); } struct args_t { @@ -62,8 +62,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 = z_config_default(); z_owned_session_t session = z_open(z_config_move(&config)); if (!z_session_check(&session)) { @@ -94,34 +94,34 @@ int main(int argc, char** argv) { return -1; } - uint8_t* data = zp_malloc(args.size); + uint8_t* data = z_malloc(args.size); for (unsigned int i = 0; i < args.size; i++) { data[i] = (uint8_t)(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(); + z_clock_t warmup_start = z_clock_now(); unsigned long elapsed_us = 0; while (elapsed_us < args.warmup_ms * 1000) { z_publisher_put(z_publisher_loan(&pub), data, args.size, NULL); - zp_condvar_wait(&cond, &mutex); - elapsed_us = zp_clock_elapsed_us(&warmup_start); + z_condvar_wait(&cond, &mutex); + elapsed_us = z_clock_elapsed_us(&warmup_start); } } - unsigned long* results = zp_malloc(sizeof(unsigned long) * args.number_of_pings); + unsigned long* results = z_malloc(sizeof(unsigned long) * args.number_of_pings); for (unsigned 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_publisher_loan(&pub), data, args.size, NULL); - zp_condvar_wait(&cond, &mutex); - results[i] = zp_clock_elapsed_us(&measure_start); + z_condvar_wait(&cond, &mutex); + results[i] = z_clock_elapsed_us(&measure_start); } for (unsigned 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); - zp_free(results); - zp_free(data); + z_mutex_unlock(&mutex); + z_free(results); + z_free(data); z_undeclare_subscriber(z_subscriber_move(&sub)); z_undeclare_publisher(z_publisher_move(&pub)); diff --git a/examples/unix/c99/z_pub_st.c b/examples/unix/c99/z_pub_st.c index 1bbaef106..44592adc8 100644 --- a/examples/unix/c99/z_pub_st.c +++ b/examples/unix/c99/z_pub_st.c @@ -81,15 +81,15 @@ int main(int argc, char **argv) { } char *buf = (char *)malloc(256); - zp_clock_t now = zp_clock_now(); + z_clock_t now = z_clock_now(); for (int idx = 0; 1;) { - if (zp_clock_elapsed_ms(&now) > 1000) { + if (z_clock_elapsed_ms(&now) > 1000) { snprintf(buf, 256, "[%4d] %s", idx, value); printf("Putting Data ('%s': '%s')...\n", keyexpr, buf); z_publisher_put(z_publisher_loan(&pub), (const uint8_t *)buf, strlen(buf), NULL); ++idx; - now = zp_clock_now(); + now = z_clock_now(); } zp_read(z_session_loan(&s), NULL); diff --git a/examples/windows/z_ping.c b/examples/windows/z_ping.c index 5643832c0..262e21659 100644 --- a/examples/windows/z_ping.c +++ b/examples/windows/z_ping.c @@ -27,17 +27,17 @@ #define DEFAULT_PING_NB 100 #define DEFAULT_WARMUP_MS 1000 -static zp_condvar_t cond; -static zp_mutex_t mutex; +static z_condvar_t cond; +static z_mutex_t mutex; void callback(const z_sample_t* sample, void* context) { (void)sample; (void)context; - zp_condvar_signal(&cond); + z_condvar_signal(&cond); } void drop(void* context) { (void)context; - zp_condvar_free(&cond); + z_condvar_free(&cond); } struct args_t { @@ -61,8 +61,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 = z_config_default(); z_owned_session_t session = z_open(z_move(config)); if (!z_check(session)) { @@ -91,34 +91,34 @@ int main(int argc, char** argv) { return -1; } - uint8_t* data = zp_malloc(args.size); + uint8_t* data = z_malloc(args.size); for (unsigned 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(); + z_clock_t warmup_start = z_clock_now(); unsigned long elapsed_us = 0; while (elapsed_us < args.warmup_ms * 1000) { z_publisher_put(z_loan(pub), data, args.size, NULL); - zp_condvar_wait(&cond, &mutex); - elapsed_us = zp_clock_elapsed_us(&warmup_start); + z_condvar_wait(&cond, &mutex); + elapsed_us = z_clock_elapsed_us(&warmup_start); } } - unsigned long* results = zp_malloc(sizeof(unsigned long) * args.number_of_pings); + unsigned long* results = z_malloc(sizeof(unsigned long) * args.number_of_pings); for (unsigned 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); - zp_condvar_wait(&cond, &mutex); - results[i] = zp_clock_elapsed_us(&measure_start); + z_condvar_wait(&cond, &mutex); + results[i] = z_clock_elapsed_us(&measure_start); } for (unsigned int i = 0; i < args.number_of_pings; i++) { printf("%d bytes: seq=%d rtt=%luus, lat=%luus\n", args.size, i, results[i], results[i] / 2); } - zp_mutex_unlock(&mutex); - zp_free(results); - zp_free(data); + z_mutex_unlock(&mutex); + z_free(results); + z_free(data); z_drop(z_move(pub)); z_drop(z_move(sub)); diff --git a/examples/windows/z_pub_st.c b/examples/windows/z_pub_st.c index 8adea5c53..cc6f41361 100644 --- a/examples/windows/z_pub_st.c +++ b/examples/windows/z_pub_st.c @@ -48,15 +48,15 @@ int main(int argc, char **argv) { } char *buf = (char *)malloc(256); - zp_clock_t now = zp_clock_now(); + z_clock_t now = z_clock_now(); for (int idx = 0; 1;) { - if (zp_clock_elapsed_ms(&now) > 1000) { + if (z_clock_elapsed_ms(&now) > 1000) { snprintf(buf, 256, "[%4d] %s", idx, value); printf("Putting Data ('%s': '%s')...\n", keyexpr, buf); z_publisher_put(z_loan(pub), (const uint8_t *)buf, strlen(buf), NULL); ++idx; - now = zp_clock_now(); + now = z_clock_now(); } zp_read(z_loan(s), NULL); diff --git a/include/zenoh-pico/api/primitives.h b/include/zenoh-pico/api/primitives.h index 76cf03f4b..54a36618e 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -120,7 +120,7 @@ _Bool zp_keyexpr_was_declared(const z_keyexpr_t *keyexpr); /** * Constructs a null-terminated string departing from a :c:type:`z_keyexpr_t` for a given :c:type:`z_session_t`. - * The user is responsible of dropping the returned string using ``zp_free``. + * The user is responsible of dropping the returned string using ``z_free``. * * Parameters: * zs: A loaned instance of the the :c:type:`z_session_t` to resolve the keyexpr. diff --git a/include/zenoh-pico/api/types.h b/include/zenoh-pico/api/types.h index c691cac13..339e04654 100644 --- a/include/zenoh-pico/api/types.h +++ b/include/zenoh-pico/api/types.h @@ -418,7 +418,7 @@ typedef struct { typedef struct { #if Z_FEATURE_MULTI_THREAD == 1 // tags{c.zp_task_read_options_t.task_attributes} - zp_task_attr_t *task_attributes; + z_task_attr_t *task_attributes; #else uint8_t __dummy; // Just to avoid empty structures that might cause undefined behavior #endif @@ -432,7 +432,7 @@ typedef struct { typedef struct { #if Z_FEATURE_MULTI_THREAD == 1 // tags{c.zp_task_lease_options_t.task_attributes} - zp_task_attr_t *task_attributes; + z_task_attr_t *task_attributes; #else uint8_t __dummy; // Just to avoid empty structures that might cause undefined behavior #endif diff --git a/include/zenoh-pico/collections/array.h b/include/zenoh-pico/collections/array.h index a54a66af3..fe2b3f306 100644 --- a/include/zenoh-pico/collections/array.h +++ b/include/zenoh-pico/collections/array.h @@ -33,7 +33,7 @@ } \ static inline name##_array_t name##_array_make(size_t capacity) { \ name##_array_t a; \ - a._val = (type *)zp_malloc(capacity * sizeof(type)); \ + a._val = (type *)z_malloc(capacity * sizeof(type)); \ if (a._val != NULL) { \ a._len = capacity; \ } else { \ @@ -58,7 +58,7 @@ for (size_t i = 0; i < a->_len; i++) { \ name##_elem_clear(&a->_val[i]); \ } \ - zp_free(a->_val); \ + z_free(a->_val); \ a->_len = 0; \ a->_val = NULL; \ } \ @@ -66,7 +66,7 @@ name##_array_t *ptr = *a; \ if (ptr != NULL) { \ name##_array_clear(ptr); \ - zp_free(ptr); \ + z_free(ptr); \ *a = NULL; \ } \ } diff --git a/include/zenoh-pico/collections/element.h b/include/zenoh-pico/collections/element.h index 5e8997954..96a62e4eb 100644 --- a/include/zenoh-pico/collections/element.h +++ b/include/zenoh-pico/collections/element.h @@ -35,13 +35,13 @@ typedef _Bool (*z_element_eq_f)(const void *left, const void *right); type *ptr = (type *)*e; \ if (ptr != NULL) { \ elem_clear_f(ptr); \ - zp_free(ptr); \ + z_free(ptr); \ *e = NULL; \ } \ } \ static inline void name##_elem_copy(void *dst, const void *src) { elem_copy_f((type *)dst, (type *)src); } \ static inline void *name##_elem_clone(const void *src) { \ - type *dst = (type *)zp_malloc(elem_size_f((type *)src)); \ + type *dst = (type *)z_malloc(elem_size_f((type *)src)); \ if (dst != NULL) { \ elem_copy_f(dst, (type *)src); \ } \ diff --git a/include/zenoh-pico/collections/intmap.h b/include/zenoh-pico/collections/intmap.h index 1d33d8afc..caa54e035 100644 --- a/include/zenoh-pico/collections/intmap.h +++ b/include/zenoh-pico/collections/intmap.h @@ -70,7 +70,7 @@ void _z_int_void_map_free(_z_int_void_map_t **map, z_element_free_f f); name##_intmap_entry_t *ptr = (name##_intmap_entry_t *)*e; \ if (ptr != NULL) { \ name##_elem_free(&ptr->_val); \ - zp_free(ptr); \ + z_free(ptr); \ *e = NULL; \ } \ } \ diff --git a/include/zenoh-pico/collections/refcount.h b/include/zenoh-pico/collections/refcount.h index c348d16b7..de12ffdea 100644 --- a/include/zenoh-pico/collections/refcount.h +++ b/include/zenoh-pico/collections/refcount.h @@ -94,7 +94,7 @@ } name##_rc_t; \ static inline name##_rc_t name##_rc_new(void) { \ name##_rc_t p; \ - p.in = (name##_inner_rc_t *)zp_malloc(sizeof(name##_inner_rc_t)); \ + p.in = (name##_inner_rc_t *)z_malloc(sizeof(name##_inner_rc_t)); \ if (p.in != NULL) { \ memset(&p.in->val, 0, sizeof(type##_t)); \ _ZP_RC_OP_INIT_CNT \ @@ -103,7 +103,7 @@ } \ static inline name##_rc_t name##_rc_new_from_val(type##_t val) { \ name##_rc_t p; \ - p.in = (name##_inner_rc_t *)zp_malloc(sizeof(name##_inner_rc_t)); \ + p.in = (name##_inner_rc_t *)z_malloc(sizeof(name##_inner_rc_t)); \ if (p.in != NULL) { \ p.in->val = val; \ _ZP_RC_OP_INIT_CNT \ @@ -117,7 +117,7 @@ return c; \ } \ static inline name##_rc_t *name##_rc_clone_as_ptr(name##_rc_t *p) { \ - name##_rc_t *c = (name##_rc_t *)zp_malloc(sizeof(name##_rc_t)); \ + name##_rc_t *c = (name##_rc_t *)z_malloc(sizeof(name##_rc_t)); \ if (c != NULL) { \ c->in = p->in; \ _ZP_RC_OP_INCR_CNT \ @@ -136,7 +136,7 @@ } \ _ZP_RC_OP_SYNC \ type##_clear(&p->in->val); \ - zp_free(p->in); \ + z_free(p->in); \ return true; \ } diff --git a/include/zenoh-pico/deprecated/platform.h b/include/zenoh-pico/deprecated/platform.h new file mode 100644 index 000000000..5e47d65c6 --- /dev/null +++ b/include/zenoh-pico/deprecated/platform.h @@ -0,0 +1,88 @@ +// Copyright (c) 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 +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, + +#ifndef ZENOH_PICO_DEPRECATED_PLATFORM_H +#define ZENOH_PICO_DEPRECATED_PLATFORM_H + +#include + +#include "zenoh-pico/config.h" +#include "zenoh-pico/system/platform-common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/*------------------ Random ------------------*/ +uint8_t zp_random_u8(void); +uint16_t zp_random_u16(void); +uint32_t zp_random_u32(void); +uint64_t zp_random_u64(void); +void zp_random_fill(void *buf, size_t len); + +/*------------------ Memory ------------------*/ +void *zp_malloc(size_t size); +void *zp_realloc(void *ptr, size_t size); +void zp_free(void *ptr); + +#if Z_FEATURE_MULTI_THREAD == 1 +/*------------------ Thread ------------------*/ +typedef z_task_t zp_task_t; +typedef z_task_attr_t zp_task_attr_t; + +int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), void *arg); +int8_t zp_task_join(zp_task_t *task); +void zp_task_free(zp_task_t **task); + +/*------------------ Mutex ------------------*/ +typedef z_mutex_t zp_mutex_t; +int8_t zp_mutex_init(zp_mutex_t *m); +int8_t zp_mutex_free(zp_mutex_t *m); + +int8_t zp_mutex_lock(zp_mutex_t *m); +int8_t zp_mutex_trylock(zp_mutex_t *m); +int8_t zp_mutex_unlock(zp_mutex_t *m); + +/*------------------ CondVar ------------------*/ +typedef z_condvar_t zp_condvar_t; +int8_t zp_condvar_init(zp_condvar_t *cv); +int8_t zp_condvar_free(zp_condvar_t *cv); + +int8_t zp_condvar_signal(zp_condvar_t *cv); +int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m); +#endif // Z_FEATURE_MULTI_THREAD == 1 + +/*------------------ Sleep ------------------*/ +int zp_sleep_us(size_t time); +int zp_sleep_ms(size_t time); +int zp_sleep_s(size_t time); + +/*------------------ Clock ------------------*/ +typedef z_clock_t zp_clock_t; +zp_clock_t zp_clock_now(void); +unsigned long zp_clock_elapsed_us(zp_clock_t *time); +unsigned long zp_clock_elapsed_ms(zp_clock_t *time); +unsigned long zp_clock_elapsed_s(zp_clock_t *time); + +/*------------------ Time ------------------*/ +typedef z_time_t zp_time_t; +zp_time_t zp_time_now(void); +const char *zp_time_now_as_str(char *const buf, unsigned long buflen); +unsigned long zp_time_elapsed_us(zp_time_t *time); +unsigned long zp_time_elapsed_ms(zp_time_t *time); +unsigned long zp_time_elapsed_s(zp_time_t *time); + +#ifdef __cplusplus +} +#endif + +#endif /* ZENOH_PICO_DEPRECATED_PLATFORM_H */ diff --git a/include/zenoh-pico/net/session.h b/include/zenoh-pico/net/session.h index 241bfde77..6662edf74 100644 --- a/include/zenoh-pico/net/session.h +++ b/include/zenoh-pico/net/session.h @@ -29,7 +29,7 @@ */ typedef struct _z_session_t { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_t _mutex_inner; + z_mutex_t _mutex_inner; #endif // Z_FEATURE_MULTI_THREAD == 1 // Zenoh-pico is considering a single transport per session. @@ -143,7 +143,7 @@ int8_t _zp_send_join(_z_session_t *z); * Returns: * ``0`` in case of success, ``-1`` in case of failure. */ -int8_t _zp_start_read_task(_z_session_t *z, zp_task_attr_t *attr); +int8_t _zp_start_read_task(_z_session_t *z, z_task_attr_t *attr); /** * Stop the read task. This may result in stopping a thread or a process depending @@ -170,7 +170,7 @@ int8_t _zp_stop_read_task(_z_session_t *z); * Returns: * ``0`` in case of success, ``-1`` in case of failure. */ -int8_t _zp_start_lease_task(_z_session_t *z, zp_task_attr_t *attr); +int8_t _zp_start_lease_task(_z_session_t *z, z_task_attr_t *attr); /** * Stop the lease task. This may result in stopping a thread or a process depending diff --git a/include/zenoh-pico/session/session.h b/include/zenoh-pico/session/session.h index a13b8a238..3b58bd0de 100644 --- a/include/zenoh-pico/session/session.h +++ b/include/zenoh-pico/session/session.h @@ -173,8 +173,8 @@ _Z_LIST_DEFINE(_z_pending_query, _z_pending_query_t) typedef struct { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_t _mutex; - zp_condvar_t _cond_var; + z_mutex_t _mutex; + z_condvar_t _cond_var; #endif // Z_FEATURE_MULTI_THREAD == 1 _z_reply_data_list_t *_replies; } _z_pending_query_collect_t; diff --git a/include/zenoh-pico/system/platform-common.h b/include/zenoh-pico/system/platform-common.h new file mode 100644 index 000000000..081a5a9c4 --- /dev/null +++ b/include/zenoh-pico/system/platform-common.h @@ -0,0 +1,108 @@ +// +// Copyright (c) 2022 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 +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// Błażej Sowa, + +#ifndef ZENOH_PICO_SYSTEM_PLATFORM_COMMON_H +#define ZENOH_PICO_SYSTEM_PLATFORM_COMMON_H + +#include + +#include "zenoh-pico/config.h" + +#if defined(ZENOH_LINUX) || defined(ZENOH_MACOS) || defined(ZENOH_BSD) +#include "zenoh-pico/system/platform/unix.h" +#elif defined(ZENOH_WINDOWS) +#include "zenoh-pico/system/platform/windows.h" +#elif defined(ZENOH_ESPIDF) +#include "zenoh-pico/system/platform/espidf.h" +#elif defined(ZENOH_MBED) +#include "zenoh-pico/system/platform/mbed.h" +#elif defined(ZENOH_ZEPHYR) +#include "zenoh-pico/system/platform/zephyr.h" +#elif defined(ZENOH_ARDUINO_ESP32) +#include "zenoh-pico/system/platform/arduino/esp32.h" +#elif defined(ZENOH_ARDUINO_OPENCR) +#include "zenoh-pico/system/platform/arduino/opencr.h" +#elif defined(ZENOH_EMSCRIPTEN) +#include "zenoh-pico/system/platform/emscripten.h" +#elif defined(ZENOH_FLIPPER) +#include "zenoh-pico/system/platform/flipper.h" +#elif defined(ZENOH_FREERTOS_PLUS_TCP) +#include "zenoh-pico/system/platform/freertos_plus_tcp.h" +#else +#include "zenoh-pico/system/platform/void.h" +#error "Unknown platform" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/*------------------ Random ------------------*/ +uint8_t z_random_u8(void); +uint16_t z_random_u16(void); +uint32_t z_random_u32(void); +uint64_t z_random_u64(void); +void z_random_fill(void *buf, size_t len); + +/*------------------ Memory ------------------*/ +void *z_malloc(size_t size); +void *z_realloc(void *ptr, size_t size); +void z_free(void *ptr); + +#if Z_FEATURE_MULTI_THREAD == 1 +/*------------------ Thread ------------------*/ +int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg); +int8_t z_task_join(z_task_t *task); +int8_t zp_task_cancel(z_task_t *task); +void z_task_free(z_task_t **task); + +/*------------------ Mutex ------------------*/ +int8_t z_mutex_init(z_mutex_t *m); +int8_t z_mutex_free(z_mutex_t *m); + +int8_t z_mutex_lock(z_mutex_t *m); +int8_t z_mutex_trylock(z_mutex_t *m); +int8_t z_mutex_unlock(z_mutex_t *m); + +/*------------------ CondVar ------------------*/ +int8_t z_condvar_init(z_condvar_t *cv); +int8_t z_condvar_free(z_condvar_t *cv); + +int8_t z_condvar_signal(z_condvar_t *cv); +int8_t z_condvar_wait(z_condvar_t *cv, z_mutex_t *m); +#endif // Z_FEATURE_MULTI_THREAD == 1 + +/*------------------ Sleep ------------------*/ +int z_sleep_us(size_t time); +int z_sleep_ms(size_t time); +int z_sleep_s(size_t time); + +/*------------------ Clock ------------------*/ +z_clock_t z_clock_now(void); +unsigned long z_clock_elapsed_us(z_clock_t *time); +unsigned long z_clock_elapsed_ms(z_clock_t *time); +unsigned long z_clock_elapsed_s(z_clock_t *time); + +/*------------------ Time ------------------*/ +z_time_t z_time_now(void); +const char *z_time_now_as_str(char *const buf, unsigned long buflen); +unsigned long z_time_elapsed_us(z_time_t *time); +unsigned long z_time_elapsed_ms(z_time_t *time); +unsigned long z_time_elapsed_s(z_time_t *time); + +#ifdef __cplusplus +} +#endif + +#endif /* ZENOH_PICO_SYSTEM_PLATFORM_COMMON_H */ diff --git a/include/zenoh-pico/system/platform.h b/include/zenoh-pico/system/platform.h index dbfab19d9..4fe70198d 100644 --- a/include/zenoh-pico/system/platform.h +++ b/include/zenoh-pico/system/platform.h @@ -12,97 +12,13 @@ // ZettaScale Zenoh Team, // Błażej Sowa, -#ifndef ZENOH_PICO_SYSTEM_COMMON_H -#define ZENOH_PICO_SYSTEM_COMMON_H +#ifndef ZENOH_PICO_SYSTEM_PLATFORM_H +#define ZENOH_PICO_SYSTEM_PLATFORM_H #include #include "zenoh-pico/config.h" +#include "zenoh-pico/deprecated/platform.h" +#include "zenoh-pico/system/platform-common.h" -#if defined(ZENOH_LINUX) || defined(ZENOH_MACOS) || defined(ZENOH_BSD) -#include "zenoh-pico/system/platform/unix.h" -#elif defined(ZENOH_WINDOWS) -#include "zenoh-pico/system/platform/windows.h" -#elif defined(ZENOH_ESPIDF) -#include "zenoh-pico/system/platform/espidf.h" -#elif defined(ZENOH_MBED) -#include "zenoh-pico/system/platform/mbed.h" -#elif defined(ZENOH_ZEPHYR) -#include "zenoh-pico/system/platform/zephyr.h" -#elif defined(ZENOH_ARDUINO_ESP32) -#include "zenoh-pico/system/platform/arduino/esp32.h" -#elif defined(ZENOH_ARDUINO_OPENCR) -#include "zenoh-pico/system/platform/arduino/opencr.h" -#elif defined(ZENOH_EMSCRIPTEN) -#include "zenoh-pico/system/platform/emscripten.h" -#elif defined(ZENOH_FLIPPER) -#include "zenoh-pico/system/platform/flipper.h" -#elif defined(ZENOH_FREERTOS_PLUS_TCP) -#include "zenoh-pico/system/platform/freertos_plus_tcp.h" -#else -#include "zenoh-pico/system/platform/void.h" -#error "Unknown platform" -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/*------------------ Random ------------------*/ -uint8_t zp_random_u8(void); -uint16_t zp_random_u16(void); -uint32_t zp_random_u32(void); -uint64_t zp_random_u64(void); -void zp_random_fill(void *buf, size_t len); - -/*------------------ Memory ------------------*/ -void *zp_malloc(size_t size); -void *zp_realloc(void *ptr, size_t size); -void zp_free(void *ptr); - -#if Z_FEATURE_MULTI_THREAD == 1 -/*------------------ Thread ------------------*/ -int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), void *arg); -int8_t zp_task_join(zp_task_t *task); -int8_t zp_task_cancel(zp_task_t *task); -void zp_task_free(zp_task_t **task); - -/*------------------ Mutex ------------------*/ -int8_t zp_mutex_init(zp_mutex_t *m); -int8_t zp_mutex_free(zp_mutex_t *m); - -int8_t zp_mutex_lock(zp_mutex_t *m); -int8_t zp_mutex_trylock(zp_mutex_t *m); -int8_t zp_mutex_unlock(zp_mutex_t *m); - -/*------------------ CondVar ------------------*/ -int8_t zp_condvar_init(zp_condvar_t *cv); -int8_t zp_condvar_free(zp_condvar_t *cv); - -int8_t zp_condvar_signal(zp_condvar_t *cv); -int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m); -#endif // Z_FEATURE_MULTI_THREAD == 1 - -/*------------------ Sleep ------------------*/ -int zp_sleep_us(size_t time); -int zp_sleep_ms(size_t time); -int zp_sleep_s(size_t time); - -/*------------------ Clock ------------------*/ -zp_clock_t zp_clock_now(void); -unsigned long zp_clock_elapsed_us(zp_clock_t *time); -unsigned long zp_clock_elapsed_ms(zp_clock_t *time); -unsigned long zp_clock_elapsed_s(zp_clock_t *time); - -/*------------------ Time ------------------*/ -zp_time_t zp_time_now(void); -const char *zp_time_now_as_str(char *const buf, unsigned long buflen); -unsigned long zp_time_elapsed_us(zp_time_t *time); -unsigned long zp_time_elapsed_ms(zp_time_t *time); -unsigned long zp_time_elapsed_s(zp_time_t *time); - -#ifdef __cplusplus -} -#endif - -#endif /* ZENOH_PICO_SYSTEM_COMMON_H */ +#endif /* ZENOH_PICO_SYSTEM_PLATFORM_H */ diff --git a/include/zenoh-pico/system/platform/arduino/esp32.h b/include/zenoh-pico/system/platform/arduino/esp32.h index c26c99a88..abdc37f67 100644 --- a/include/zenoh-pico/system/platform/arduino/esp32.h +++ b/include/zenoh-pico/system/platform/arduino/esp32.h @@ -24,14 +24,14 @@ #endif // Z_FEATURE_MULTI_THREAD == 1 #if Z_FEATURE_MULTI_THREAD == 1 -typedef TaskHandle_t zp_task_t; -typedef void *zp_task_attr_t; // Not used in ESP32 -typedef pthread_mutex_t zp_mutex_t; -typedef pthread_cond_t zp_condvar_t; +typedef TaskHandle_t z_task_t; +typedef void *z_task_attr_t; // Not used in ESP32 +typedef pthread_mutex_t z_mutex_t; +typedef pthread_cond_t z_condvar_t; #endif // Z_FEATURE_MULTI_THREAD == 1 -typedef struct timespec zp_clock_t; -typedef struct timeval zp_time_t; +typedef struct timespec z_clock_t; +typedef struct timeval z_time_t; typedef struct BluetoothSerial BluetoothSerial; // Forward declaration to be used in _z_sys_net_socket_t typedef struct HardwareSerial HardwareSerial; // Forward declaration to be used in _z_sys_net_socket_t diff --git a/include/zenoh-pico/system/platform/arduino/opencr.h b/include/zenoh-pico/system/platform/arduino/opencr.h index ebc054164..af16ce60b 100644 --- a/include/zenoh-pico/system/platform/arduino/opencr.h +++ b/include/zenoh-pico/system/platform/arduino/opencr.h @@ -21,14 +21,14 @@ #include "zenoh-pico/config.h" #if Z_FEATURE_MULTI_THREAD == 1 -typedef void *zp_task_t; -typedef void *zp_task_attr_t; -typedef void *zp_mutex_t; -typedef void *zp_condvar_t; +typedef void *z_task_t; +typedef void *z_task_attr_t; +typedef void *z_mutex_t; +typedef void *z_condvar_t; #endif // Z_FEATURE_MULTI_THREAD == 1 -typedef struct timespec zp_clock_t; -typedef struct timeval zp_time_t; +typedef struct timespec z_clock_t; +typedef struct timeval z_time_t; typedef struct IPAddress IPAddress; // Forward declaration to be used in __z_net_iptcp_addr_t typedef struct WiFiClient WiFiClient; // Forward declaration to be used in _z_sys_net_socket_t diff --git a/include/zenoh-pico/system/platform/emscripten.h b/include/zenoh-pico/system/platform/emscripten.h index e74216bf5..b89921197 100644 --- a/include/zenoh-pico/system/platform/emscripten.h +++ b/include/zenoh-pico/system/platform/emscripten.h @@ -22,14 +22,14 @@ #if Z_FEATURE_MULTI_THREAD == 1 #include -typedef pthread_t zp_task_t; -typedef pthread_attr_t zp_task_attr_t; -typedef pthread_mutex_t zp_mutex_t; -typedef pthread_cond_t zp_condvar_t; +typedef pthread_t z_task_t; +typedef pthread_attr_t z_task_attr_t; +typedef pthread_mutex_t z_mutex_t; +typedef pthread_cond_t z_condvar_t; #endif // Z_FEATURE_MULTI_THREAD == 1 -typedef double zp_clock_t; -typedef double zp_time_t; +typedef double z_clock_t; +typedef double z_time_t; typedef struct { union { diff --git a/include/zenoh-pico/system/platform/espidf.h b/include/zenoh-pico/system/platform/espidf.h index 6210a9abc..671617989 100644 --- a/include/zenoh-pico/system/platform/espidf.h +++ b/include/zenoh-pico/system/platform/espidf.h @@ -24,14 +24,14 @@ #if Z_FEATURE_MULTI_THREAD == 1 #include -typedef TaskHandle_t zp_task_t; -typedef void *zp_task_attr_t; // Not used in ESP32 -typedef pthread_mutex_t zp_mutex_t; -typedef pthread_cond_t zp_condvar_t; +typedef TaskHandle_t z_task_t; +typedef void *z_task_attr_t; // Not used in ESP32 +typedef pthread_mutex_t z_mutex_t; +typedef pthread_cond_t z_condvar_t; #endif // Z_FEATURE_MULTI_THREAD == 1 -typedef struct timespec zp_clock_t; -typedef struct timeval zp_time_t; +typedef struct timespec z_clock_t; +typedef struct timeval z_time_t; typedef struct { union { diff --git a/include/zenoh-pico/system/platform/flipper.h b/include/zenoh-pico/system/platform/flipper.h index f32e51f4f..124714afe 100644 --- a/include/zenoh-pico/system/platform/flipper.h +++ b/include/zenoh-pico/system/platform/flipper.h @@ -27,14 +27,14 @@ #define FLIPPER_SERIAL_TIMEOUT_MS 200 #if Z_FEATURE_MULTI_THREAD == 1 -typedef FuriThread* zp_task_t; -typedef uint32_t zp_task_attr_t; -typedef FuriMutex* zp_mutex_t; -typedef void* zp_condvar_t; +typedef FuriThread* z_task_t; +typedef uint32_t z_task_attr_t; +typedef FuriMutex* z_mutex_t; +typedef void* z_condvar_t; #endif // Z_FEATURE_MULTI_THREAD == 1 -typedef struct timespec zp_clock_t; -typedef struct timeval zp_time_t; +typedef struct timespec z_clock_t; +typedef struct timeval z_time_t; typedef struct { #if Z_FEATURE_LINK_SERIAL == 1 diff --git a/include/zenoh-pico/system/platform/freertos_plus_tcp.h b/include/zenoh-pico/system/platform/freertos_plus_tcp.h index 8af5d8041..f85269dab 100644 --- a/include/zenoh-pico/system/platform/freertos_plus_tcp.h +++ b/include/zenoh-pico/system/platform/freertos_plus_tcp.h @@ -28,19 +28,19 @@ typedef struct { StackType_t *stack_buffer; StaticTask_t *task_buffer; #endif /* SUPPORT_STATIC_ALLOCATION */ -} zp_task_attr_t; +} z_task_attr_t; typedef struct { TaskHandle_t handle; EventGroupHandle_t join_event; -} zp_task_t; +} z_task_t; -typedef SemaphoreHandle_t zp_mutex_t; -typedef void *zp_condvar_t; +typedef SemaphoreHandle_t z_mutex_t; +typedef void *z_condvar_t; #endif // Z_MULTI_THREAD == 1 -typedef TickType_t zp_clock_t; -typedef TickType_t zp_time_t; +typedef TickType_t z_clock_t; +typedef TickType_t z_time_t; typedef struct { union { diff --git a/include/zenoh-pico/system/platform/mbed.h b/include/zenoh-pico/system/platform/mbed.h index 922e95fee..170b230f3 100644 --- a/include/zenoh-pico/system/platform/mbed.h +++ b/include/zenoh-pico/system/platform/mbed.h @@ -23,14 +23,14 @@ typedef int _z_socket_t; #if Z_FEATURE_MULTI_THREAD == 1 -typedef void *zp_task_t; // Workaround as MBED is a C++ library -typedef void *zp_task_attr_t; // Workaround as MBED is a C++ library -typedef void *zp_mutex_t; // Workaround as MBED is a C++ library -typedef void *zp_condvar_t; // Workaround as MBED is a C++ library -#endif // Z_FEATURE_MULTI_THREAD == 1 +typedef void *z_task_t; // Workaround as MBED is a C++ library +typedef void *z_task_attr_t; // Workaround as MBED is a C++ library +typedef void *z_mutex_t; // Workaround as MBED is a C++ library +typedef void *z_condvar_t; // Workaround as MBED is a C++ library +#endif // Z_FEATURE_MULTI_THREAD == 1 -typedef void *zp_clock_t; // Not defined -typedef struct timeval zp_time_t; +typedef void *z_clock_t; // Not defined +typedef struct timeval z_time_t; typedef struct BufferedSerial BufferedSerial; // Forward declaration to be used in _z_sys_net_socket_t typedef struct UDPSocket UDPSocket; // Forward declaration to be used in _z_sys_net_socket_t diff --git a/include/zenoh-pico/system/platform/unix.h b/include/zenoh-pico/system/platform/unix.h index d3344a73f..8fd10421e 100644 --- a/include/zenoh-pico/system/platform/unix.h +++ b/include/zenoh-pico/system/platform/unix.h @@ -25,14 +25,14 @@ #if Z_FEATURE_MULTI_THREAD == 1 #include -typedef pthread_t zp_task_t; -typedef pthread_attr_t zp_task_attr_t; -typedef pthread_mutex_t zp_mutex_t; -typedef pthread_cond_t zp_condvar_t; +typedef pthread_t z_task_t; +typedef pthread_attr_t z_task_attr_t; +typedef pthread_mutex_t z_mutex_t; +typedef pthread_cond_t z_condvar_t; #endif // Z_FEATURE_MULTI_THREAD == 1 -typedef struct timespec zp_clock_t; -typedef struct timeval zp_time_t; +typedef struct timespec z_clock_t; +typedef struct timeval z_time_t; typedef struct { union { diff --git a/include/zenoh-pico/system/platform/void.h b/include/zenoh-pico/system/platform/void.h index b124bbc8f..b6fc1dd99 100644 --- a/include/zenoh-pico/system/platform/void.h +++ b/include/zenoh-pico/system/platform/void.h @@ -18,13 +18,13 @@ #include "zenoh-pico/config.h" #if Z_FEATURE_MULTI_THREAD == 1 -typedef void *zp_task_t; -typedef void *zp_task_attr_t; -typedef void *zp_mutex_t; -typedef void *zp_condvar_t; +typedef void *z_task_t; +typedef void *z_task_attr_t; +typedef void *z_mutex_t; +typedef void *z_condvar_t; #endif // Z_FEATURE_MULTI_THREAD == 1 -typedef void *zp_clock_t; -typedef void *zp_time_t; +typedef void *z_clock_t; +typedef void *z_time_t; #endif /* ZENOH_PICO_SYSTEM_VOID_H */ diff --git a/include/zenoh-pico/system/platform/windows.h b/include/zenoh-pico/system/platform/windows.h index 44e3b5a25..d003be987 100644 --- a/include/zenoh-pico/system/platform/windows.h +++ b/include/zenoh-pico/system/platform/windows.h @@ -21,14 +21,14 @@ #include "zenoh-pico/config.h" #if Z_FEATURE_MULTI_THREAD == 1 -typedef HANDLE *zp_task_t; -typedef void *zp_task_attr_t; // Not used in Windows -typedef SRWLOCK zp_mutex_t; -typedef CONDITION_VARIABLE zp_condvar_t; +typedef HANDLE *z_task_t; +typedef void *z_task_attr_t; // Not used in Windows +typedef SRWLOCK z_mutex_t; +typedef CONDITION_VARIABLE z_condvar_t; #endif // Z_FEATURE_MULTI_THREAD == 1 -typedef LARGE_INTEGER zp_clock_t; -typedef struct timeb zp_time_t; +typedef LARGE_INTEGER z_clock_t; +typedef struct timeb z_time_t; typedef struct { union { diff --git a/include/zenoh-pico/system/platform/zephyr.h b/include/zenoh-pico/system/platform/zephyr.h index 830f7f2f4..da7b41997 100644 --- a/include/zenoh-pico/system/platform/zephyr.h +++ b/include/zenoh-pico/system/platform/zephyr.h @@ -31,14 +31,14 @@ #include "zenoh-pico/config.h" #if Z_FEATURE_MULTI_THREAD == 1 -typedef pthread_t zp_task_t; -typedef pthread_attr_t zp_task_attr_t; -typedef pthread_mutex_t zp_mutex_t; -typedef pthread_cond_t zp_condvar_t; +typedef pthread_t z_task_t; +typedef pthread_attr_t z_task_attr_t; +typedef pthread_mutex_t z_mutex_t; +typedef pthread_cond_t z_condvar_t; #endif // Z_FEATURE_MULTI_THREAD == 1 -typedef struct timespec zp_clock_t; -typedef struct timeval zp_time_t; +typedef struct timespec z_clock_t; +typedef struct timeval z_time_t; typedef struct { union { diff --git a/include/zenoh-pico/transport/multicast/lease.h b/include/zenoh-pico/transport/multicast/lease.h index 7c5ba8296..628eaa088 100644 --- a/include/zenoh-pico/transport/multicast/lease.h +++ b/include/zenoh-pico/transport/multicast/lease.h @@ -23,7 +23,7 @@ int8_t _zp_multicast_stop_lease_task(_z_transport_multicast_t *ztm); void *_zp_multicast_lease_task(void *ztm_arg); // The argument is void* to avoid incompatible pointer types in tasks #if Z_FEATURE_MULTI_THREAD == 1 && (Z_FEATURE_MULTICAST_TRANSPORT == 1 || Z_FEATURE_RAWETH_TRANSPORT == 1) -int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, zp_task_attr_t *attr, zp_task_t *task); +int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, z_task_attr_t *attr, z_task_t *task); #else int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, void *attr, void *task); #endif /* Z_FEATURE_MULTI_THREAD == 1 && (Z_FEATURE_MULTICAST_TRANSPORT == 1 || Z_FEATURE_RAWETH_TRANSPORT == 1) */ diff --git a/include/zenoh-pico/transport/multicast/read.h b/include/zenoh-pico/transport/multicast/read.h index f321a74d6..67b046397 100644 --- a/include/zenoh-pico/transport/multicast/read.h +++ b/include/zenoh-pico/transport/multicast/read.h @@ -22,7 +22,7 @@ int8_t _zp_multicast_stop_read_task(_z_transport_t *zt); void *_zp_multicast_read_task(void *ztm_arg); // The argument is void* to avoid incompatible pointer types in tasks #if Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_MULTICAST_TRANSPORT == 1 -int8_t _zp_multicast_start_read_task(_z_transport_t *zt, zp_task_attr_t *attr, zp_task_t *task); +int8_t _zp_multicast_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, z_task_t *task); #else int8_t _zp_multicast_start_read_task(_z_transport_t *zt, void *attr, void *task); #endif /* #if Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_MULTICAST_TRANSPORT == 1 */ diff --git a/include/zenoh-pico/transport/raweth/read.h b/include/zenoh-pico/transport/raweth/read.h index bc8325465..3df0d2979 100644 --- a/include/zenoh-pico/transport/raweth/read.h +++ b/include/zenoh-pico/transport/raweth/read.h @@ -22,7 +22,7 @@ int8_t _zp_raweth_stop_read_task(_z_transport_t *zt); void *_zp_raweth_read_task(void *ztm_arg); // The argument is void* to avoid incompatible pointer types in tasks #if Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_RAWETH_TRANSPORT == 1 -int8_t _zp_raweth_start_read_task(_z_transport_t *zt, zp_task_attr_t *attr, zp_task_t *task); +int8_t _zp_raweth_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, z_task_t *task); #else int8_t _zp_raweth_start_read_task(_z_transport_t *zt, void *attr, void *task); #endif /* Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_RAWETH_TRANSPORT == 1 */ diff --git a/include/zenoh-pico/transport/transport.h b/include/zenoh-pico/transport/transport.h index 313f77268..76921bd9c 100644 --- a/include/zenoh-pico/transport/transport.h +++ b/include/zenoh-pico/transport/transport.h @@ -69,8 +69,8 @@ typedef struct { #if Z_FEATURE_MULTI_THREAD == 1 // TX and RX mutexes - zp_mutex_t _mutex_rx; - zp_mutex_t _mutex_tx; + z_mutex_t _mutex_rx; + z_mutex_t _mutex_tx; #endif // Z_FEATURE_MULTI_THREAD == 1 _z_link_t _link; @@ -96,8 +96,8 @@ typedef struct { volatile _z_zint_t _lease; #if Z_FEATURE_MULTI_THREAD == 1 - zp_task_t *_read_task; - zp_task_t *_lease_task; + z_task_t *_read_task; + z_task_t *_lease_task; volatile _Bool _read_task_running; volatile _Bool _lease_task_running; #endif // Z_FEATURE_MULTI_THREAD == 1 @@ -112,11 +112,11 @@ typedef struct _z_transport_multicast_t { #if Z_FEATURE_MULTI_THREAD == 1 // TX and RX mutexes - zp_mutex_t _mutex_rx; - zp_mutex_t _mutex_tx; + z_mutex_t _mutex_rx; + z_mutex_t _mutex_tx; // Peer list mutex - zp_mutex_t _mutex_peer; + z_mutex_t _mutex_peer; #endif // Z_FEATURE_MULTI_THREAD == 1 _z_link_t _link; @@ -138,8 +138,8 @@ typedef struct _z_transport_multicast_t { _zp_f_send_tmsg _send_f; #if Z_FEATURE_MULTI_THREAD == 1 - zp_task_t *_read_task; - zp_task_t *_lease_task; + z_task_t *_read_task; + z_task_t *_lease_task; volatile _Bool _read_task_running; volatile _Bool _lease_task_running; #endif // Z_FEATURE_MULTI_THREAD == 1 diff --git a/include/zenoh-pico/transport/unicast/lease.h b/include/zenoh-pico/transport/unicast/lease.h index 6cdfa195d..8ccad0e7b 100644 --- a/include/zenoh-pico/transport/unicast/lease.h +++ b/include/zenoh-pico/transport/unicast/lease.h @@ -22,7 +22,7 @@ int8_t _zp_unicast_stop_lease_task(_z_transport_t *zt); void *_zp_unicast_lease_task(void *ztu_arg); // The argument is void* to avoid incompatible pointer types in tasks #if Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_UNICAST_TRANSPORT == 1 -int8_t _zp_unicast_start_lease_task(_z_transport_t *zt, zp_task_attr_t *attr, zp_task_t *task); +int8_t _zp_unicast_start_lease_task(_z_transport_t *zt, z_task_attr_t *attr, z_task_t *task); #else int8_t _zp_unicast_start_lease_task(_z_transport_t *zt, void *attr, void *task); #endif /* Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_UNICAST_TRANSPORT == 1 */ diff --git a/include/zenoh-pico/transport/unicast/read.h b/include/zenoh-pico/transport/unicast/read.h index c54069427..c3c17bc05 100644 --- a/include/zenoh-pico/transport/unicast/read.h +++ b/include/zenoh-pico/transport/unicast/read.h @@ -22,7 +22,7 @@ int8_t _zp_unicast_stop_read_task(_z_transport_t *zt); void *_zp_unicast_read_task(void *ztu_arg); // The argument is void* to avoid incompatible pointer types in tasks #if Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_UNICAST_TRANSPORT == 1 -int8_t _zp_unicast_start_read_task(_z_transport_t *zt, zp_task_attr_t *attr, zp_task_t *task); +int8_t _zp_unicast_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, z_task_t *task); #else int8_t _zp_unicast_start_read_task(_z_transport_t *zt, void *attr, void *task); #endif /* Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_UNICAST_TRANSPORT == 1 */ diff --git a/include/zenoh-pico/utils/logging.h b/include/zenoh-pico/utils/logging.h index c8bdc8352..f6e3304ef 100644 --- a/include/zenoh-pico/utils/logging.h +++ b/include/zenoh-pico/utils/logging.h @@ -25,7 +25,7 @@ // Timestamp function static inline void __z_print_timestamp(void) { char ret[64]; - printf("[%s ", zp_time_now_as_str(ret, sizeof(ret))); + printf("[%s ", z_time_now_as_str(ret, sizeof(ret))); } // Logging macros diff --git a/src/api/api.c b/src/api/api.c index 73350bd23..1c1660be5 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -59,7 +59,7 @@ z_owned_str_t z_keyexpr_to_string(z_keyexpr_t keyexpr) { if (keyexpr._id == Z_RESOURCE_ID_NONE) { size_t ke_len = _z_str_size(keyexpr._suffix); - ret._value = (char *)zp_malloc(ke_len); + ret._value = (char *)z_malloc(ke_len); if (ret._value != NULL) { _z_str_n_copy(ret._value, keyexpr._suffix, ke_len); } @@ -348,7 +348,7 @@ void z_closure_zid_call(const z_owned_closure_zid_t *closure, const z_id_t *id) ownedtype *z_##name##_move(ownedtype *val) { return val; } \ ownedtype z_##name##_clone(ownedtype *val) { \ ownedtype ret; \ - ret._value = (type *)zp_malloc(sizeof(type)); \ + ret._value = (type *)z_malloc(sizeof(type)); \ if (ret._value != NULL) { \ f_copy(ret._value, val->_value); \ } \ @@ -369,7 +369,7 @@ void z_closure_zid_call(const z_owned_closure_zid_t *closure, const z_id_t *id) #define OWNED_FUNCTIONS_PTR_CLONE(type, ownedtype, name, f_copy) \ ownedtype z_##name##_clone(ownedtype *val) { \ ownedtype ret; \ - ret._value = (_##type *)zp_malloc(sizeof(_##type)); \ + ret._value = (_##type *)z_malloc(sizeof(_##type)); \ if (ret._value != NULL) { \ f_copy(ret._value, val->_value); \ } \ @@ -391,7 +391,7 @@ void z_closure_zid_call(const z_owned_closure_zid_t *closure, const z_id_t *id) ownedtype z_##name##_clone(ownedtype *val) { \ ownedtype ret; \ size_t size = _z_str_size(val->_value); \ - ret._value = (_##type)zp_malloc(size); \ + ret._value = (_##type)z_malloc(size); \ if (ret._value != NULL) { \ f_copy(ret._value, val->_value, size); \ } \ @@ -495,7 +495,7 @@ int8_t z_scout(z_owned_scouting_config_t *config, z_owned_closure_hello_t *callb // TODO[API-NET]: When API and NET are a single layer, there is no wrap the user callback and args // to enclose the z_reply_t into a z_owned_reply_t. __z_hello_handler_wrapper_t *wrapped_ctx = - (__z_hello_handler_wrapper_t *)zp_malloc(sizeof(__z_hello_handler_wrapper_t)); + (__z_hello_handler_wrapper_t *)z_malloc(sizeof(__z_hello_handler_wrapper_t)); if (wrapped_ctx != NULL) { wrapped_ctx->user_call = callback->call; wrapped_ctx->ctx = ctx; @@ -526,7 +526,7 @@ int8_t z_scout(z_owned_scouting_config_t *config, z_owned_closure_hello_t *callb _z_scout(what, zid, mcast_locator, timeout, __z_hello_handler, wrapped_ctx, callback->drop, ctx); - zp_free(wrapped_ctx); + z_free(wrapped_ctx); z_scouting_config_drop(config); } else { ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; @@ -770,7 +770,7 @@ int8_t z_publisher_delete(const z_publisher_t pub, const z_publisher_delete_opti } z_owned_keyexpr_t z_publisher_keyexpr(z_publisher_t publisher) { - z_owned_keyexpr_t ret = {._value = zp_malloc(sizeof(_z_keyexpr_t))}; + z_owned_keyexpr_t ret = {._value = z_malloc(sizeof(_z_keyexpr_t))}; if (ret._value != NULL && publisher._val != NULL) { *ret._value = _z_keyexpr_duplicate(publisher._val->_key); } @@ -829,7 +829,7 @@ int8_t z_get(z_session_t zs, z_keyexpr_t keyexpr, const char *parameters, z_owne // TODO[API-NET]: When API and NET are a single layer, there is no wrap the user callback and args // to enclose the z_reply_t into a z_owned_reply_t. __z_reply_handler_wrapper_t *wrapped_ctx = - (__z_reply_handler_wrapper_t *)zp_malloc(sizeof(__z_reply_handler_wrapper_t)); + (__z_reply_handler_wrapper_t *)z_malloc(sizeof(__z_reply_handler_wrapper_t)); if (wrapped_ctx != NULL) { wrapped_ctx->user_call = callback->call; wrapped_ctx->ctx = ctx; @@ -927,7 +927,7 @@ int8_t z_query_reply(const z_query_t *query, const z_keyexpr_t keyexpr, const ui z_owned_keyexpr_t z_keyexpr_new(const char *name) { z_owned_keyexpr_t key; - key._value = name ? (z_keyexpr_t *)zp_malloc(sizeof(z_keyexpr_t)) : NULL; + key._value = name ? (z_keyexpr_t *)z_malloc(sizeof(z_keyexpr_t)) : NULL; if (key._value != NULL) { *key._value = _z_rid_with_suffix(Z_RESOURCE_ID_NONE, name); } @@ -938,7 +938,7 @@ z_owned_keyexpr_t z_keyexpr_new(const char *name) { z_owned_keyexpr_t z_declare_keyexpr(z_session_t zs, z_keyexpr_t keyexpr) { z_owned_keyexpr_t key; - key._value = (z_keyexpr_t *)zp_malloc(sizeof(z_keyexpr_t)); + key._value = (z_keyexpr_t *)z_malloc(sizeof(z_keyexpr_t)); if (key._value != NULL) { uint16_t id = _z_declare_resource(&zs._val.in->val, keyexpr); *key._value = _z_rid_with_suffix(id, NULL); @@ -991,7 +991,7 @@ z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z if (wild != NULL && wild != keyexpr._suffix) { wild -= 1; size_t len = wild - keyexpr._suffix; - suffix = zp_malloc(len + 1); + suffix = z_malloc(len + 1); if (suffix != NULL) { memcpy(suffix, keyexpr._suffix, len); suffix[len] = 0; @@ -1014,7 +1014,7 @@ z_owned_subscriber_t z_declare_subscriber(z_session_t zs, z_keyexpr_t keyexpr, z } _z_subscriber_t *sub = _z_declare_subscriber(&zs._val, key, subinfo, callback->call, callback->drop, ctx); if (suffix != NULL) { - zp_free(suffix); + z_free(suffix); } return (z_owned_subscriber_t){._value = sub}; @@ -1073,7 +1073,7 @@ z_owned_keyexpr_t z_subscriber_keyexpr(z_subscriber_t sub) { _z_subscription_rc_t *head = _z_subscription_rc_list_head(tail); if (head->in->val._id == lookup) { _z_keyexpr_t key = _z_keyexpr_duplicate(head->in->val._key); - ret = (z_owned_keyexpr_t){._value = zp_malloc(sizeof(_z_keyexpr_t))}; + ret = (z_owned_keyexpr_t){._value = z_malloc(sizeof(_z_keyexpr_t))}; if (ret._value != NULL) { *ret._value = key; } else { @@ -1239,7 +1239,7 @@ void z_bytes_map_insert_by_alias(const z_owned_bytes_map_t *this_, z_bytes_t key _z_bytes_clear(&head->value); head->value = _z_bytes_wrap(value.start, value.len); } else { - struct _z_bytes_pair_t *insert = zp_malloc(sizeof(struct _z_bytes_pair_t)); + struct _z_bytes_pair_t *insert = z_malloc(sizeof(struct _z_bytes_pair_t)); memset(insert, 0, sizeof(struct _z_bytes_pair_t)); insert->key = _z_bytes_wrap(key.start, key.len); insert->value = _z_bytes_wrap(value.start, value.len); @@ -1263,7 +1263,7 @@ void z_bytes_map_insert_by_copy(const z_owned_bytes_map_t *this_, z_bytes_t key, _z_bytes_copy(&head->key, &key); } } else { - struct _z_bytes_pair_t *insert = zp_malloc(sizeof(struct _z_bytes_pair_t)); + struct _z_bytes_pair_t *insert = z_malloc(sizeof(struct _z_bytes_pair_t)); memset(insert, 0, sizeof(struct _z_bytes_pair_t)); _z_bytes_copy(&insert->key, &key); _z_bytes_copy(&insert->value, &value); diff --git a/src/collections/bytes.c b/src/collections/bytes.c index 1fa4f71d0..40e67bd36 100644 --- a/src/collections/bytes.c +++ b/src/collections/bytes.c @@ -26,7 +26,7 @@ _z_bytes_t _z_bytes_empty(void) { return (_z_bytes_t){.start = NULL, .len = 0, . int8_t _z_bytes_init(_z_bytes_t *bs, size_t capacity) { int8_t ret = _Z_RES_OK; - bs->start = (uint8_t *)zp_malloc(capacity); + bs->start = (uint8_t *)z_malloc(capacity); if (bs->start != NULL) { bs->len = capacity; bs->_is_alloc = true; @@ -61,7 +61,7 @@ void _z_bytes_reset(_z_bytes_t *bs) { void _z_bytes_clear(_z_bytes_t *bs) { if ((bs->_is_alloc == true) && (bs->start != NULL)) { - zp_free((uint8_t *)bs->start); + z_free((uint8_t *)bs->start); } _z_bytes_reset(bs); } @@ -72,7 +72,7 @@ void _z_bytes_free(_z_bytes_t **bs) { if (ptr != NULL) { _z_bytes_clear(ptr); - zp_free(ptr); + z_free(ptr); *bs = NULL; } } diff --git a/src/collections/intmap.c b/src/collections/intmap.c index 203052b9e..5abeab4f7 100644 --- a/src/collections/intmap.c +++ b/src/collections/intmap.c @@ -66,7 +66,7 @@ void *_z_int_void_map_insert(_z_int_void_map_t *map, size_t k, void *v, z_elemen if (map->_vals == NULL) { // Lazily allocate and initialize to NULL all the pointers size_t len = map->_capacity * sizeof(_z_list_t *); - map->_vals = (_z_list_t **)zp_malloc(len); + map->_vals = (_z_list_t **)z_malloc(len); if (map->_vals != NULL) { (void)memset(map->_vals, 0, len); } @@ -77,7 +77,7 @@ void *_z_int_void_map_insert(_z_int_void_map_t *map, size_t k, void *v, z_elemen _z_int_void_map_remove(map, k, f_f); // Insert the element - _z_int_void_map_entry_t *entry = (_z_int_void_map_entry_t *)zp_malloc(sizeof(_z_int_void_map_entry_t)); + _z_int_void_map_entry_t *entry = (_z_int_void_map_entry_t *)z_malloc(sizeof(_z_int_void_map_entry_t)); if (entry != NULL) { entry->_key = k; entry->_val = v; @@ -116,7 +116,7 @@ void _z_int_void_map_clear(_z_int_void_map_t *map, z_element_free_f f_f) { _z_list_free(&map->_vals[idx], f_f); } - zp_free(map->_vals); + z_free(map->_vals); map->_vals = NULL; } } @@ -126,7 +126,7 @@ void _z_int_void_map_free(_z_int_void_map_t **map, z_element_free_f f) { if (ptr != NULL) { _z_int_void_map_clear(ptr, f); - zp_free(ptr); + z_free(ptr); *map = NULL; } } diff --git a/src/collections/list.c b/src/collections/list.c index 46a67446c..36dbadd51 100644 --- a/src/collections/list.c +++ b/src/collections/list.c @@ -18,7 +18,7 @@ /*-------- Inner single-linked list --------*/ _z_list_t *_z_list_of(void *x) { - _z_list_t *xs = (_z_list_t *)zp_malloc(sizeof(_z_list_t)); + _z_list_t *xs = (_z_list_t *)z_malloc(sizeof(_z_list_t)); if (xs != NULL) { xs->_val = x; xs->_tail = NULL; @@ -71,7 +71,7 @@ _z_list_t *_z_list_pop(_z_list_t *xs, z_element_free_f f_f, void **x) { } else { f_f(&head->_val); } - zp_free(head); + z_free(head); return l; } @@ -113,7 +113,7 @@ _z_list_t *_z_list_drop_filter(_z_list_t *xs, z_element_free_f f_f, z_element_eq } f_f(&this_->_val); - zp_free(this_); + z_free(this_); break; } else { previous = current; diff --git a/src/collections/string.c b/src/collections/string.c index 98d7dda3d..51a19c38b 100644 --- a/src/collections/string.c +++ b/src/collections/string.c @@ -53,7 +53,7 @@ void _z_string_reset(_z_string_t *str) { } void _z_string_clear(_z_string_t *str) { - zp_free(str->val); + z_free(str->val); _z_string_reset(str); } @@ -62,7 +62,7 @@ void _z_string_free(_z_string_t **str) { if (ptr != NULL) { _z_string_clear(ptr); - zp_free(ptr); + z_free(ptr); *str = NULL; } } @@ -70,7 +70,7 @@ void _z_string_free(_z_string_t **str) { _z_string_t _z_string_from_bytes(const _z_bytes_t *bs) { _z_string_t s; size_t len = bs->len * (size_t)2; - char *s_val = (char *)zp_malloc((len + (size_t)1) * sizeof(char)); + char *s_val = (char *)z_malloc((len + (size_t)1) * sizeof(char)); if (s_val != NULL) { const char c[] = "0123456789ABCDEF"; @@ -92,7 +92,7 @@ _z_string_t _z_string_from_bytes(const _z_bytes_t *bs) { /*-------- str --------*/ size_t _z_str_size(const char *src) { return strlen(src) + (size_t)1; } -void _z_str_clear(char *src) { zp_free(src); } +void _z_str_clear(char *src) { z_free(src); } void _z_str_free(char **src) { char *ptr = *src; @@ -116,7 +116,7 @@ void _z_str_n_copy(char *dst, const char *src, size_t size) { char *_z_str_clone(const char *src) { size_t len = _z_str_size(src); - char *dst = (char *)zp_malloc(len); + char *dst = (char *)z_malloc(len); if (dst != NULL) { _z_str_n_copy(dst, src, len); } @@ -129,7 +129,7 @@ _Bool _z_str_eq(const char *left, const char *right) { return strcmp(left, right /*-------- str_array --------*/ void _z_str_array_init(_z_str_array_t *sa, size_t len) { char **val = (char **)&sa->val; - *val = (char *)zp_malloc(len * sizeof(char *)); + *val = (char *)z_malloc(len * sizeof(char *)); if (*val != NULL) { sa->len = len; } @@ -151,9 +151,9 @@ _Bool _z_str_array_is_empty(const _z_str_array_t *sa) { return sa->len == 0; } void _z_str_array_clear(_z_str_array_t *sa) { for (size_t i = 0; i < sa->len; i++) { - zp_free(sa->val[i]); + z_free(sa->val[i]); } - zp_free(sa->val); + z_free(sa->val); } void _z_str_array_free(_z_str_array_t **sa) { @@ -161,7 +161,7 @@ void _z_str_array_free(_z_str_array_t **sa) { if (ptr != NULL) { _z_str_array_clear(ptr); - zp_free(ptr); + z_free(ptr); *sa = NULL; } } diff --git a/src/collections/vec.c b/src/collections/vec.c index fabd490fb..20afff6ca 100644 --- a/src/collections/vec.c +++ b/src/collections/vec.c @@ -22,7 +22,7 @@ _z_vec_t _z_vec_make(size_t capacity) { _z_vec_t v = {._capacity = capacity, ._len = 0, ._val = NULL}; if (capacity != 0) { - v._val = (void **)zp_malloc(sizeof(void *) * capacity); + v._val = (void **)z_malloc(sizeof(void *) * capacity); } if (v._val != NULL) { v._capacity = capacity; @@ -33,7 +33,7 @@ _z_vec_t _z_vec_make(size_t capacity) { void _z_vec_copy(_z_vec_t *dst, const _z_vec_t *src, z_element_clone_f d_f) { dst->_capacity = src->_capacity; dst->_len = src->_len; - dst->_val = (void **)zp_malloc(sizeof(void *) * src->_capacity); + dst->_val = (void **)z_malloc(sizeof(void *) * src->_capacity); if (dst->_val != NULL) { for (size_t i = 0; i < src->_len; i++) { _z_vec_append(dst, d_f(src->_val[i])); @@ -54,7 +54,7 @@ void _z_vec_clear(_z_vec_t *v, z_element_free_f free_f) { free_f(&v->_val[i]); } - zp_free(v->_val); + z_free(v->_val); v->_val = NULL; v->_capacity = 0; @@ -67,7 +67,7 @@ void _z_vec_free(_z_vec_t **v, z_element_free_f free_f) { if (ptr != NULL) { _z_vec_clear(ptr, free_f); - zp_free(ptr); + z_free(ptr); *v = NULL; } } @@ -80,12 +80,12 @@ void _z_vec_append(_z_vec_t *v, void *e) { if (v->_len == v->_capacity) { // Allocate a new vector size_t _capacity = (v->_capacity << 1) | 0x01; - void **_val = (void **)zp_malloc(_capacity * sizeof(void *)); + void **_val = (void **)z_malloc(_capacity * sizeof(void *)); if (_val != NULL) { (void)memcpy(_val, v->_val, v->_capacity * sizeof(void *)); // Free the old vector - zp_free(v->_val); + z_free(v->_val); // Update the current vector v->_val = _val; diff --git a/src/deprecated/platform.c b/src/deprecated/platform.c new file mode 100644 index 000000000..4081d5b1e --- /dev/null +++ b/src/deprecated/platform.c @@ -0,0 +1,63 @@ +// +// Copyright (c) 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 +// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// +// Contributors: +// ZettaScale Zenoh Team, +// + +#include "zenoh-pico/deprecated/platform.h" + +#include "zenoh-pico/system/platform-common.h" + +uint8_t zp_random_u8(void) { return z_random_u8(); }; +uint16_t zp_random_u16(void) { return z_random_u16(); }; +uint32_t zp_random_u32(void) { return z_random_u32(); }; +uint64_t zp_random_u64(void) { return z_random_u64(); }; +void zp_random_fill(void *buf, size_t len) { return z_random_fill(buf, len); }; + +void *zp_malloc(size_t size) { return z_malloc(size); }; +void *zp_realloc(void *ptr, size_t size) { return z_realloc(ptr, size); }; +void zp_free(void *ptr) { return z_free(ptr); }; + +#if Z_FEATURE_MULTI_THREAD == 1 + +int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), void *arg) { + return z_task_init(task, attr, fun, arg); +}; +int8_t zp_task_join(zp_task_t *task) { return z_task_join(task); }; +void zp_task_free(zp_task_t **task) { return z_task_free(task); }; + +int8_t zp_mutex_init(zp_mutex_t *m) { return z_mutex_init(m); }; +int8_t zp_mutex_free(zp_mutex_t *m) { return z_mutex_free(m); }; +int8_t zp_mutex_lock(zp_mutex_t *m) { return z_mutex_lock(m); }; +int8_t zp_mutex_trylock(zp_mutex_t *m) { return z_mutex_trylock(m); }; +int8_t zp_mutex_unlock(zp_mutex_t *m) { return z_mutex_unlock(m); }; + +int8_t zp_condvar_init(zp_condvar_t *cv) { return z_condvar_init(cv); }; +int8_t zp_condvar_free(zp_condvar_t *cv) { return z_condvar_free(cv); }; + +int8_t zp_condvar_signal(zp_condvar_t *cv) { return z_condvar_signal(cv); }; +int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return z_condvar_wait(cv, m); }; +#endif // Z_FEATURE_MULTI_THREAD == 1 + +int zp_sleep_us(size_t time) { return z_sleep_us(time); }; +int zp_sleep_ms(size_t time) { return z_sleep_ms(time); }; +int zp_sleep_s(size_t time) { return z_sleep_s(time); }; + +zp_clock_t zp_clock_now(void) { return z_clock_now(); }; +unsigned long zp_clock_elapsed_us(zp_clock_t *time) { return z_clock_elapsed_us(time); }; +unsigned long zp_clock_elapsed_ms(zp_clock_t *time) { return z_clock_elapsed_ms(time); }; +unsigned long zp_clock_elapsed_s(zp_clock_t *time) { return z_clock_elapsed_s(time); }; + +zp_time_t zp_time_now(void) { return z_time_now(); }; +const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { return z_time_now_as_str(buf, buflen); }; +unsigned long zp_time_elapsed_us(zp_time_t *time) { return z_time_elapsed_us(time); }; +unsigned long zp_time_elapsed_ms(zp_time_t *time) { return z_time_elapsed_ms(time); }; +unsigned long zp_time_elapsed_s(zp_time_t *time) { return z_time_elapsed_s(time); }; diff --git a/src/link/endpoint.c b/src/link/endpoint.c index dc44a0b30..035e646a6 100644 --- a/src/link/endpoint.c +++ b/src/link/endpoint.c @@ -56,7 +56,7 @@ void _z_locator_free(_z_locator_t **lc) { if (ptr != NULL) { _z_locator_clear(ptr); - zp_free(ptr); + z_free(ptr); *lc = NULL; } } @@ -91,7 +91,7 @@ char *_z_locator_protocol_from_str(const char *str) { const char *p_end = strchr(p_start, LOCATOR_PROTOCOL_SEPARATOR); if ((p_end != NULL) && (p_start != p_end)) { size_t p_len = _z_ptr_char_diff(p_end, p_start) + (size_t)1; - ret = (char *)zp_malloc(p_len); + ret = (char *)z_malloc(p_len); if (ret != NULL) { _z_str_n_copy(ret, p_start, p_len); } @@ -118,7 +118,7 @@ char *_z_locator_address_from_str(const char *str) { if (p_start != p_end) { size_t a_len = _z_ptr_char_diff(p_end, p_start) + (size_t)1; - ret = (char *)zp_malloc(a_len); + ret = (char *)z_malloc(a_len); if (ret != NULL) { _z_str_n_copy(ret, p_start, a_len); } @@ -256,7 +256,7 @@ void __z_locator_onto_str(char *dst, size_t dst_len, const _z_locator_t *loc) { */ char *_z_locator_to_str(const _z_locator_t *l) { size_t len = _z_locator_strlen(l) + (size_t)1; - char *dst = (char *)zp_malloc(len); + char *dst = (char *)z_malloc(len); if (dst != NULL) { __z_locator_onto_str(dst, len, l); } @@ -281,7 +281,7 @@ void _z_endpoint_free(_z_endpoint_t **ep) { _z_locator_clear(&ptr->_locator); _z_str_intmap_clear(&ptr->_config); - zp_free(ptr); + z_free(ptr); *ep = NULL; } } @@ -430,7 +430,7 @@ char *_z_endpoint_to_str(const _z_endpoint_t *endpoint) { } // Reconstruct the endpoint as a string - ret = (char *)zp_malloc(len); + ret = (char *)z_malloc(len); if (ret != NULL) { ret[0] = '\0'; len = len - (size_t)1; diff --git a/src/link/link.c b/src/link/link.c index 674da4bf1..91d484594 100644 --- a/src/link/link.c +++ b/src/link/link.c @@ -130,7 +130,7 @@ void _z_link_free(_z_link_t **l) { if (ptr != NULL) { _z_link_clear(ptr); - zp_free(ptr); + z_free(ptr); *l = NULL; } } diff --git a/src/link/multicast/udp.c b/src/link/multicast/udp.c index 4961948c2..69d359ba1 100644 --- a/src/link/multicast/udp.c +++ b/src/link/multicast/udp.c @@ -35,7 +35,7 @@ char *__z_parse_port_segment_udp_multicast(const char *address) { const char *p_end = &address[strlen(address)]; size_t len = _z_ptr_char_diff(p_end, p_start) + (size_t)1; - ret = (char *)zp_malloc(len); + ret = (char *)z_malloc(len); if (ret != NULL) { _z_str_n_copy(ret, p_start, len); } @@ -55,7 +55,7 @@ char *__z_parse_address_segment_udp_multicast(const char *address) { p_start = _z_cptr_char_offset(p_start, 1); p_end = _z_cptr_char_offset(p_end, -1); size_t len = _z_ptr_char_diff(p_end, p_start) + (size_t)1; - ret = (char *)zp_malloc(len); + ret = (char *)z_malloc(len); if (ret != NULL) { _z_str_n_copy(ret, p_start, len); } @@ -63,7 +63,7 @@ char *__z_parse_address_segment_udp_multicast(const char *address) { // IPv4 else { size_t len = _z_ptr_char_diff(p_end, p_start) + (size_t)1; - ret = (char *)zp_malloc(len); + ret = (char *)z_malloc(len); if (ret != NULL) { _z_str_n_copy(ret, p_start, len); } @@ -84,7 +84,7 @@ int8_t _z_endpoint_udp_multicast_valid(_z_endpoint_t *endpoint) { if (s_address == NULL) { ret = _Z_ERR_CONFIG_LOCATOR_INVALID; } else { - zp_free(s_address); + z_free(s_address); } } @@ -97,7 +97,7 @@ int8_t _z_endpoint_udp_multicast_valid(_z_endpoint_t *endpoint) { if ((port < (uint32_t)1) || (port > (uint32_t)65355)) { // Port numbers should range from 1 to 65355 ret = _Z_ERR_CONFIG_LOCATOR_INVALID; } - zp_free(s_port); + z_free(s_port); } } @@ -183,8 +183,8 @@ int8_t _z_new_link_udp_multicast(_z_link_t *zl, _z_endpoint_t endpoint) { char *s_port = __z_parse_port_segment_udp_multicast(endpoint._locator._address); ret = _z_create_endpoint_udp(&zl->_socket._udp._rep, s_address, s_port); memset(&zl->_socket._udp._lep, 0, sizeof(zl->_socket._udp._lep)); - zp_free(s_address); - zp_free(s_port); + z_free(s_address); + z_free(s_port); zl->_open_f = _z_f_link_open_udp_multicast; zl->_listen_f = _z_f_link_listen_udp_multicast; diff --git a/src/link/unicast/tcp.c b/src/link/unicast/tcp.c index dfec4dd6a..a6cf3de7a 100644 --- a/src/link/unicast/tcp.c +++ b/src/link/unicast/tcp.c @@ -35,7 +35,7 @@ char *__z_parse_port_segment_tcp(char *address) { const char *p_end = &address[strlen(address)]; size_t len = _z_ptr_char_diff(p_end, p_start) + (size_t)1; - ret = (char *)zp_malloc(len); + ret = (char *)z_malloc(len); if (ret != NULL) { _z_str_n_copy(ret, p_start, len); } @@ -55,7 +55,7 @@ char *__z_parse_address_segment_tcp(char *address) { p_start = _z_cptr_char_offset(p_start, 1); p_end = _z_cptr_char_offset(p_end, -1); size_t len = _z_ptr_char_diff(p_end, p_start) + (size_t)1; - ret = (char *)zp_malloc(len); + ret = (char *)z_malloc(len); if (ret != NULL) { _z_str_n_copy(ret, p_start, len); } @@ -63,7 +63,7 @@ char *__z_parse_address_segment_tcp(char *address) { // IPv4 else { size_t len = _z_ptr_char_diff(p_end, p_start) + (size_t)1; - ret = (char *)zp_malloc(len); + ret = (char *)z_malloc(len); if (ret != NULL) { _z_str_n_copy(ret, p_start, len); } @@ -84,7 +84,7 @@ int8_t _z_endpoint_tcp_valid(_z_endpoint_t *endpoint) { if (s_address == NULL) { ret = _Z_ERR_CONFIG_LOCATOR_INVALID; } else { - zp_free(s_address); + z_free(s_address); } } @@ -97,7 +97,7 @@ int8_t _z_endpoint_tcp_valid(_z_endpoint_t *endpoint) { if ((port < (uint32_t)1) || (port > (uint32_t)65355)) { // Port numbers should range from 1 to 65355 ret = _Z_ERR_CONFIG_LOCATOR_INVALID; } - zp_free(s_port); + z_free(s_port); } } @@ -166,8 +166,8 @@ int8_t _z_new_link_tcp(_z_link_t *zl, _z_endpoint_t *endpoint) { char *s_address = __z_parse_address_segment_tcp(endpoint->_locator._address); char *s_port = __z_parse_port_segment_tcp(endpoint->_locator._address); ret = _z_create_endpoint_tcp(&zl->_socket._tcp._rep, s_address, s_port); - zp_free(s_address); - zp_free(s_port); + z_free(s_address); + z_free(s_port); zl->_open_f = _z_f_link_open_tcp; zl->_listen_f = _z_f_link_listen_tcp; diff --git a/src/link/unicast/udp.c b/src/link/unicast/udp.c index c10c4c0f3..cd93cdff7 100644 --- a/src/link/unicast/udp.c +++ b/src/link/unicast/udp.c @@ -35,7 +35,7 @@ char *__z_parse_port_segment_udp_unicast(char *address) { const char *p_end = &address[strlen(address)]; size_t len = _z_ptr_char_diff(p_end, p_start) + (size_t)1; - ret = (char *)zp_malloc(len); + ret = (char *)z_malloc(len); if (ret != NULL) { _z_str_n_copy(ret, p_start, len); } @@ -55,7 +55,7 @@ char *__z_parse_address_segment_udp_unicast(char *address) { p_start = _z_cptr_char_offset(p_start, 1); p_end = _z_cptr_char_offset(p_end, -1); size_t len = _z_ptr_char_diff(p_end, p_start) + (size_t)1; - ret = (char *)zp_malloc(len); + ret = (char *)z_malloc(len); if (ret != NULL) { _z_str_n_copy(ret, p_start, len); } @@ -63,7 +63,7 @@ char *__z_parse_address_segment_udp_unicast(char *address) { // IPv4 else { size_t len = _z_ptr_char_diff(p_end, p_start) + (size_t)1; - ret = (char *)zp_malloc(len); + ret = (char *)z_malloc(len); if (ret != NULL) { _z_str_n_copy(ret, p_start, len); } @@ -84,7 +84,7 @@ int8_t _z_endpoint_udp_unicast_valid(_z_endpoint_t *endpoint) { if (s_address == NULL) { ret = _Z_ERR_CONFIG_LOCATOR_INVALID; } else { - zp_free(s_address); + z_free(s_address); } } @@ -97,7 +97,7 @@ int8_t _z_endpoint_udp_unicast_valid(_z_endpoint_t *endpoint) { if ((port < (uint32_t)1) || (port > (uint32_t)65355)) { // Port numbers should range from 1 to 65355 ret = _Z_ERR_CONFIG_LOCATOR_INVALID; } - zp_free(s_port); + z_free(s_port); } } @@ -172,8 +172,8 @@ int8_t _z_new_link_udp_unicast(_z_link_t *zl, _z_endpoint_t endpoint) { char *s_address = __z_parse_address_segment_udp_unicast(endpoint._locator._address); char *s_port = __z_parse_port_segment_udp_unicast(endpoint._locator._address); ret = _z_create_endpoint_udp(&zl->_socket._udp._rep, s_address, s_port); - zp_free(s_address); - zp_free(s_port); + z_free(s_address); + z_free(s_port); zl->_open_f = _z_f_link_open_udp_unicast; zl->_listen_f = _z_f_link_listen_udp_unicast; diff --git a/src/link/unicast/ws.c b/src/link/unicast/ws.c index f67d1aeda..f59fde872 100644 --- a/src/link/unicast/ws.c +++ b/src/link/unicast/ws.c @@ -36,7 +36,7 @@ char *__z_parse_port_segment_ws(char *address) { const char *p_end = &address[strlen(address)]; size_t len = _z_ptr_char_diff(p_end, p_start) + (size_t)1; - ret = (char *)zp_malloc(len); + ret = (char *)z_malloc(len); if (ret != NULL) { _z_str_n_copy(ret, p_start, len); } @@ -56,7 +56,7 @@ char *__z_parse_address_segment_ws(char *address) { p_start = _z_cptr_char_offset(p_start, 1); p_end = _z_cptr_char_offset(p_end, -1); size_t len = _z_ptr_char_diff(p_end, p_start) + (size_t)1; - ret = (char *)zp_malloc(len); + ret = (char *)z_malloc(len); if (ret != NULL) { _z_str_n_copy(ret, p_start, len); } @@ -64,7 +64,7 @@ char *__z_parse_address_segment_ws(char *address) { // IPv4 else { size_t len = _z_ptr_char_diff(p_end, p_start) + (size_t)1; - ret = (char *)zp_malloc(len); + ret = (char *)z_malloc(len); if (ret != NULL) { _z_str_n_copy(ret, p_start, len); } @@ -85,7 +85,7 @@ int8_t _z_endpoint_ws_valid(_z_endpoint_t *endpoint) { if (s_addr == NULL) { ret = _Z_ERR_CONFIG_LOCATOR_INVALID; } else { - zp_free(s_addr); + z_free(s_addr); } } @@ -98,7 +98,7 @@ int8_t _z_endpoint_ws_valid(_z_endpoint_t *endpoint) { if ((port < (uint32_t)1) || (port > (uint32_t)65355)) { // Port numbers should range from 1 to 65355 ret = _Z_ERR_CONFIG_LOCATOR_INVALID; } - zp_free(s_port); + z_free(s_port); } } @@ -167,8 +167,8 @@ int8_t _z_new_link_ws(_z_link_t *zl, _z_endpoint_t *endpoint) { char *s_addr = __z_parse_address_segment_ws(endpoint->_locator._address); char *s_port = __z_parse_port_segment_ws(endpoint->_locator._address); ret = _z_create_endpoint_ws(&zl->_socket._ws._rep, s_addr, s_port); - zp_free(s_addr); - zp_free(s_port); + z_free(s_addr); + z_free(s_port); zl->_open_f = _z_f_link_open_ws; zl->_listen_f = _z_f_link_listen_ws; diff --git a/src/net/config.c b/src/net/config.c index 58bd252c3..7b0457836 100644 --- a/src/net/config.c +++ b/src/net/config.c @@ -18,7 +18,7 @@ #include "zenoh-pico/net/config.h" _z_config_t *_z_config_empty(void) { - _z_config_t *config = (_z_config_t *)zp_malloc(sizeof(_z_config_t)); + _z_config_t *config = (_z_config_t *)z_malloc(sizeof(_z_config_t)); if (config != NULL) { _z_config_init(config); } diff --git a/src/net/memory.c b/src/net/memory.c index b8cd9f55c..33f7582ec 100644 --- a/src/net/memory.c +++ b/src/net/memory.c @@ -44,7 +44,7 @@ void _z_sample_free(_z_sample_t **sample) { if (ptr != NULL) { _z_sample_clear(ptr); - zp_free(ptr); + z_free(ptr); *sample = NULL; } } @@ -61,7 +61,7 @@ void _z_hello_free(_z_hello_t **hello) { if (ptr != NULL) { _z_hello_clear(ptr); - zp_free(ptr); + z_free(ptr); *hello = NULL; } } @@ -77,7 +77,7 @@ void _z_reply_data_free(_z_reply_data_t **reply_data) { if (ptr != NULL) { _z_reply_data_clear(ptr); - zp_free(ptr); + z_free(ptr); *reply_data = NULL; } } @@ -93,7 +93,7 @@ void _z_value_free(_z_value_t **value) { if (ptr != NULL) { _z_value_clear(ptr); - zp_free(ptr); + z_free(ptr); *value = NULL; } } diff --git a/src/net/primitives.c b/src/net/primitives.c index 4977acc32..c4c144d06 100644 --- a/src/net/primitives.c +++ b/src/net/primitives.c @@ -101,7 +101,7 @@ int8_t _z_undeclare_resource(_z_session_t *zn, uint16_t rid) { _z_publisher_t *_z_declare_publisher(_z_session_rc_t *zn, _z_keyexpr_t keyexpr, z_congestion_control_t congestion_control, z_priority_t priority) { // Allocate publisher - _z_publisher_t *ret = (_z_publisher_t *)zp_malloc(sizeof(_z_publisher_t)); + _z_publisher_t *ret = (_z_publisher_t *)z_malloc(sizeof(_z_publisher_t)); if (ret == NULL) { return NULL; } @@ -197,7 +197,7 @@ _z_subscriber_t *_z_declare_subscriber(_z_session_rc_t *zn, _z_keyexpr_t keyexpr s._arg = arg; // Allocate subscriber - _z_subscriber_t *ret = (_z_subscriber_t *)zp_malloc(sizeof(_z_subscriber_t)); + _z_subscriber_t *ret = (_z_subscriber_t *)z_malloc(sizeof(_z_subscriber_t)); if (ret == NULL) { _z_subscription_clear(&s); return NULL; @@ -279,7 +279,7 @@ _z_queryable_t *_z_declare_queryable(_z_session_rc_t *zn, _z_keyexpr_t keyexpr, q._arg = arg; // Allocate queryable - _z_queryable_t *ret = (_z_queryable_t *)zp_malloc(sizeof(_z_queryable_t)); + _z_queryable_t *ret = (_z_queryable_t *)z_malloc(sizeof(_z_queryable_t)); if (ret == NULL) { _z_session_queryable_clear(&q); return NULL; @@ -387,7 +387,7 @@ int8_t _z_query(_z_session_t *zn, _z_keyexpr_t keyexpr, const char *parameters, int8_t ret = _Z_RES_OK; // Create the pending query object - _z_pending_query_t *pq = (_z_pending_query_t *)zp_malloc(sizeof(_z_pending_query_t)); + _z_pending_query_t *pq = (_z_pending_query_t *)z_malloc(sizeof(_z_pending_query_t)); if (pq != NULL) { pq->_id = _z_get_query_id(zn); pq->_key = _z_get_expanded_key_from_key(zn, &keyexpr); diff --git a/src/net/publish.c b/src/net/publish.c index a17dbc97a..7b2d1bffc 100644 --- a/src/net/publish.c +++ b/src/net/publish.c @@ -25,7 +25,7 @@ void _z_publisher_free(_z_publisher_t **pub) { if (ptr != NULL) { _z_publisher_clear(ptr); - zp_free(ptr); + z_free(ptr); *pub = NULL; } } diff --git a/src/net/query.c b/src/net/query.c index 41b290f52..74b1ad88c 100644 --- a/src/net/query.c +++ b/src/net/query.c @@ -24,7 +24,7 @@ void _z_query_clear(_z_query_t *q) { } // Clean up memory _z_msg_clear(&z_msg); - zp_free(q->_parameters); + z_free(q->_parameters); _z_keyexpr_clear(&q->_key); _z_value_clear(&q->_value); // Ideally free session rc if you have one @@ -36,7 +36,7 @@ _z_query_t _z_query_create(const _z_value_t *value, const _z_keyexpr_t *key, con _z_query_t q; q._request_id = request_id; q._zn = zn; // Ideally would have been an rc - q._parameters = (char *)zp_malloc(parameters->len + 1); + q._parameters = (char *)z_malloc(parameters->len + 1); memcpy(q._parameters, parameters->start, parameters->len); q._parameters[parameters->len] = 0; q._anyke = (strstr(q._parameters, Z_SELECTOR_QUERY_MATCH) == NULL) ? false : true; @@ -56,7 +56,7 @@ void _z_queryable_free(_z_queryable_t **qbl) { if (ptr != NULL) { _z_queryable_clear(ptr); - zp_free(ptr); + z_free(ptr); *qbl = NULL; } } diff --git a/src/net/session.c b/src/net/session.c index 4c386e3a3..8925c962e 100644 --- a/src/net/session.c +++ b/src/net/session.c @@ -150,7 +150,7 @@ int8_t _z_open(_z_session_t *zn, _z_config_t *config) { void _z_close(_z_session_t *zn) { _z_session_close(zn, _Z_CLOSE_GENERIC); } _z_config_t *_z_info(const _z_session_t *zn) { - _z_config_t *ps = (_z_config_t *)zp_malloc(sizeof(_z_config_t)); + _z_config_t *ps = (_z_config_t *)z_malloc(sizeof(_z_config_t)); if (ps != NULL) { _z_config_init(ps); _z_bytes_t local_zid = _z_bytes_wrap(zn->_local_zid.id, _z_id_len(zn->_local_zid)); @@ -179,10 +179,10 @@ int8_t _zp_send_keep_alive(_z_session_t *zn) { return _z_send_keep_alive(&zn->_t int8_t _zp_send_join(_z_session_t *zn) { return _z_send_join(&zn->_tp); } #if Z_FEATURE_MULTI_THREAD == 1 -int8_t _zp_start_read_task(_z_session_t *zn, zp_task_attr_t *attr) { +int8_t _zp_start_read_task(_z_session_t *zn, z_task_attr_t *attr) { int8_t ret = _Z_RES_OK; // Allocate task - zp_task_t *task = (zp_task_t *)zp_malloc(sizeof(zp_task_t)); + z_task_t *task = (z_task_t *)z_malloc(sizeof(z_task_t)); if (task == NULL) { ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; } @@ -203,15 +203,15 @@ int8_t _zp_start_read_task(_z_session_t *zn, zp_task_attr_t *attr) { } // Free task if operation failed if (ret != _Z_RES_OK) { - zp_free(task); + z_free(task); } return ret; } -int8_t _zp_start_lease_task(_z_session_t *zn, zp_task_attr_t *attr) { +int8_t _zp_start_lease_task(_z_session_t *zn, z_task_attr_t *attr) { int8_t ret = _Z_RES_OK; // Allocate task - zp_task_t *task = (zp_task_t *)zp_malloc(sizeof(zp_task_t)); + z_task_t *task = (z_task_t *)z_malloc(sizeof(z_task_t)); if (task == NULL) { ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; } @@ -232,7 +232,7 @@ int8_t _zp_start_lease_task(_z_session_t *zn, zp_task_attr_t *attr) { } // Free task if operation failed if (ret != _Z_RES_OK) { - zp_free(task); + z_free(task); } return ret; } diff --git a/src/net/subscribe.c b/src/net/subscribe.c index 316966897..44eb83770 100644 --- a/src/net/subscribe.c +++ b/src/net/subscribe.c @@ -41,7 +41,7 @@ void _z_subscriber_free(_z_subscriber_t **sub) { if (ptr != NULL) { _z_subscriber_clear(ptr); - zp_free(ptr); + z_free(ptr); *sub = NULL; } } diff --git a/src/protocol/codec.c b/src/protocol/codec.c index 5320f12b1..65e13ec07 100644 --- a/src/protocol/codec.c +++ b/src/protocol/codec.c @@ -362,8 +362,8 @@ int8_t _z_str_decode(char **str, _z_zbuf_t *zbf) { _z_zint_t len = 0; ret |= _z_zint_decode(&len, zbf); if (ret == _Z_RES_OK) { - if (_z_zbuf_len(zbf) >= len) { // Check if we have enough bytes to read - char *tmp = (char *)zp_malloc(len + (size_t)1); // Allocate space for the string terminator + if (_z_zbuf_len(zbf) >= len) { // Check if we have enough bytes to read + char *tmp = (char *)z_malloc(len + (size_t)1); // Allocate space for the string terminator if (tmp != NULL) { tmp[len] = '\0'; _z_zbuf_read_bytes(zbf, (uint8_t *)tmp, 0, len); diff --git a/src/protocol/codec/declarations.c b/src/protocol/codec/declarations.c index 554d84a59..f139fbc3a 100644 --- a/src/protocol/codec/declarations.c +++ b/src/protocol/codec/declarations.c @@ -218,7 +218,7 @@ int8_t _z_undecl_decode_extensions(_z_msg_ext_t *extension, void *ctx) { _Z_RETURN_IF_ERR(_z_zint16_decode(&ke->_id, zbf)); if (_Z_HAS_FLAG(header, 1)) { size_t len = _z_zbuf_len(zbf); - ke->_suffix = zp_malloc(len + 1); + ke->_suffix = z_malloc(len + 1); if (!ke->_suffix) { return _Z_ERR_SYSTEM_OUT_OF_MEMORY; } @@ -255,7 +255,7 @@ int8_t _z_decl_commons_decode(_z_zbuf_t *zbf, uint8_t header, _Bool *has_extensi if (_z_zbuf_len(zbf) < len) { return _Z_ERR_MESSAGE_DESERIALIZATION_FAILED; } - ke->_suffix = zp_malloc(len + 1); + ke->_suffix = z_malloc(len + 1); if (ke->_suffix == NULL) { return _Z_ERR_SYSTEM_OUT_OF_MEMORY; } diff --git a/src/protocol/codec/ext.c b/src/protocol/codec/ext.c index bc7c18c5d..8d99054b5 100644 --- a/src/protocol/codec/ext.c +++ b/src/protocol/codec/ext.c @@ -154,7 +154,7 @@ int8_t _z_msg_ext_vec_encode(_z_wbuf_t *wbf, const _z_msg_ext_vec_t *extensions) return ret; } int8_t _z_msg_ext_vec_push_callback(_z_msg_ext_t *extension, _z_msg_ext_vec_t *extensions) { - _z_msg_ext_t *ext = (_z_msg_ext_t *)zp_malloc(sizeof(_z_msg_ext_t)); + _z_msg_ext_t *ext = (_z_msg_ext_t *)z_malloc(sizeof(_z_msg_ext_t)); *ext = *extension; *extension = _z_msg_ext_make_unit(0); _z_msg_ext_vec_append(extensions, extension); @@ -181,13 +181,13 @@ int8_t _z_msg_ext_unknown_error(_z_msg_ext_t *extension, uint8_t trace_id) { } case _Z_MSG_EXT_ENC_ZBUF: { _z_bytes_t buf = extension->_body._zbuf._val; - char *hex = zp_malloc(buf.len * 2 + 1); + char *hex = z_malloc(buf.len * 2 + 1); for (size_t i = 0; i < buf.len; ++i) { snprintf(hex + 2 * i, 3, "%02x", buf.start[i]); } _Z_ERROR("Unknown mandatory extension found (extension_id: %02x, trace_id: %02x), ZBUF(%.*s)", ext_id, trace_id, (int)buf.len * 2, hex); - zp_free(hex); + z_free(hex); break; } default: { diff --git a/src/protocol/codec/message.c b/src/protocol/codec/message.c index 0f8438653..a182326be 100644 --- a/src/protocol/codec/message.c +++ b/src/protocol/codec/message.c @@ -150,7 +150,7 @@ int8_t _z_locators_encode(_z_wbuf_t *wbf, const _z_locator_array_t *la) { for (size_t i = 0; i < la->_len; i++) { char *s = _z_locator_to_str(&la->_val[i]); _Z_RETURN_IF_ERR(_z_str_encode(wbf, s)) - zp_free(s); + z_free(s); } return ret; @@ -172,7 +172,7 @@ int8_t _z_locators_decode_na(_z_locator_array_t *a_loc, _z_zbuf_t *zbf) { if (ret == _Z_RES_OK) { _z_locator_init(&a_loc->_val[i]); ret |= _z_locator_from_str(&a_loc->_val[i], str); - zp_free(str); + z_free(str); } else { a_loc->_len = i; } diff --git a/src/protocol/codec/transport.c b/src/protocol/codec/transport.c index 1eaf27a41..66b0a1142 100644 --- a/src/protocol/codec/transport.c +++ b/src/protocol/codec/transport.c @@ -350,7 +350,7 @@ int8_t _z_frame_decode(_z_t_msg_frame_t *msg, _z_zbuf_t *zbf, uint8_t header) { while (_z_zbuf_len(zbf) > 0) { // Mark the reading position of the iobfer size_t r_pos = _z_zbuf_get_rpos(zbf); - _z_network_message_t *nm = (_z_network_message_t *)zp_malloc(sizeof(_z_network_message_t)); + _z_network_message_t *nm = (_z_network_message_t *)z_malloc(sizeof(_z_network_message_t)); memset(nm, 0, sizeof(_z_network_message_t)); ret |= _z_network_message_decode(nm, zbf); if (ret == _Z_RES_OK) { diff --git a/src/protocol/config.c b/src/protocol/config.c index ffee65656..3c70a27e6 100644 --- a/src/protocol/config.c +++ b/src/protocol/config.c @@ -81,7 +81,7 @@ int8_t _z_str_intmap_from_strn(_z_str_intmap_t *strint, const char *s, uint8_t a } size_t p_value_len = _z_ptr_char_diff(p_value_end, p_value_start) + (size_t)1; - char *p_value = (char *)zp_malloc(p_value_len); + char *p_value = (char *)z_malloc(p_value_len); if (p_value != NULL) { _z_str_n_copy(p_value, p_value_start, p_value_len); @@ -155,7 +155,7 @@ char *_z_str_intmap_to_str(const _z_str_intmap_t *s, uint8_t argc, _z_str_intmap // Calculate the string length to allocate size_t len = _z_str_intmap_strlen(s, argc, argv) + (size_t)1; // Build the string - char *dst = (char *)zp_malloc(len); + char *dst = (char *)z_malloc(len); if (dst != NULL) { _z_str_intmap_onto_str(dst, len, s, argc, argv); } diff --git a/src/protocol/definitions/network.c b/src/protocol/definitions/network.c index af5192b14..056558c3d 100644 --- a/src/protocol/definitions/network.c +++ b/src/protocol/definitions/network.c @@ -139,7 +139,7 @@ void _z_n_msg_free(_z_network_message_t **msg) { if (ptr != NULL) { _z_n_msg_clear(ptr); - zp_free(ptr); + z_free(ptr); *msg = NULL; } } diff --git a/src/protocol/iobuf.c b/src/protocol/iobuf.c index 67802e9fe..c5700886f 100644 --- a/src/protocol/iobuf.c +++ b/src/protocol/iobuf.c @@ -40,7 +40,7 @@ void __z_iosli_init(_z_iosli_t *ios, size_t capacity) { ios->_w_pos = 0; ios->_capacity = capacity; ios->_is_alloc = true; - ios->_buf = (uint8_t *)zp_malloc(capacity); + ios->_buf = (uint8_t *)z_malloc(capacity); if (ios->_buf == NULL) { ios->_capacity = 0; ios->_is_alloc = false; @@ -54,7 +54,7 @@ _z_iosli_t _z_iosli_make(size_t capacity) { } _z_iosli_t *_z_iosli_new(size_t capacity) { - _z_iosli_t *pios = (_z_iosli_t *)zp_malloc(sizeof(_z_iosli_t)); + _z_iosli_t *pios = (_z_iosli_t *)z_malloc(sizeof(_z_iosli_t)); if (pios != NULL) { __z_iosli_init(pios, capacity); } @@ -119,7 +119,7 @@ size_t _z_iosli_size(const _z_iosli_t *ios) { void _z_iosli_clear(_z_iosli_t *ios) { if ((ios->_is_alloc == true) && (ios->_buf != NULL)) { - zp_free(ios->_buf); + z_free(ios->_buf); ios->_buf = NULL; } } @@ -130,7 +130,7 @@ void _z_iosli_free(_z_iosli_t **ios) { if (ptr != NULL) { _z_iosli_clear(ptr); - zp_free(ptr); + z_free(ptr); *ios = NULL; } } @@ -141,7 +141,7 @@ void _z_iosli_copy(_z_iosli_t *dst, const _z_iosli_t *src) { dst->_capacity = src->_capacity; dst->_is_alloc = src->_is_alloc; if (dst->_is_alloc == true) { - dst->_buf = (uint8_t *)zp_malloc(src->_capacity); + dst->_buf = (uint8_t *)z_malloc(src->_capacity); if (dst->_buf != NULL) { (void)memcpy(dst->_buf, src->_buf, src->_capacity); } @@ -151,7 +151,7 @@ void _z_iosli_copy(_z_iosli_t *dst, const _z_iosli_t *src) { } _z_iosli_t *_z_iosli_clone(const _z_iosli_t *src) { - _z_iosli_t *dst = (_z_iosli_t *)zp_malloc(_z_iosli_size(src)); + _z_iosli_t *dst = (_z_iosli_t *)z_malloc(_z_iosli_size(src)); if (dst != NULL) { _z_iosli_copy(dst, src); } @@ -233,7 +233,7 @@ void _z_zbuf_free(_z_zbuf_t **zbf) { if (ptr != NULL) { _z_iosli_clear(&ptr->_ios); - zp_free(ptr); + z_free(ptr); *zbf = NULL; } } @@ -245,7 +245,7 @@ void _z_wbuf_add_iosli(_z_wbuf_t *wbf, _z_iosli_t *ios) { } _z_iosli_t *__z_wbuf_new_iosli(size_t capacity) { - _z_iosli_t *ios = (_z_iosli_t *)zp_malloc(sizeof(_z_iosli_t)); + _z_iosli_t *ios = (_z_iosli_t *)z_malloc(sizeof(_z_iosli_t)); if (ios != NULL) { __z_iosli_init(ios, capacity); } @@ -559,7 +559,7 @@ void _z_wbuf_free(_z_wbuf_t **wbf) { if (ptr != NULL) { _z_wbuf_clear(ptr); - zp_free(ptr); + z_free(ptr); *wbf = NULL; } } diff --git a/src/protocol/keyexpr.c b/src/protocol/keyexpr.c index 4f1b10a60..49fefcbf7 100644 --- a/src/protocol/keyexpr.c +++ b/src/protocol/keyexpr.c @@ -69,7 +69,7 @@ void _z_keyexpr_free(_z_keyexpr_t **rk) { if (ptr != NULL) { _z_keyexpr_clear(ptr); - zp_free(ptr); + z_free(ptr); *rk = NULL; } } diff --git a/src/session/query.c b/src/session/query.c index 491be698d..83c474049 100644 --- a/src/session/query.c +++ b/src/session/query.c @@ -24,7 +24,7 @@ #if Z_FEATURE_QUERY == 1 _z_reply_t *_z_reply_alloc_and_move(_z_reply_t *_reply) { - _z_reply_t *reply = (_z_reply_t *)zp_malloc(sizeof(_z_reply_t)); + _z_reply_t *reply = (_z_reply_t *)z_malloc(sizeof(_z_reply_t)); if (reply != NULL) { *reply = *_reply; (void)memset(_reply, 0, sizeof(_z_reply_t)); @@ -40,7 +40,7 @@ void _z_reply_free(_z_reply_t **reply) { if (*reply != NULL) { _z_reply_clear(ptr); - zp_free(ptr); + z_free(ptr); *reply = NULL; } } @@ -62,7 +62,7 @@ void _z_pending_query_clear(_z_pending_query_t *pen_qry) { pen_qry->_dropper(pen_qry->_drop_arg); } - zp_free(pen_qry->_call_arg); + z_free(pen_qry->_call_arg); _z_keyexpr_clear(&pen_qry->_key); _z_str_clear(pen_qry->_parameters); @@ -104,13 +104,13 @@ _z_pending_query_t *__unsafe__z_get_pending_query_by_id(_z_session_t *zn, const _z_pending_query_t *_z_get_pending_query_by_id(_z_session_t *zn, const _z_zint_t id) { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_pending_query_t *pql = __unsafe__z_get_pending_query_by_id(zn, id); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 return pql; } @@ -122,7 +122,7 @@ int8_t _z_register_pending_query(_z_session_t *zn, _z_pending_query_t *pen_qry) pen_qry->_parameters); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_pending_query_t *pql = __unsafe__z_get_pending_query_by_id(zn, pen_qry->_id); @@ -133,7 +133,7 @@ int8_t _z_register_pending_query(_z_session_t *zn, _z_pending_query_t *pen_qry) } #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 return ret; @@ -145,7 +145,7 @@ int8_t _z_trigger_query_reply_partial(_z_session_t *zn, const _z_zint_t id, cons int8_t ret = _Z_RES_OK; #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_pending_query_t *pen_qry = __unsafe__z_get_pending_query_by_id(zn, id); @@ -196,7 +196,7 @@ int8_t _z_trigger_query_reply_partial(_z_session_t *zn, const _z_zint_t id, cons if (drop == false) { // Cache most recent reply - pen_rep = (_z_pending_reply_t *)zp_malloc(sizeof(_z_pending_reply_t)); + pen_rep = (_z_pending_reply_t *)z_malloc(sizeof(_z_pending_reply_t)); if (pen_rep != NULL) { if (pen_qry->_consolidation == Z_CONSOLIDATION_MODE_MONOTONIC) { // No need to store the whole reply in the monotonic mode. @@ -217,7 +217,7 @@ int8_t _z_trigger_query_reply_partial(_z_session_t *zn, const _z_zint_t id, cons } #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 // Trigger the user callback @@ -236,7 +236,7 @@ int8_t _z_trigger_query_reply_final(_z_session_t *zn, _z_zint_t id) { int8_t ret = _Z_RES_OK; #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 // Final reply received for unknown query id @@ -262,7 +262,7 @@ int8_t _z_trigger_query_reply_final(_z_session_t *zn, _z_zint_t id) { } #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 return ret; @@ -270,25 +270,25 @@ int8_t _z_trigger_query_reply_final(_z_session_t *zn, _z_zint_t id) { void _z_unregister_pending_query(_z_session_t *zn, _z_pending_query_t *pen_qry) { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 zn->_pending_queries = _z_pending_query_list_drop_filter(zn->_pending_queries, _z_pending_query_eq, pen_qry); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 } void _z_flush_pending_queries(_z_session_t *zn) { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_pending_query_list_free(&zn->_pending_queries); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 } #endif diff --git a/src/session/queryable.c b/src/session/queryable.c index ce4ba8b19..ce6044a54 100644 --- a/src/session/queryable.c +++ b/src/session/queryable.c @@ -96,13 +96,13 @@ _z_session_queryable_rc_list_t *__unsafe_z_get_session_queryable_by_key(_z_sessi _z_session_queryable_rc_t *_z_get_session_queryable_by_id(_z_session_t *zn, const _z_zint_t id) { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_session_queryable_rc_t *qle = __unsafe_z_get_session_queryable_by_id(zn, id); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 return qle; @@ -110,14 +110,14 @@ _z_session_queryable_rc_t *_z_get_session_queryable_by_id(_z_session_t *zn, cons _z_session_queryable_rc_list_t *_z_get_session_queryable_by_key(_z_session_t *zn, const _z_keyexpr_t *keyexpr) { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_keyexpr_t key = __unsafe_z_get_expanded_key_from_key(zn, keyexpr); _z_session_queryable_rc_list_t *qles = __unsafe_z_get_session_queryable_by_key(zn, key); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 return qles; @@ -128,17 +128,17 @@ _z_session_queryable_rc_t *_z_register_session_queryable(_z_session_t *zn, _z_se _z_session_queryable_rc_t *ret = NULL; #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 - ret = (_z_session_queryable_rc_t *)zp_malloc(sizeof(_z_session_queryable_rc_t)); + ret = (_z_session_queryable_rc_t *)z_malloc(sizeof(_z_session_queryable_rc_t)); if (ret != NULL) { *ret = _z_session_queryable_rc_new_from_val(*q); zn->_local_queryable = _z_session_queryable_rc_list_push(zn->_local_queryable, ret); } #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 return ret; @@ -148,7 +148,7 @@ int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *msgq, const int8_t ret = _Z_RES_OK; #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_keyexpr_t key = __unsafe_z_get_expanded_key_from_key(zn, &q_key); @@ -156,7 +156,7 @@ int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *msgq, const _z_session_queryable_rc_list_t *qles = __unsafe_z_get_session_queryable_by_key(zn, key); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 // Build the z_query @@ -175,7 +175,7 @@ int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *msgq, const _z_session_queryable_rc_list_free(&qles); } else { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 ret = _Z_ERR_KEYEXPR_UNKNOWN; @@ -186,26 +186,26 @@ int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *msgq, const void _z_unregister_session_queryable(_z_session_t *zn, _z_session_queryable_rc_t *qle) { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 zn->_local_queryable = _z_session_queryable_rc_list_drop_filter(zn->_local_queryable, _z_session_queryable_rc_eq, qle); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 } void _z_flush_session_queryable(_z_session_t *zn) { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_session_queryable_rc_list_free(&zn->_local_queryable); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 } diff --git a/src/session/resource.c b/src/session/resource.c index 8841037cf..ca107f4e7 100644 --- a/src/session/resource.c +++ b/src/session/resource.c @@ -35,7 +35,7 @@ void _z_resource_free(_z_resource_t **res) { if (ptr != NULL) { _z_resource_clear(ptr); - zp_free(ptr); + z_free(ptr); *res = NULL; } } @@ -119,7 +119,7 @@ _z_keyexpr_t __z_get_expanded_key_from_key(_z_resource_list_t *xs, const _z_keye if (len != (size_t)0) { char *rname = NULL; - rname = (char *)zp_malloc(len); + rname = (char *)z_malloc(len); if (rname != NULL) { rname[0] = '\0'; // NULL terminator must be set (required to strcat) len = len - (size_t)1; @@ -175,13 +175,13 @@ _z_keyexpr_t __unsafe_z_get_expanded_key_from_key(_z_session_t *zn, const _z_key _z_resource_t *_z_get_resource_by_id(_z_session_t *zn, uint16_t mapping, _z_zint_t rid) { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_resource_t *res = __unsafe_z_get_resource_by_id(zn, mapping, rid); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 return res; @@ -192,13 +192,13 @@ _z_resource_t *_z_get_resource_by_key(_z_session_t *zn, const _z_keyexpr_t *keye return _z_get_resource_by_id(zn, _z_keyexpr_mapping_id(keyexpr), keyexpr->_id); } #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_resource_t *res = __unsafe_z_get_resource_by_key(zn, keyexpr); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 return res; @@ -206,12 +206,12 @@ _z_resource_t *_z_get_resource_by_key(_z_session_t *zn, const _z_keyexpr_t *keye _z_keyexpr_t _z_get_expanded_key_from_key(_z_session_t *zn, const _z_keyexpr_t *keyexpr) { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_keyexpr_t res = __unsafe_z_get_expanded_key_from_key(zn, keyexpr); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 return res; @@ -225,7 +225,7 @@ int16_t _z_register_resource(_z_session_t *zn, _z_keyexpr_t key, uint16_t id, ui uint16_t parent_mapping = _z_keyexpr_mapping_id(&key); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 if (key._id != Z_RESOURCE_ID_NONE) { @@ -238,7 +238,7 @@ int16_t _z_register_resource(_z_session_t *zn, _z_keyexpr_t key, uint16_t id, ui } ret = key._id; if ((key._suffix != NULL)) { - _z_resource_t *res = zp_malloc(sizeof(_z_resource_t)); + _z_resource_t *res = z_malloc(sizeof(_z_resource_t)); if (res == NULL) { ret = Z_RESOURCE_ID_NONE; } else { @@ -256,7 +256,7 @@ int16_t _z_register_resource(_z_session_t *zn, _z_keyexpr_t key, uint16_t id, ui } #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 return ret; @@ -266,7 +266,7 @@ void _z_unregister_resource(_z_session_t *zn, uint16_t id, uint16_t mapping) { _Bool is_local = mapping == _Z_KEYEXPR_MAPPING_LOCAL; _Z_DEBUG("unregistering: id %d, mapping: %d", id, mapping); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_resource_list_t **parent_mut = is_local ? &zn->_local_resources : &zn->_remote_resources; while (id != 0) { @@ -290,7 +290,7 @@ void _z_unregister_resource(_z_session_t *zn, uint16_t id, uint16_t mapping) { } } #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 } @@ -300,26 +300,26 @@ _Bool _z_unregister_resource_for_peer_filter(const _z_resource_t *candidate, con } void _z_unregister_resources_for_peer(_z_session_t *zn, uint16_t mapping) { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_resource_t ctx = {._id = mapping, ._refcount = 0, ._key = {0}}; zn->_remote_resources = _z_resource_list_drop_filter(zn->_remote_resources, _z_unregister_resource_for_peer_filter, &ctx); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 } void _z_flush_resources(_z_session_t *zn) { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_resource_list_free(&zn->_local_resources); _z_resource_list_free(&zn->_remote_resources); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 } diff --git a/src/session/scout.c b/src/session/scout.c index 0099552d4..b3a8dffb8 100644 --- a/src/session/scout.c +++ b/src/session/scout.c @@ -55,8 +55,8 @@ _z_hello_list_t *__z_scout_loop(const _z_wbuf_t *wbf, const char *locator, unsig // The receiving buffer _z_zbuf_t zbf = _z_zbuf_make(Z_BATCH_UNICAST_SIZE); - zp_clock_t start = zp_clock_now(); - while (zp_clock_elapsed_ms(&start) < period) { + z_clock_t start = z_clock_now(); + while (z_clock_elapsed_ms(&start) < period) { // Eventually read hello messages _z_zbuf_reset(&zbf); @@ -76,7 +76,7 @@ _z_hello_list_t *__z_scout_loop(const _z_wbuf_t *wbf, const char *locator, unsig switch (_Z_MID(s_msg._header)) { case _Z_MID_HELLO: { _Z_INFO("Received _Z_HELLO message"); - _z_hello_t *hello = (_z_hello_t *)zp_malloc(sizeof(_z_hello_t)); + _z_hello_t *hello = (_z_hello_t *)z_malloc(sizeof(_z_hello_t)); if (hello != NULL) { hello->version = s_msg._body._hello._version; hello->whatami = s_msg._body._hello._whatami; diff --git a/src/session/subscription.c b/src/session/subscription.c index 1b9345b0d..280b5d1c9 100644 --- a/src/session/subscription.c +++ b/src/session/subscription.c @@ -99,13 +99,13 @@ _z_subscription_rc_list_t *__unsafe_z_get_subscriptions_by_key(_z_session_t *zn, _z_subscription_rc_t *_z_get_subscription_by_id(_z_session_t *zn, uint8_t is_local, const _z_zint_t id) { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_subscription_rc_t *sub = __unsafe_z_get_subscription_by_id(zn, is_local, id); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 return sub; @@ -113,13 +113,13 @@ _z_subscription_rc_t *_z_get_subscription_by_id(_z_session_t *zn, uint8_t is_loc _z_subscription_rc_list_t *_z_get_subscriptions_by_key(_z_session_t *zn, uint8_t is_local, const _z_keyexpr_t *key) { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_subscription_rc_list_t *subs = __unsafe_z_get_subscriptions_by_key(zn, is_local, *key); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 return subs; @@ -130,12 +130,12 @@ _z_subscription_rc_t *_z_register_subscription(_z_session_t *zn, uint8_t is_loca _z_subscription_rc_t *ret = NULL; #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_subscription_rc_list_t *subs = __unsafe_z_get_subscriptions_by_key(zn, is_local, s->_key); if (subs == NULL) { // A subscription for this name does not yet exists - ret = (_z_subscription_rc_t *)zp_malloc(sizeof(_z_subscription_rc_t)); + ret = (_z_subscription_rc_t *)z_malloc(sizeof(_z_subscription_rc_t)); if (ret != NULL) { *ret = _z_subscription_rc_new_from_val(*s); if (is_local == _Z_RESOURCE_IS_LOCAL) { @@ -147,7 +147,7 @@ _z_subscription_rc_t *_z_register_subscription(_z_session_t *zn, uint8_t is_loca } #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 return ret; @@ -182,7 +182,7 @@ int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, co int8_t ret = _Z_RES_OK; #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _Z_DEBUG("Resolving %d - %s on mapping 0x%x", keyexpr._id, keyexpr._suffix, _z_keyexpr_mapping_id(&keyexpr)); @@ -192,7 +192,7 @@ int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, co _z_subscription_rc_list_t *subs = __unsafe_z_get_subscriptions_by_key(zn, _Z_RESOURCE_IS_LOCAL, key); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 // Build the sample @@ -218,7 +218,7 @@ int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, co _z_subscription_rc_list_free(&subs); } else { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 ret = _Z_ERR_KEYEXPR_UNKNOWN; } @@ -228,7 +228,7 @@ int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, co void _z_unregister_subscription(_z_session_t *zn, uint8_t is_local, _z_subscription_rc_t *sub) { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 if (is_local == _Z_RESOURCE_IS_LOCAL) { @@ -240,20 +240,20 @@ void _z_unregister_subscription(_z_session_t *zn, uint8_t is_local, _z_subscript } #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 } void _z_flush_subscriptions(_z_session_t *zn) { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&zn->_mutex_inner); + z_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_subscription_rc_list_free(&zn->_local_subscriptions); _z_subscription_rc_list_free(&zn->_remote_subscriptions); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&zn->_mutex_inner); + z_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 } #else // Z_FEATURE_SUBSCRIPTION == 0 diff --git a/src/session/utils.c b/src/session/utils.c index 8897411c7..a95643888 100644 --- a/src/session/utils.c +++ b/src/session/utils.c @@ -44,7 +44,7 @@ _Bool _z_timestamp_check(const _z_timestamp_t *stamp) { int8_t _z_session_generate_zid(_z_id_t *bs, uint8_t size) { int8_t ret = _Z_RES_OK; - zp_random_fill((uint8_t *)bs->id, size); + z_random_fill((uint8_t *)bs->id, size); return ret; } @@ -73,7 +73,7 @@ int8_t _z_session_init(_z_session_t *zn, _z_id_t *zid) { #endif #if Z_FEATURE_MULTI_THREAD == 1 - ret = zp_mutex_init(&zn->_mutex_inner); + ret = z_mutex_init(&zn->_mutex_inner); if (ret != _Z_RES_OK) { _z_transport_clear(&zn->_tp); return ret; @@ -117,7 +117,7 @@ void _z_session_clear(_z_session_t *zn) { #endif #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_free(&zn->_mutex_inner); + z_mutex_free(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 } diff --git a/src/system/arduino/esp32/network.cpp b/src/system/arduino/esp32/network.cpp index a865aa5cc..ba4e65206 100644 --- a/src/system/arduino/esp32/network.cpp +++ b/src/system/arduino/esp32/network.cpp @@ -171,7 +171,7 @@ int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_ sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { - zp_time_t tv; + z_time_t tv; tv.tv_sec = tout / (uint32_t)1000; tv.tv_usec = (tout % (uint32_t)1000) * (uint32_t)1000; if ((ret == _Z_RES_OK) && (setsockopt(sock->_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { @@ -246,7 +246,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin struct sockaddr *lsockaddr = NULL; unsigned int addrlen = 0; if (rep._iptcp->ai_family == AF_INET) { - lsockaddr = (struct sockaddr *)zp_malloc(sizeof(struct sockaddr_in)); + lsockaddr = (struct sockaddr *)z_malloc(sizeof(struct sockaddr_in)); if (lsockaddr != NULL) { (void)memset(lsockaddr, 0, sizeof(struct sockaddr_in)); addrlen = sizeof(struct sockaddr_in); @@ -259,7 +259,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin ret = _Z_ERR_GENERIC; } } else if (rep._iptcp->ai_family == AF_INET6) { - lsockaddr = (struct sockaddr *)zp_malloc(sizeof(struct sockaddr_in6)); + lsockaddr = (struct sockaddr *)z_malloc(sizeof(struct sockaddr_in6)); if (lsockaddr != NULL) { (void)memset(lsockaddr, 0, sizeof(struct sockaddr_in6)); addrlen = sizeof(struct sockaddr_in6); @@ -279,7 +279,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin if (addrlen != 0U) { sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { - zp_time_t tv; + z_time_t tv; tv.tv_sec = tout / (uint32_t)1000; tv.tv_usec = (tout % (uint32_t)1000) * (uint32_t)1000; if ((ret == _Z_RES_OK) && (setsockopt(sock->_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { @@ -312,7 +312,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin // Create laddr endpoint if (ret == _Z_RES_OK) { - struct addrinfo *laddr = (struct addrinfo *)zp_malloc(sizeof(struct addrinfo)); + struct addrinfo *laddr = (struct addrinfo *)z_malloc(sizeof(struct addrinfo)); if (laddr != NULL) { laddr->ai_flags = 0; laddr->ai_family = rep._iptcp->ai_family; @@ -336,7 +336,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin } if (ret != _Z_RES_OK) { - zp_free(lsockaddr); + z_free(lsockaddr); } } else { ret = _Z_ERR_GENERIC; @@ -353,7 +353,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo struct sockaddr *lsockaddr = NULL; unsigned int addrlen = 0; if (rep._iptcp->ai_family == AF_INET) { - lsockaddr = (struct sockaddr *)zp_malloc(sizeof(struct sockaddr_in)); + lsockaddr = (struct sockaddr *)z_malloc(sizeof(struct sockaddr_in)); if (lsockaddr != NULL) { (void)memset(lsockaddr, 0, sizeof(struct sockaddr_in)); addrlen = sizeof(struct sockaddr_in); @@ -366,7 +366,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo ret = _Z_ERR_GENERIC; } } else if (rep._iptcp->ai_family == AF_INET6) { - lsockaddr = (struct sockaddr *)zp_malloc(sizeof(struct sockaddr_in6)); + lsockaddr = (struct sockaddr *)z_malloc(sizeof(struct sockaddr_in6)); if (lsockaddr != NULL) { (void)memset(lsockaddr, 0, sizeof(struct sockaddr_in6)); addrlen = sizeof(struct sockaddr_in6); @@ -387,7 +387,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo if (addrlen != 0U) { sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { - zp_time_t tv; + z_time_t tv; tv.tv_sec = tout / (uint32_t)1000; tv.tv_usec = (tout % (uint32_t)1000) * (uint32_t)1000; if ((ret == _Z_RES_OK) && (setsockopt(sock->_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { @@ -438,7 +438,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo ret = _Z_ERR_GENERIC; } - zp_free(lsockaddr); + z_free(lsockaddr); } else { ret = _Z_ERR_GENERIC; } @@ -759,7 +759,7 @@ size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) size_t rb = 0; for (size_t i = 0; i < _Z_SERIAL_MAX_COBS_BUF_SIZE; i++) { while (sock._serial->available() < 1) { - zp_sleep_ms(1); // FIXME: Yield by sleeping. + z_sleep_ms(1); // FIXME: Yield by sleeping. } before_cobs[i] = sock._serial->read(); rb = rb + (size_t)1; @@ -824,7 +824,7 @@ size_t _z_read_exact_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len) { int8_t ret = _Z_RES_OK; - uint8_t *before_cobs = (uint8_t *)zp_malloc(_Z_SERIAL_MFS_SIZE); + uint8_t *before_cobs = (uint8_t *)z_malloc(_Z_SERIAL_MFS_SIZE); size_t i = 0; for (i = 0; i < sizeof(uint16_t); ++i) { before_cobs[i] = (len >> (i * (size_t)8)) & (size_t)0XFF; @@ -839,7 +839,7 @@ size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t i = i + (size_t)1; } - uint8_t *after_cobs = (uint8_t *)zp_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); + uint8_t *after_cobs = (uint8_t *)z_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); ssize_t twb = _z_cobs_encode(before_cobs, i, after_cobs); after_cobs[twb] = 0x00; // Manually add the COBS delimiter ssize_t wb = sock._serial->write(after_cobs, twb + (ssize_t)1); @@ -847,8 +847,8 @@ size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t ret = _Z_ERR_GENERIC; } - zp_free(before_cobs); - zp_free(after_cobs); + z_free(before_cobs); + z_free(after_cobs); size_t sb = len; if (ret != _Z_RES_OK) { diff --git a/src/system/arduino/esp32/system.c b/src/system/arduino/esp32/system.c index 6fc6f9b68..6c82757a5 100644 --- a/src/system/arduino/esp32/system.c +++ b/src/system/arduino/esp32/system.c @@ -20,29 +20,29 @@ #include "zenoh-pico/system/platform.h" /*------------------ Random ------------------*/ -uint8_t zp_random_u8(void) { return zp_random_u32(); } +uint8_t z_random_u8(void) { return z_random_u32(); } -uint16_t zp_random_u16(void) { return zp_random_u32(); } +uint16_t z_random_u16(void) { return z_random_u32(); } -uint32_t zp_random_u32(void) { return esp_random(); } +uint32_t z_random_u32(void) { return esp_random(); } -uint64_t zp_random_u64(void) { +uint64_t z_random_u64(void) { uint64_t ret = 0; - ret |= zp_random_u32(); + ret |= z_random_u32(); ret = ret << 32; - ret |= zp_random_u32(); + ret |= z_random_u32(); return ret; } -void zp_random_fill(void *buf, size_t len) { esp_fill_random(buf, len); } +void z_random_fill(void *buf, size_t len) { esp_fill_random(buf, len); } /*------------------ Memory ------------------*/ -void *zp_malloc(size_t size) { return heap_caps_malloc(size, MALLOC_CAP_8BIT); } +void *z_malloc(size_t size) { return heap_caps_malloc(size, MALLOC_CAP_8BIT); } -void *zp_realloc(void *ptr, size_t size) { return heap_caps_realloc(ptr, size, MALLOC_CAP_8BIT); } +void *z_realloc(void *ptr, size_t size) { return heap_caps_realloc(ptr, size, MALLOC_CAP_8BIT); } -void zp_free(void *ptr) { heap_caps_free(ptr); } +void z_free(void *ptr) { heap_caps_free(ptr); } #if Z_FEATURE_MULTI_THREAD == 1 // This wrapper is only used for ESP32. @@ -56,14 +56,14 @@ typedef struct { void z_task_wrapper(z_task_arg *targ) { targ->_fun(targ->_arg); vTaskDelete(NULL); - zp_free(targ); + z_free(targ); } /*------------------ Task ------------------*/ -int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), void *arg) { +int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { int ret = 0; - z_task_arg *z_arg = (z_task_arg *)zp_malloc(sizeof(z_task_arg)); + z_task_arg *z_arg = (z_task_arg *)z_malloc(sizeof(z_task_arg)); if (z_arg != NULL) { z_arg->_fun = fun; z_arg->_arg = arg; @@ -77,86 +77,86 @@ int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), return ret; } -int8_t zp_task_join(zp_task_t *task) { +int8_t z_task_join(z_task_t *task) { // Note: task/thread join not supported on FreeRTOS API, so we force its deletion instead. return zp_task_cancel(task); } -int8_t zp_task_cancel(zp_task_t *task) { +int8_t zp_task_cancel(z_task_t *task) { vTaskDelete(*task); return 0; } -void zp_task_free(zp_task_t **task) { - zp_task_t *ptr = *task; - zp_free(ptr); +void z_task_free(z_task_t **task) { + z_task_t *ptr = *task; + z_free(ptr); *task = NULL; } /*------------------ Mutex ------------------*/ -int8_t zp_mutex_init(zp_mutex_t *m) { return pthread_mutex_init(m, NULL); } +int8_t z_mutex_init(z_mutex_t *m) { return pthread_mutex_init(m, NULL); } -int8_t zp_mutex_free(zp_mutex_t *m) { return pthread_mutex_destroy(m); } +int8_t z_mutex_free(z_mutex_t *m) { return pthread_mutex_destroy(m); } -int8_t zp_mutex_lock(zp_mutex_t *m) { return pthread_mutex_lock(m); } +int8_t z_mutex_lock(z_mutex_t *m) { return pthread_mutex_lock(m); } -int8_t zp_mutex_trylock(zp_mutex_t *m) { return pthread_mutex_trylock(m); } +int8_t z_mutex_trylock(z_mutex_t *m) { return pthread_mutex_trylock(m); } -int8_t zp_mutex_unlock(zp_mutex_t *m) { return pthread_mutex_unlock(m); } +int8_t z_mutex_unlock(z_mutex_t *m) { return pthread_mutex_unlock(m); } /*------------------ Condvar ------------------*/ -int8_t zp_condvar_init(zp_condvar_t *cv) { return pthread_cond_init(cv, NULL); } +int8_t z_condvar_init(z_condvar_t *cv) { return pthread_cond_init(cv, NULL); } -int8_t zp_condvar_free(zp_condvar_t *cv) { return pthread_cond_destroy(cv); } +int8_t z_condvar_free(z_condvar_t *cv) { return pthread_cond_destroy(cv); } -int8_t zp_condvar_signal(zp_condvar_t *cv) { return pthread_cond_signal(cv); } +int8_t z_condvar_signal(z_condvar_t *cv) { return pthread_cond_signal(cv); } -int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return pthread_cond_wait(cv, m); } +int8_t z_condvar_wait(z_condvar_t *cv, z_mutex_t *m) { return pthread_cond_wait(cv, m); } #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ -int zp_sleep_us(size_t time) { return usleep(time); } +int z_sleep_us(size_t time) { return usleep(time); } -int zp_sleep_ms(size_t time) { - zp_time_t start = zp_time_now(); +int z_sleep_ms(size_t time) { + z_time_t start = z_time_now(); // Most sleep APIs promise to sleep at least whatever you asked them to. // This may compound, so this approach may make sleeps longer than expected. // This extra check tries to minimize the amount of extra time it might sleep. - while (zp_time_elapsed_ms(&start) < time) { - zp_sleep_us(1000); + while (z_time_elapsed_ms(&start) < time) { + z_sleep_us(1000); } return 0; } -int zp_sleep_s(size_t time) { return sleep(time); } +int z_sleep_s(size_t time) { return sleep(time); } /*------------------ Instant ------------------*/ -zp_clock_t zp_clock_now(void) { - zp_clock_t now; +z_clock_t z_clock_now(void) { + z_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); return now; } -unsigned long zp_clock_elapsed_us(zp_clock_t *instant) { - zp_clock_t now; +unsigned long z_clock_elapsed_us(z_clock_t *instant) { + z_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = (1000000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000); return elapsed; } -unsigned long zp_clock_elapsed_ms(zp_clock_t *instant) { - zp_clock_t now; +unsigned long z_clock_elapsed_ms(z_clock_t *instant) { + z_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = (1000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000000); return elapsed; } -unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { - zp_clock_t now; +unsigned long z_clock_elapsed_s(z_clock_t *instant) { + z_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = now.tv_sec - instant->tv_sec; @@ -164,38 +164,38 @@ unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { } /*------------------ Time ------------------*/ -zp_time_t zp_time_now(void) { - zp_time_t now; +z_time_t z_time_now(void) { + z_time_t now; gettimeofday(&now, NULL); return now; } -const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { - zp_time_t tv = zp_time_now(); +const char *z_time_now_as_str(char *const buf, unsigned long buflen) { + z_time_t tv = z_time_now(); struct tm ts; ts = *localtime(&tv.tv_sec); strftime(buf, buflen, "%Y-%m-%dT%H:%M:%SZ", &ts); return buf; } -unsigned long zp_time_elapsed_us(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_us(z_time_t *time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = (1000000 * (now.tv_sec - time->tv_sec) + (now.tv_usec - time->tv_usec)); return elapsed; } -unsigned long zp_time_elapsed_ms(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_ms(z_time_t *time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = (1000 * (now.tv_sec - time->tv_sec) + (now.tv_usec - time->tv_usec) / 1000); return elapsed; } -unsigned long zp_time_elapsed_s(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_s(z_time_t *time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = now.tv_sec - time->tv_sec; diff --git a/src/system/arduino/opencr/system.c b/src/system/arduino/opencr/system.c index 93612bf2e..ed017d200 100644 --- a/src/system/arduino/opencr/system.c +++ b/src/system/arduino/opencr/system.c @@ -20,40 +20,40 @@ #include "zenoh-pico/system/platform.h" /*------------------ Random ------------------*/ -uint8_t zp_random_u8(void) { return random(0xFF); } +uint8_t z_random_u8(void) { return random(0xFF); } -uint16_t zp_random_u16(void) { return random(0xFFFF); } +uint16_t z_random_u16(void) { return random(0xFFFF); } -uint32_t zp_random_u32(void) { return random(0xFFFFFFFF); } +uint32_t z_random_u32(void) { return random(0xFFFFFFFF); } -uint64_t zp_random_u64(void) { +uint64_t z_random_u64(void) { uint64_t ret = 0; - ret |= zp_random_u32(); + ret |= z_random_u32(); ret = ret << 32; - ret |= zp_random_u32(); + ret |= z_random_u32(); return ret; } -void zp_random_fill(void *buf, size_t len) { +void z_random_fill(void *buf, size_t len) { for (size_t i = 0; i < len; i++) { - ((uint8_t *)buf)[i] = zp_random_u8(); + ((uint8_t *)buf)[i] = z_random_u8(); } } /*------------------ Memory ------------------*/ -void *zp_malloc(size_t size) { +void *z_malloc(size_t size) { // return pvPortMalloc(size); // FIXME: Further investigation is required to understand // why pvPortMalloc or pvPortMallocAligned are failing return malloc(size); } -void *zp_realloc(void *ptr, size_t size) { +void *z_realloc(void *ptr, size_t size) { // Not implemented by the platform return NULL; } -void zp_free(void *ptr) { +void z_free(void *ptr) { // vPortFree(ptr); // FIXME: Further investigation is required to understand // why vPortFree or vPortFreeAligned are failing return free(ptr); @@ -63,133 +63,133 @@ void zp_free(void *ptr) { #error "Multi-threading not supported yet on OpenCR port. Disable it by defining Z_FEATURE_MULTI_THREAD=0" /*------------------ Task ------------------*/ -int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), void *arg) { return -1; } +int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { return -1; } -int8_t zp_task_join(zp_task_t *task) { return -1; } +int8_t z_task_join(z_task_t *task) { return -1; } -int8_t zp_task_cancel(zp_task_t *task) { return -1; } +int8_t zp_task_cancel(z_task_t *task) { return -1; } -void zp_task_free(zp_task_t **task) { - zp_task_t *ptr = *task; - zp_free(ptr); +void z_task_free(z_task_t **task) { + z_task_t *ptr = *task; + z_free(ptr); *task = NULL; } /*------------------ Mutex ------------------*/ -int8_t zp_mutex_init(zp_mutex_t *m) { return -1; } +int8_t z_mutex_init(z_mutex_t *m) { return -1; } -int8_t zp_mutex_free(zp_mutex_t *m) { return -1; } +int8_t z_mutex_free(z_mutex_t *m) { return -1; } -int8_t zp_mutex_lock(zp_mutex_t *m) { return -1; } +int8_t z_mutex_lock(z_mutex_t *m) { return -1; } -int8_t zp_mutex_trylock(zp_mutex_t *m) { return -1; } +int8_t z_mutex_trylock(z_mutex_t *m) { return -1; } -int8_t zp_mutex_unlock(zp_mutex_t *m) { return -1; } +int8_t z_mutex_unlock(z_mutex_t *m) { return -1; } /*------------------ Condvar ------------------*/ -int8_t zp_condvar_init(zp_condvar_t *cv) { return -1; } +int8_t z_condvar_init(z_condvar_t *cv) { return -1; } -int8_t zp_condvar_free(zp_condvar_t *cv) { return -1; } +int8_t z_condvar_free(z_condvar_t *cv) { return -1; } -int8_t zp_condvar_signal(zp_condvar_t *cv) { return -1; } +int8_t z_condvar_signal(z_condvar_t *cv) { return -1; } -int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return -1; } +int8_t z_condvar_wait(z_condvar_t *cv, z_mutex_t *m) { return -1; } #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ -int zp_sleep_us(size_t time) { +int z_sleep_us(size_t time) { delay_us(time); return 0; } -int zp_sleep_ms(size_t time) { +int z_sleep_ms(size_t time) { delay_ms(time); return 0; } -int zp_sleep_s(size_t time) { - zp_time_t start = zp_time_now(); +int z_sleep_s(size_t time) { + z_time_t start = z_time_now(); // Most sleep APIs promise to sleep at least whatever you asked them to. // This may compound, so this approach may make sleeps longer than expected. // This extra check tries to minimize the amount of extra time it might sleep. - while (zp_time_elapsed_s(&start) < time) { - zp_sleep_ms(1000); + while (z_time_elapsed_s(&start) < time) { + z_sleep_ms(1000); } return 0; } /*------------------ Instant ------------------*/ -void __zp_clock_gettime(zp_clock_t *ts) { +void __z_clock_gettime(z_clock_t *ts) { uint64_t m = millis(); ts->tv_sec = m / (uint64_t)1000000; ts->tv_nsec = (m % (uint64_t)1000000) * (uint64_t)1000; } -zp_clock_t zp_clock_now(void) { - zp_clock_t now; - __zp_clock_gettime(&now); +z_clock_t z_clock_now(void) { + z_clock_t now; + __z_clock_gettime(&now); return now; } -unsigned long zp_clock_elapsed_us(zp_clock_t *instant) { - zp_clock_t now; - __zp_clock_gettime(&now); +unsigned long z_clock_elapsed_us(z_clock_t *instant) { + z_clock_t now; + __z_clock_gettime(&now); unsigned long elapsed = (1000000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000); return elapsed; } -unsigned long zp_clock_elapsed_ms(zp_clock_t *instant) { - zp_clock_t now; - __zp_clock_gettime(&now); +unsigned long z_clock_elapsed_ms(z_clock_t *instant) { + z_clock_t now; + __z_clock_gettime(&now); unsigned long elapsed = (1000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000000); return elapsed; } -unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { - zp_clock_t now; - __zp_clock_gettime(&now); +unsigned long z_clock_elapsed_s(z_clock_t *instant) { + z_clock_t now; + __z_clock_gettime(&now); unsigned long elapsed = now.tv_sec - instant->tv_sec; return elapsed; } /*------------------ Time ------------------*/ -zp_time_t zp_time_now(void) { - zp_time_t now; +z_time_t z_time_now(void) { + z_time_t now; gettimeofday(&now, NULL); return now; } -const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { - zp_time_t tv = zp_time_now(); +const char *z_time_now_as_str(char *const buf, unsigned long buflen) { + z_time_t tv = z_time_now(); struct tm ts; ts = *localtime(&tv.tv_sec); strftime(buf, buflen, "%Y-%m-%dT%H:%M:%SZ", &ts); return buf; } -unsigned long zp_time_elapsed_us(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_us(z_time_t *time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = (1000000 * (now.tv_sec - time->tv_sec) + (now.tv_usec - time->tv_usec)); return elapsed; } -unsigned long zp_time_elapsed_ms(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_ms(z_time_t *time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = (1000 * (now.tv_sec - time->tv_sec) + (now.tv_usec - time->tv_usec) / 1000); return elapsed; } -unsigned long zp_time_elapsed_s(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_s(z_time_t *time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = now.tv_sec - time->tv_sec; diff --git a/src/system/emscripten/network.c b/src/system/emscripten/network.c index 262217495..95c0d2f09 100644 --- a/src/system/emscripten/network.c +++ b/src/system/emscripten/network.c @@ -83,7 +83,7 @@ int8_t _z_open_ws(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, ui // WARNING: workaround as connect returns before the websocket is // actually open. - zp_sleep_ms(100); + z_sleep_ms(100); if (ret != _Z_RES_OK) { close(sock->_ws._fd); @@ -111,9 +111,9 @@ void _z_close_ws(_z_sys_net_socket_t *sock) { close(sock->_ws._fd); } size_t _z_read_ws(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) { // WARNING: workaroud implementing here the timeout ssize_t rb = 0; - zp_time_t start = zp_time_now(); - while ((zp_time_elapsed_ms(&start) < sock._ws._tout) && (rb <= 0)) { - zp_sleep_ms(WS_LINK_SLEEP); // WARNING: workaround need to give the hand to the emscripten threads + z_time_t start = z_time_now(); + while ((z_time_elapsed_ms(&start) < sock._ws._tout) && (rb <= 0)) { + z_sleep_ms(WS_LINK_SLEEP); // WARNING: workaround need to give the hand to the emscripten threads rb = recv(sock._ws._fd, ptr, len, 0); } // WARNING: workaround as the recv returns -1 not only in case of errors @@ -144,9 +144,9 @@ size_t _z_read_exact_ws(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len size_t _z_send_ws(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len) { // WARNING: workaroud implementing here the timeout ssize_t sb = 0; - zp_time_t start = zp_time_now(); - while ((zp_time_elapsed_ms(&start) < sock._ws._tout) && (sb <= 0)) { - zp_sleep_ms(WS_LINK_SLEEP); // WARNING: workaround need to give the hand to the emscripten threads + z_time_t start = z_time_now(); + while ((z_time_elapsed_ms(&start) < sock._ws._tout) && (sb <= 0)) { + z_sleep_ms(WS_LINK_SLEEP); // WARNING: workaround need to give the hand to the emscripten threads sb = send(sock._ws._fd, ptr, len, 0); } // WARNING: workaround as the recv returns -1 not only in case of errors diff --git a/src/system/emscripten/system.c b/src/system/emscripten/system.c index dc2396575..121724269 100644 --- a/src/system/emscripten/system.c +++ b/src/system/emscripten/system.c @@ -21,112 +21,112 @@ #include "zenoh-pico/system/platform.h" /*------------------ Random ------------------*/ -uint8_t zp_random_u8(void) { return (emscripten_random() * 255.0); } +uint8_t z_random_u8(void) { return (emscripten_random() * 255.0); } -uint16_t zp_random_u16(void) { return (emscripten_random() * 65535.0); } +uint16_t z_random_u16(void) { return (emscripten_random() * 65535.0); } -uint32_t zp_random_u32(void) { return (emscripten_random() * 4294967295.0); } +uint32_t z_random_u32(void) { return (emscripten_random() * 4294967295.0); } -uint64_t zp_random_u64(void) { return (emscripten_random() * 18446744073709551615.0); } +uint64_t z_random_u64(void) { return (emscripten_random() * 18446744073709551615.0); } -void zp_random_fill(void *buf, size_t len) { +void z_random_fill(void *buf, size_t len) { for (size_t i = 0; i < len; i++) { - *((uint8_t *)buf) = zp_random_u8(); + *((uint8_t *)buf) = z_random_u8(); } } /*------------------ Memory ------------------*/ -void *zp_malloc(size_t size) { return malloc(size); } +void *z_malloc(size_t size) { return malloc(size); } -void *zp_realloc(void *ptr, size_t size) { return realloc(ptr, size); } +void *z_realloc(void *ptr, size_t size) { return realloc(ptr, size); } -void zp_free(void *ptr) { free(ptr); } +void z_free(void *ptr) { free(ptr); } #if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ -int8_t zp_task_init(zp_task_t *task, pthread_attr_t *attr, void *(*fun)(void *), void *arg) { +int8_t z_task_init(z_task_t *task, pthread_attr_t *attr, void *(*fun)(void *), void *arg) { return pthread_create(task, attr, fun, arg); } -int8_t zp_task_join(zp_task_t *task) { return pthread_join(*task, NULL); } +int8_t z_task_join(z_task_t *task) { return pthread_join(*task, NULL); } -int8_t zp_task_cancel(zp_task_t *task) { return pthread_cancel(*task); } +int8_t zp_task_cancel(z_task_t *task) { return pthread_cancel(*task); } -void zp_task_free(zp_task_t **task) { - zp_task_t *ptr = *task; - zp_free(ptr); +void z_task_free(z_task_t **task) { + z_task_t *ptr = *task; + z_free(ptr); *task = NULL; } /*------------------ Mutex ------------------*/ -int8_t zp_mutex_init(zp_mutex_t *m) { return pthread_mutex_init(m, 0); } +int8_t z_mutex_init(z_mutex_t *m) { return pthread_mutex_init(m, 0); } -int8_t zp_mutex_free(zp_mutex_t *m) { return pthread_mutex_destroy(m); } +int8_t z_mutex_free(z_mutex_t *m) { return pthread_mutex_destroy(m); } -int8_t zp_mutex_lock(zp_mutex_t *m) { return pthread_mutex_lock(m); } +int8_t z_mutex_lock(z_mutex_t *m) { return pthread_mutex_lock(m); } -int8_t zp_mutex_trylock(zp_mutex_t *m) { return pthread_mutex_trylock(m); } +int8_t z_mutex_trylock(z_mutex_t *m) { return pthread_mutex_trylock(m); } -int8_t zp_mutex_unlock(zp_mutex_t *m) { return pthread_mutex_unlock(m); } +int8_t z_mutex_unlock(z_mutex_t *m) { return pthread_mutex_unlock(m); } /*------------------ Condvar ------------------*/ -int8_t zp_condvar_init(zp_condvar_t *cv) { return pthread_cond_init(cv, 0); } +int8_t z_condvar_init(z_condvar_t *cv) { return pthread_cond_init(cv, 0); } -int8_t zp_condvar_free(zp_condvar_t *cv) { return pthread_cond_destroy(cv); } +int8_t z_condvar_free(z_condvar_t *cv) { return pthread_cond_destroy(cv); } -int8_t zp_condvar_signal(zp_condvar_t *cv) { return pthread_cond_signal(cv); } +int8_t z_condvar_signal(z_condvar_t *cv) { return pthread_cond_signal(cv); } -int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return pthread_cond_wait(cv, m); } +int8_t z_condvar_wait(z_condvar_t *cv, z_mutex_t *m) { return pthread_cond_wait(cv, m); } #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ -int zp_sleep_us(size_t time) { +int z_sleep_us(size_t time) { emscripten_sleep((time / 1000) + (time % 1000 == 0 ? 0 : 1)); return 0; } -int zp_sleep_ms(size_t time) { +int z_sleep_ms(size_t time) { emscripten_sleep(time); return 0; } -int zp_sleep_s(size_t time) { - zp_time_t start = zp_time_now(); +int z_sleep_s(size_t time) { + z_time_t start = z_time_now(); // Most sleep APIs promise to sleep at least whatever you asked them to. // This may compound, so this approach may make sleeps longer than expected. // This extra check tries to minimize the amount of extra time it might sleep. - while (zp_time_elapsed_s(&start) < time) { - zp_sleep_ms(1000); + while (z_time_elapsed_s(&start) < time) { + z_sleep_ms(1000); } return 0; } /*------------------ Instant ------------------*/ -zp_clock_t zp_clock_now(void) { return zp_time_now(); } +z_clock_t z_clock_now(void) { return z_time_now(); } -unsigned long zp_clock_elapsed_us(zp_clock_t *instant) { return zp_clock_elapsed_ms(instant) * 1000; } +unsigned long z_clock_elapsed_us(z_clock_t *instant) { return z_clock_elapsed_ms(instant) * 1000; } -unsigned long zp_clock_elapsed_ms(zp_clock_t *instant) { return zp_time_elapsed_ms(instant); } +unsigned long z_clock_elapsed_ms(z_clock_t *instant) { return z_time_elapsed_ms(instant); } -unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { return zp_time_elapsed_ms(instant) * 1000; } +unsigned long z_clock_elapsed_s(z_clock_t *instant) { return z_time_elapsed_ms(instant) * 1000; } /*------------------ Time ------------------*/ -zp_time_t zp_time_now(void) { return emscripten_get_now(); } +z_time_t z_time_now(void) { return emscripten_get_now(); } -const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { - snprintf(buf, buflen, "%f", zp_time_now()); +const char *z_time_now_as_str(char *const buf, unsigned long buflen) { + snprintf(buf, buflen, "%f", z_time_now()); return buf; } -unsigned long zp_time_elapsed_us(zp_time_t *time) { return zp_time_elapsed_ms(time) * 1000; } +unsigned long z_time_elapsed_us(z_time_t *time) { return z_time_elapsed_ms(time) * 1000; } -unsigned long zp_time_elapsed_ms(zp_time_t *time) { - zp_time_t now = emscripten_get_now(); +unsigned long z_time_elapsed_ms(z_time_t *time) { + z_time_t now = emscripten_get_now(); unsigned long elapsed = now - *time; return elapsed; } -unsigned long zp_time_elapsed_s(zp_time_t *time) { return zp_time_elapsed_ms(time) * 1000; } +unsigned long z_time_elapsed_s(z_time_t *time) { return z_time_elapsed_ms(time) * 1000; } diff --git a/src/system/espidf/network.c b/src/system/espidf/network.c index f11d60658..10bd34aae 100644 --- a/src/system/espidf/network.c +++ b/src/system/espidf/network.c @@ -167,7 +167,7 @@ int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_ sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { - zp_time_t tv; + z_time_t tv; tv.tv_sec = tout / (uint32_t)1000; tv.tv_usec = (tout % (uint32_t)1000) * (uint32_t)1000; if ((ret == _Z_RES_OK) && (setsockopt(sock->_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { @@ -242,7 +242,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin struct sockaddr *lsockaddr = NULL; socklen_t addrlen = 0; if (rep._iptcp->ai_family == AF_INET) { - lsockaddr = (struct sockaddr *)zp_malloc(sizeof(struct sockaddr_in)); + lsockaddr = (struct sockaddr *)z_malloc(sizeof(struct sockaddr_in)); if (lsockaddr != NULL) { (void)memset(lsockaddr, 0, sizeof(struct sockaddr_in)); addrlen = sizeof(struct sockaddr_in); @@ -255,7 +255,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin ret = _Z_ERR_GENERIC; } } else if (rep._iptcp->ai_family == AF_INET6) { - lsockaddr = (struct sockaddr *)zp_malloc(sizeof(struct sockaddr_in6)); + lsockaddr = (struct sockaddr *)z_malloc(sizeof(struct sockaddr_in6)); if (lsockaddr != NULL) { (void)memset(lsockaddr, 0, sizeof(struct sockaddr_in6)); addrlen = sizeof(struct sockaddr_in6); @@ -275,7 +275,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin if (addrlen != 0U) { sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { - zp_time_t tv; + z_time_t tv; tv.tv_sec = tout / (uint32_t)1000; tv.tv_usec = (tout % (uint32_t)1000) * (uint32_t)1000; if ((ret == _Z_RES_OK) && (setsockopt(sock->_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { @@ -308,7 +308,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin // Create laddr endpoint if (ret == _Z_RES_OK) { - struct addrinfo *laddr = (struct addrinfo *)zp_malloc(sizeof(struct addrinfo)); + struct addrinfo *laddr = (struct addrinfo *)z_malloc(sizeof(struct addrinfo)); if (laddr != NULL) { laddr->ai_flags = 0; laddr->ai_family = rep._iptcp->ai_family; @@ -332,7 +332,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin } if (ret != _Z_RES_OK) { - zp_free(lsockaddr); + z_free(lsockaddr); } } else { ret = _Z_ERR_GENERIC; @@ -349,7 +349,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo struct sockaddr *lsockaddr = NULL; unsigned int addrlen = 0; if (rep._iptcp->ai_family == AF_INET) { - lsockaddr = (struct sockaddr *)zp_malloc(sizeof(struct sockaddr_in)); + lsockaddr = (struct sockaddr *)z_malloc(sizeof(struct sockaddr_in)); if (lsockaddr != NULL) { (void)memset(lsockaddr, 0, sizeof(struct sockaddr_in)); addrlen = sizeof(struct sockaddr_in); @@ -362,7 +362,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo ret = _Z_ERR_GENERIC; } } else if (rep._iptcp->ai_family == AF_INET6) { - lsockaddr = (struct sockaddr *)zp_malloc(sizeof(struct sockaddr_in6)); + lsockaddr = (struct sockaddr *)z_malloc(sizeof(struct sockaddr_in6)); if (lsockaddr != NULL) { (void)memset(lsockaddr, 0, sizeof(struct sockaddr_in6)); addrlen = sizeof(struct sockaddr_in6); @@ -383,7 +383,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo if (addrlen != 0U) { sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { - zp_time_t tv; + z_time_t tv; tv.tv_sec = tout / (uint32_t)1000; tv.tv_usec = (tout % (uint32_t)1000) * (uint32_t)1000; if ((ret == _Z_RES_OK) && (setsockopt(sock->_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { @@ -434,7 +434,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo ret = _Z_ERR_GENERIC; } - zp_free(lsockaddr); + z_free(lsockaddr); } else { ret = _Z_ERR_GENERIC; } @@ -627,14 +627,14 @@ void _z_close_serial(_z_sys_net_socket_t *sock) { uart_driver_delete(sock->_seri size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) { int8_t ret = _Z_RES_OK; - uint8_t *before_cobs = (uint8_t *)zp_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); + uint8_t *before_cobs = (uint8_t *)z_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); size_t rb = 0; for (size_t i = 0; i < _Z_SERIAL_MAX_COBS_BUF_SIZE; i++) { size_t len = 0; do { uart_get_buffered_data_len(sock._serial, &len); if (len < 1) { - zp_sleep_ms(10); // FIXME: Yield by sleeping. + z_sleep_ms(10); // FIXME: Yield by sleeping. } else { break; } @@ -646,7 +646,7 @@ size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) } } - uint8_t *after_cobs = (uint8_t *)zp_malloc(_Z_SERIAL_MFS_SIZE); + uint8_t *after_cobs = (uint8_t *)z_malloc(_Z_SERIAL_MFS_SIZE); size_t trb = _z_cobs_decode(before_cobs, rb, after_cobs); size_t i = 0; @@ -673,8 +673,8 @@ size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) ret = _Z_ERR_GENERIC; } - zp_free(before_cobs); - zp_free(after_cobs); + z_free(before_cobs); + z_free(after_cobs); rb = payload_len; if (ret != _Z_RES_OK) { @@ -702,7 +702,7 @@ size_t _z_read_exact_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len) { int8_t ret = _Z_RES_OK; - uint8_t *before_cobs = (uint8_t *)zp_malloc(_Z_SERIAL_MFS_SIZE); + uint8_t *before_cobs = (uint8_t *)z_malloc(_Z_SERIAL_MFS_SIZE); size_t i = 0; for (i = 0; i < sizeof(uint16_t); ++i) { before_cobs[i] = (len >> (i * (size_t)8)) & (size_t)0XFF; @@ -717,7 +717,7 @@ size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t i = i + (size_t)1; } - uint8_t *after_cobs = (uint8_t *)zp_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); + uint8_t *after_cobs = (uint8_t *)z_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); ssize_t twb = _z_cobs_encode(before_cobs, i, after_cobs); after_cobs[twb] = 0x00; // Manually add the COBS delimiter ssize_t wb = uart_write_bytes(sock._serial, after_cobs, twb + (ssize_t)1); @@ -725,8 +725,8 @@ size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t ret = _Z_ERR_GENERIC; } - zp_free(before_cobs); - zp_free(after_cobs); + z_free(before_cobs); + z_free(after_cobs); size_t sb = len; if (ret != _Z_RES_OK) { diff --git a/src/system/espidf/system.c b/src/system/espidf/system.c index 12633ad2b..55eccb52f 100644 --- a/src/system/espidf/system.c +++ b/src/system/espidf/system.c @@ -21,29 +21,29 @@ #include "zenoh-pico/system/platform.h" /*------------------ Random ------------------*/ -uint8_t zp_random_u8(void) { return zp_random_u32(); } +uint8_t z_random_u8(void) { return z_random_u32(); } -uint16_t zp_random_u16(void) { return zp_random_u32(); } +uint16_t z_random_u16(void) { return z_random_u32(); } -uint32_t zp_random_u32(void) { return esp_random(); } +uint32_t z_random_u32(void) { return esp_random(); } -uint64_t zp_random_u64(void) { +uint64_t z_random_u64(void) { uint64_t ret = 0; - ret |= zp_random_u32(); + ret |= z_random_u32(); ret = ret << 32; - ret |= zp_random_u32(); + ret |= z_random_u32(); return ret; } -void zp_random_fill(void *buf, size_t len) { esp_fill_random(buf, len); } +void z_random_fill(void *buf, size_t len) { esp_fill_random(buf, len); } /*------------------ Memory ------------------*/ -void *zp_malloc(size_t size) { return heap_caps_malloc(size, MALLOC_CAP_8BIT); } +void *z_malloc(size_t size) { return heap_caps_malloc(size, MALLOC_CAP_8BIT); } -void *zp_realloc(void *ptr, size_t size) { return heap_caps_realloc(ptr, size, MALLOC_CAP_8BIT); } +void *z_realloc(void *ptr, size_t size) { return heap_caps_realloc(ptr, size, MALLOC_CAP_8BIT); } -void zp_free(void *ptr) { heap_caps_free(ptr); } +void z_free(void *ptr) { heap_caps_free(ptr); } #if Z_FEATURE_MULTI_THREAD == 1 // This wrapper is only used for ESP32. @@ -57,14 +57,14 @@ typedef struct { void z_task_wrapper(z_task_arg *targ) { targ->_fun(targ->_arg); vTaskDelete(NULL); - zp_free(targ); + z_free(targ); } /*------------------ Task ------------------*/ -int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), void *arg) { +int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { int ret = 0; - z_task_arg *z_arg = (z_task_arg *)zp_malloc(sizeof(z_task_arg)); + z_task_arg *z_arg = (z_task_arg *)z_malloc(sizeof(z_task_arg)); if (z_arg != NULL) { z_arg->_fun = fun; z_arg->_arg = arg; @@ -78,86 +78,86 @@ int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), return ret; } -int8_t zp_task_join(zp_task_t *task) { +int8_t z_task_join(z_task_t *task) { // Note: task/thread join not supported on FreeRTOS API, so we force its deletion instead. return zp_task_cancel(task); } -int8_t zp_task_cancel(zp_task_t *task) { +int8_t zp_task_cancel(z_task_t *task) { vTaskDelete(*task); return 0; } -void zp_task_free(zp_task_t **task) { - zp_task_t *ptr = *task; - zp_free(ptr); +void z_task_free(z_task_t **task) { + z_task_t *ptr = *task; + z_free(ptr); *task = NULL; } /*------------------ Mutex ------------------*/ -int8_t zp_mutex_init(zp_mutex_t *m) { return pthread_mutex_init(m, NULL); } +int8_t z_mutex_init(z_mutex_t *m) { return pthread_mutex_init(m, NULL); } -int8_t zp_mutex_free(zp_mutex_t *m) { return pthread_mutex_destroy(m); } +int8_t z_mutex_free(z_mutex_t *m) { return pthread_mutex_destroy(m); } -int8_t zp_mutex_lock(zp_mutex_t *m) { return pthread_mutex_lock(m); } +int8_t z_mutex_lock(z_mutex_t *m) { return pthread_mutex_lock(m); } -int8_t zp_mutex_trylock(zp_mutex_t *m) { return pthread_mutex_trylock(m); } +int8_t z_mutex_trylock(z_mutex_t *m) { return pthread_mutex_trylock(m); } -int8_t zp_mutex_unlock(zp_mutex_t *m) { return pthread_mutex_unlock(m); } +int8_t z_mutex_unlock(z_mutex_t *m) { return pthread_mutex_unlock(m); } /*------------------ Condvar ------------------*/ -int8_t zp_condvar_init(zp_condvar_t *cv) { return pthread_cond_init(cv, NULL); } +int8_t z_condvar_init(z_condvar_t *cv) { return pthread_cond_init(cv, NULL); } -int8_t zp_condvar_free(zp_condvar_t *cv) { return pthread_cond_destroy(cv); } +int8_t z_condvar_free(z_condvar_t *cv) { return pthread_cond_destroy(cv); } -int8_t zp_condvar_signal(zp_condvar_t *cv) { return pthread_cond_signal(cv); } +int8_t z_condvar_signal(z_condvar_t *cv) { return pthread_cond_signal(cv); } -int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return pthread_cond_wait(cv, m); } +int8_t z_condvar_wait(z_condvar_t *cv, z_mutex_t *m) { return pthread_cond_wait(cv, m); } #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ -int zp_sleep_us(size_t time) { return usleep(time); } +int z_sleep_us(size_t time) { return usleep(time); } -int zp_sleep_ms(size_t time) { - zp_time_t start = zp_time_now(); +int z_sleep_ms(size_t time) { + z_time_t start = z_time_now(); // Most sleep APIs promise to sleep at least whatever you asked them to. // This may compound, so this approach may make sleeps longer than expected. // This extra check tries to minimize the amount of extra time it might sleep. - while (zp_time_elapsed_ms(&start) < time) { - zp_sleep_us(1000); + while (z_time_elapsed_ms(&start) < time) { + z_sleep_us(1000); } return 0; } -int zp_sleep_s(size_t time) { return sleep(time); } +int z_sleep_s(size_t time) { return sleep(time); } /*------------------ Instant ------------------*/ -zp_clock_t zp_clock_now(void) { - zp_clock_t now; +z_clock_t z_clock_now(void) { + z_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); return now; } -unsigned long zp_clock_elapsed_us(zp_clock_t *instant) { - zp_clock_t now; +unsigned long z_clock_elapsed_us(z_clock_t *instant) { + z_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = (1000000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000); return elapsed; } -unsigned long zp_clock_elapsed_ms(zp_clock_t *instant) { - zp_clock_t now; +unsigned long z_clock_elapsed_ms(z_clock_t *instant) { + z_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = (1000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000000); return elapsed; } -unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { - zp_clock_t now; +unsigned long z_clock_elapsed_s(z_clock_t *instant) { + z_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = now.tv_sec - instant->tv_sec; @@ -165,38 +165,38 @@ unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { } /*------------------ Time ------------------*/ -zp_time_t zp_time_now(void) { - zp_time_t now; +z_time_t z_time_now(void) { + z_time_t now; gettimeofday(&now, NULL); return now; } -const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { - zp_time_t tv = zp_time_now(); +const char *z_time_now_as_str(char *const buf, unsigned long buflen) { + z_time_t tv = z_time_now(); struct tm ts; ts = *localtime(&tv.tv_sec); strftime(buf, buflen, "%Y-%m-%dT%H:%M:%SZ", &ts); return buf; } -unsigned long zp_time_elapsed_us(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_us(z_time_t *time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = (1000000 * (now.tv_sec - time->tv_sec) + (now.tv_usec - time->tv_usec)); return elapsed; } -unsigned long zp_time_elapsed_ms(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_ms(z_time_t *time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = (1000 * (now.tv_sec - time->tv_sec) + (now.tv_usec - time->tv_usec) / 1000); return elapsed; } -unsigned long zp_time_elapsed_s(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_s(z_time_t *time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = now.tv_sec - time->tv_sec; diff --git a/src/system/flipper/network.c b/src/system/flipper/network.c index 4b291aab0..7067ae27f 100644 --- a/src/system/flipper/network.c +++ b/src/system/flipper/network.c @@ -106,7 +106,7 @@ void _z_close_serial(_z_sys_net_socket_t* sock) { furi_hal_serial_control_release(sock->_serial); // Wait until the serial read timeout ends - zp_sleep_ms(FLIPPER_SERIAL_TIMEOUT_MS * 2); + z_sleep_ms(FLIPPER_SERIAL_TIMEOUT_MS * 2); furi_stream_buffer_free(sock->_rx_stream); @@ -119,13 +119,13 @@ void _z_close_serial(_z_sys_net_socket_t* sock) { size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t* ptr, size_t len) { int8_t ret = _Z_RES_OK; - uint8_t* before_cobs = (uint8_t*)zp_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); + uint8_t* before_cobs = (uint8_t*)z_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); size_t rb = 0; for (size_t i = 0; i < _Z_SERIAL_MAX_COBS_BUF_SIZE; i++) { size_t len = 0; len = furi_stream_buffer_receive(sock._rx_stream, &before_cobs[i], 1, FLIPPER_SERIAL_TIMEOUT_MS); if (!len) { - zp_free(before_cobs); + z_free(before_cobs); return SIZE_MAX; } rb += 1; @@ -135,7 +135,7 @@ size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t* ptr, size_t len) } } - uint8_t* after_cobs = (uint8_t*)zp_malloc(_Z_SERIAL_MFS_SIZE); + uint8_t* after_cobs = (uint8_t*)z_malloc(_Z_SERIAL_MFS_SIZE); size_t trb = _z_cobs_decode(before_cobs, rb, after_cobs); size_t i = 0; @@ -162,8 +162,8 @@ size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t* ptr, size_t len) ret = _Z_ERR_GENERIC; } - zp_free(before_cobs); - zp_free(after_cobs); + z_free(before_cobs); + z_free(after_cobs); rb = payload_len; if (ret != _Z_RES_OK) { @@ -191,7 +191,7 @@ size_t _z_read_exact_serial(const _z_sys_net_socket_t sock, uint8_t* ptr, size_t size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t* ptr, size_t len) { int8_t ret = _Z_RES_OK; - uint8_t* before_cobs = (uint8_t*)zp_malloc(_Z_SERIAL_MFS_SIZE); + uint8_t* before_cobs = (uint8_t*)z_malloc(_Z_SERIAL_MFS_SIZE); size_t i = 0; for (i = 0; i < sizeof(uint16_t); ++i) { before_cobs[i] = (len >> (i * (size_t)8)) & (size_t)0XFF; @@ -206,15 +206,15 @@ size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t* ptr, size_t i++; } - uint8_t* after_cobs = (uint8_t*)zp_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); + uint8_t* after_cobs = (uint8_t*)z_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); ssize_t twb = _z_cobs_encode(before_cobs, i, after_cobs); after_cobs[twb] = 0x00; // Manually add the COBS delimiter furi_hal_serial_tx(sock._serial, after_cobs, twb + (ssize_t)1); furi_hal_serial_tx_wait_complete(sock._serial); - zp_free(before_cobs); - zp_free(after_cobs); + z_free(before_cobs); + z_free(after_cobs); return len; } diff --git a/src/system/flipper/system.c b/src/system/flipper/system.c index fb6170853..e723f6aa5 100644 --- a/src/system/flipper/system.c +++ b/src/system/flipper/system.c @@ -21,36 +21,36 @@ #include "zenoh-pico/utils/result.h" /*------------------ Random ------------------*/ -uint8_t zp_random_u8(void) { return random(); } +uint8_t z_random_u8(void) { return random(); } -uint16_t zp_random_u16(void) { return random(); } +uint16_t z_random_u16(void) { return random(); } -uint32_t zp_random_u32(void) { return random(); } +uint32_t z_random_u32(void) { return random(); } -uint64_t zp_random_u64(void) { +uint64_t z_random_u64(void) { uint64_t ret = 0; - ret |= zp_random_u32(); + ret |= z_random_u32(); ret = ret << 32; - ret |= zp_random_u32(); + ret |= z_random_u32(); return ret; } -void zp_random_fill(void* buf, size_t len) { +void z_random_fill(void* buf, size_t len) { for (size_t i = 0; i < len; i++) { - ((uint8_t*)buf)[i] = zp_random_u8(); + ((uint8_t*)buf)[i] = z_random_u8(); } } /*------------------ Memory ------------------*/ -void* zp_malloc(size_t size) { +void* z_malloc(size_t size) { if (!size) { return NULL; } return malloc(size); } -void* zp_realloc(void* ptr, size_t size) { +void* z_realloc(void* ptr, size_t size) { if (!size) { free(ptr); return NULL; @@ -58,11 +58,11 @@ void* zp_realloc(void* ptr, size_t size) { return realloc(ptr, size); } -void zp_free(void* ptr) { return free(ptr); } +void z_free(void* ptr) { return free(ptr); } /*------------------ Task ------------------*/ -int8_t zp_task_init(zp_task_t* task, zp_task_attr_t* attr, void* (*fun)(void*), void* arg) { +int8_t z_task_init(z_task_t* task, z_task_attr_t* attr, void* (*fun)(void*), void* arg) { if (task == NULL) { return -1; } @@ -80,16 +80,16 @@ int8_t zp_task_init(zp_task_t* task, zp_task_attr_t* attr, void* (*fun)(void*), return _Z_RES_OK; } -int8_t zp_task_join(zp_task_t* task) { +int8_t z_task_join(z_task_t* task) { if (task == NULL) { return -1; } return furi_thread_join(*task); } -int8_t zp_task_cancel(zp_task_t* task) { return -1; } +int8_t zp_task_cancel(z_task_t* task) { return -1; } -void zp_task_free(zp_task_t** task) { +void z_task_free(z_task_t** task) { if (task == NULL || *task == NULL) { return; } @@ -98,7 +98,7 @@ void zp_task_free(zp_task_t** task) { } /*------------------ Mutex ------------------*/ -int8_t zp_mutex_init(zp_mutex_t* m) { +int8_t z_mutex_init(z_mutex_t* m) { if (m == NULL) { return -1; } @@ -106,7 +106,7 @@ int8_t zp_mutex_init(zp_mutex_t* m) { return (*m != 0) ? _Z_RES_OK : _Z_ERR_SYSTEM_TASK_FAILED; } -int8_t zp_mutex_free(zp_mutex_t* m) { +int8_t z_mutex_free(z_mutex_t* m) { if (m == NULL) { return -1; } @@ -118,7 +118,7 @@ int8_t zp_mutex_free(zp_mutex_t* m) { return 0; } -int8_t zp_mutex_lock(zp_mutex_t* m) { +int8_t z_mutex_lock(z_mutex_t* m) { if (m == NULL) { return -1; } @@ -128,9 +128,9 @@ int8_t zp_mutex_lock(zp_mutex_t* m) { return furi_mutex_acquire(*m, FuriWaitForever); } -int8_t zp_mutex_trylock(zp_mutex_t* m) { return -1; } +int8_t z_mutex_trylock(z_mutex_t* m) { return -1; } -int8_t zp_mutex_unlock(zp_mutex_t* m) { +int8_t z_mutex_unlock(z_mutex_t* m) { if (m == NULL) { return -1; } @@ -141,108 +141,108 @@ int8_t zp_mutex_unlock(zp_mutex_t* m) { } /*------------------ Condvar ------------------*/ -int8_t zp_condvar_init(zp_condvar_t* cv) { return -1; } +int8_t z_condvar_init(z_condvar_t* cv) { return -1; } -int8_t zp_condvar_free(zp_condvar_t* cv) { return -1; } +int8_t z_condvar_free(z_condvar_t* cv) { return -1; } -int8_t zp_condvar_signal(zp_condvar_t* cv) { return -1; } +int8_t z_condvar_signal(z_condvar_t* cv) { return -1; } -int8_t zp_condvar_wait(zp_condvar_t* cv, zp_mutex_t* m) { return -1; } +int8_t z_condvar_wait(z_condvar_t* cv, z_mutex_t* m) { return -1; } /*------------------ Sleep ------------------*/ -int zp_sleep_us(size_t time) { +int z_sleep_us(size_t time) { furi_delay_us(time); return 0; } -int zp_sleep_ms(size_t time) { +int z_sleep_ms(size_t time) { furi_delay_ms(time); return 0; } -int zp_sleep_s(size_t time) { - zp_time_t start = zp_time_now(); +int z_sleep_s(size_t time) { + z_time_t start = z_time_now(); // Most sleep APIs promise to sleep at least whatever you asked them to. // This may compound, so this approach may make sleeps longer than expected. // This extra check tries to minimize the amount of extra time it might sleep. - while (zp_time_elapsed_s(&start) < time) { - zp_sleep_ms(1000); + while (z_time_elapsed_s(&start) < time) { + z_sleep_ms(1000); } return 0; } /*------------------ Instant ------------------*/ -void __zp_clock_gettime(zp_clock_t* ts) { +void __z_clock_gettime(z_clock_t* ts) { uint64_t m = millis(); ts->tv_sec = m / (uint64_t)1000000; ts->tv_nsec = (m % (uint64_t)1000000) * (uint64_t)1000; } -zp_clock_t zp_clock_now(void) { - zp_clock_t now; - __zp_clock_gettime(&now); +z_clock_t z_clock_now(void) { + z_clock_t now; + __z_clock_gettime(&now); return now; } -unsigned long zp_clock_elapsed_us(zp_clock_t* instant) { - zp_clock_t now; - __zp_clock_gettime(&now); +unsigned long z_clock_elapsed_us(z_clock_t* instant) { + z_clock_t now; + __z_clock_gettime(&now); unsigned long elapsed = (1000000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000); return elapsed; } -unsigned long zp_clock_elapsed_ms(zp_clock_t* instant) { - zp_clock_t now; - __zp_clock_gettime(&now); +unsigned long z_clock_elapsed_ms(z_clock_t* instant) { + z_clock_t now; + __z_clock_gettime(&now); unsigned long elapsed = (1000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000000); return elapsed; } -unsigned long zp_clock_elapsed_s(zp_clock_t* instant) { - zp_clock_t now; - __zp_clock_gettime(&now); +unsigned long z_clock_elapsed_s(z_clock_t* instant) { + z_clock_t now; + __z_clock_gettime(&now); unsigned long elapsed = now.tv_sec - instant->tv_sec; return elapsed; } /*------------------ Time ------------------*/ -zp_time_t zp_time_now(void) { - zp_time_t now; +z_time_t z_time_now(void) { + z_time_t now; gettimeofday(&now, NULL); return now; } -const char* zp_time_now_as_str(char* const buf, unsigned long buflen) { - zp_time_t tv = zp_time_now(); +const char* z_time_now_as_str(char* const buf, unsigned long buflen) { + z_time_t tv = z_time_now(); struct tm ts; ts = *localtime(&tv.tv_sec); strftime(buf, buflen, "%Y-%m-%dT%H:%M:%SZ", &ts); return buf; } -unsigned long zp_time_elapsed_us(zp_time_t* time) { - zp_time_t now; +unsigned long z_time_elapsed_us(z_time_t* time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = (1000000 * (now.tv_sec - time->tv_sec) + (now.tv_usec - time->tv_usec)); return elapsed; } -unsigned long zp_time_elapsed_ms(zp_time_t* time) { - zp_time_t now; +unsigned long z_time_elapsed_ms(z_time_t* time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = (1000 * (now.tv_sec - time->tv_sec) + (now.tv_usec - time->tv_usec) / 1000); return elapsed; } -unsigned long zp_time_elapsed_s(zp_time_t* time) { - zp_time_t now; +unsigned long z_time_elapsed_s(z_time_t* time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = now.tv_sec - time->tv_sec; diff --git a/src/system/freertos_plus_tcp/system.c b/src/system/freertos_plus_tcp/system.c index a2d17992a..025ccc44a 100644 --- a/src/system/freertos_plus_tcp/system.c +++ b/src/system/freertos_plus_tcp/system.c @@ -23,39 +23,39 @@ #include "zenoh-pico/system/platform.h" /*------------------ Random ------------------*/ -uint8_t zp_random_u8(void) { return zp_random_u32(); } +uint8_t z_random_u8(void) { return z_random_u32(); } -uint16_t zp_random_u16(void) { return zp_random_u32(); } +uint16_t z_random_u16(void) { return z_random_u32(); } -uint32_t zp_random_u32(void) { +uint32_t z_random_u32(void) { uint32_t ret = 0; xApplicationGetRandomNumber(&ret); return ret; } -uint64_t zp_random_u64(void) { +uint64_t z_random_u64(void) { uint64_t ret = 0; - ret |= zp_random_u32(); + ret |= z_random_u32(); ret = ret << 32; - ret |= zp_random_u32(); + ret |= z_random_u32(); return ret; } -void zp_random_fill(void *buf, size_t len) { +void z_random_fill(void *buf, size_t len) { for (size_t i = 0; i < len; i++) { - *((uint8_t *)buf) = zp_random_u8(); + *((uint8_t *)buf) = z_random_u8(); } } /*------------------ Memory ------------------*/ -void *zp_malloc(size_t size) { return pvPortMalloc(size); } +void *z_malloc(size_t size) { return pvPortMalloc(size); } -void *zp_realloc(void *ptr, size_t size) { +void *z_realloc(void *ptr, size_t size) { // realloc not implemented in FreeRTOS return NULL; } -void zp_free(void *ptr) { vPortFree(ptr); } +void z_free(void *ptr) { vPortFree(ptr); } #if Z_FEATURE_MULTI_THREAD == 1 // In FreeRTOS, tasks created using xTaskCreate must end with vTaskDelete. @@ -73,7 +73,7 @@ static void z_task_wrapper(void *arg) { vTaskDelete(NULL); } -static zp_task_attr_t z_default_task_attr = { +static z_task_attr_t z_default_task_attr = { .name = "", .priority = configMAX_PRIORITIES / 2, .stack_depth = 5120, @@ -85,8 +85,8 @@ static zp_task_attr_t z_default_task_attr = { }; /*------------------ Thread ------------------*/ -int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), void *arg) { - z_task_arg *z_arg = (z_task_arg *)zp_malloc(sizeof(z_task_arg)); +int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { + z_task_arg *z_arg = (z_task_arg *)z_malloc(sizeof(z_task_arg)); if (z_arg == NULL) { return -1; } @@ -119,86 +119,86 @@ int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), return 0; } -int8_t zp_task_join(zp_task_t *task) { +int8_t z_task_join(z_task_t *task) { xEventGroupWaitBits(task->join_event, 1, pdFALSE, pdFALSE, portMAX_DELAY); return 0; } -int8_t zp_task_cancel(zp_task_t *task) { +int8_t zp_task_cancel(z_task_t *task) { vTaskDelete(task->handle); return 0; } -void zp_task_free(zp_task_t **task) { - zp_free((*task)->join_event); - zp_free(*task); +void z_task_free(z_task_t **task) { + z_free((*task)->join_event); + z_free(*task); } /*------------------ Mutex ------------------*/ -int8_t zp_mutex_init(zp_mutex_t *m) { +int8_t z_mutex_init(z_mutex_t *m) { *m = xSemaphoreCreateRecursiveMutex(); return *m == NULL ? -1 : 0; } -int8_t zp_mutex_free(zp_mutex_t *m) { - zp_free(*m); +int8_t z_mutex_free(z_mutex_t *m) { + z_free(*m); return 0; } -int8_t zp_mutex_lock(zp_mutex_t *m) { return xSemaphoreTakeRecursive(*m, portMAX_DELAY) == pdTRUE ? 0 : -1; } +int8_t z_mutex_lock(z_mutex_t *m) { return xSemaphoreTakeRecursive(*m, portMAX_DELAY) == pdTRUE ? 0 : -1; } -int8_t zp_mutex_trylock(zp_mutex_t *m) { return xSemaphoreTakeRecursive(*m, 0) == pdTRUE ? 0 : -1; } +int8_t z_mutex_trylock(z_mutex_t *m) { return xSemaphoreTakeRecursive(*m, 0) == pdTRUE ? 0 : -1; } -int8_t zp_mutex_unlock(zp_mutex_t *m) { return xSemaphoreGiveRecursive(*m) == pdTRUE ? 0 : -1; } +int8_t z_mutex_unlock(z_mutex_t *m) { return xSemaphoreGiveRecursive(*m) == pdTRUE ? 0 : -1; } /*------------------ CondVar ------------------*/ // Condition variables not supported in FreeRTOS -int8_t zp_condvar_init(zp_condvar_t *cv) { return -1; } -int8_t zp_condvar_free(zp_condvar_t *cv) { return -1; } -int8_t zp_condvar_signal(zp_condvar_t *cv) { return -1; } -int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return -1; } +int8_t z_condvar_init(z_condvar_t *cv) { return -1; } +int8_t z_condvar_free(z_condvar_t *cv) { return -1; } +int8_t z_condvar_signal(z_condvar_t *cv) { return -1; } +int8_t z_condvar_wait(z_condvar_t *cv, z_mutex_t *m) { return -1; } #endif // Z_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ -int zp_sleep_us(size_t time) { +int z_sleep_us(size_t time) { vTaskDelay(pdMS_TO_TICKS(time / 1000)); return 0; } -int zp_sleep_ms(size_t time) { +int z_sleep_ms(size_t time) { vTaskDelay(pdMS_TO_TICKS(time)); return 0; } -int zp_sleep_s(size_t time) { +int z_sleep_s(size_t time) { vTaskDelay(pdMS_TO_TICKS(time * 1000)); return 0; } /*------------------ Clock ------------------*/ -zp_clock_t zp_clock_now(void) { return zp_time_now(); } +z_clock_t z_clock_now(void) { return z_time_now(); } -unsigned long zp_clock_elapsed_us(zp_clock_t *instant) { return zp_clock_elapsed_ms(instant) * 1000; } +unsigned long z_clock_elapsed_us(z_clock_t *instant) { return z_clock_elapsed_ms(instant) * 1000; } -unsigned long zp_clock_elapsed_ms(zp_clock_t *instant) { return zp_time_elapsed_ms(instant); } +unsigned long z_clock_elapsed_ms(z_clock_t *instant) { return z_time_elapsed_ms(instant); } -unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { return zp_clock_elapsed_ms(instant) / 1000; } +unsigned long z_clock_elapsed_s(z_clock_t *instant) { return z_clock_elapsed_ms(instant) / 1000; } /*------------------ Time ------------------*/ -zp_time_t zp_time_now(void) { return xTaskGetTickCount(); } +z_time_t z_time_now(void) { return xTaskGetTickCount(); } -const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { - snprintf(buf, buflen, "%u", zp_time_now()); +const char *z_time_now_as_str(char *const buf, unsigned long buflen) { + snprintf(buf, buflen, "%u", z_time_now()); return buf; } -unsigned long zp_time_elapsed_us(zp_time_t *time) { return zp_time_elapsed_ms(time) * 1000; } +unsigned long z_time_elapsed_us(z_time_t *time) { return z_time_elapsed_ms(time) * 1000; } -unsigned long zp_time_elapsed_ms(zp_time_t *time) { - zp_time_t now = zp_time_now(); +unsigned long z_time_elapsed_ms(z_time_t *time) { + z_time_t now = z_time_now(); unsigned long elapsed = (now - *time) * portTICK_PERIOD_MS; return elapsed; } -unsigned long zp_time_elapsed_s(zp_time_t *time) { return zp_time_elapsed_ms(time) / 1000; } +unsigned long z_time_elapsed_s(z_time_t *time) { return z_time_elapsed_ms(time) / 1000; } diff --git a/src/system/mbed/system.cpp b/src/system/mbed/system.cpp index b8205a9fb..7b2ffc65f 100644 --- a/src/system/mbed/system.cpp +++ b/src/system/mbed/system.cpp @@ -22,86 +22,86 @@ extern "C" { #include "zenoh-pico/system/platform.h" /*------------------ Random ------------------*/ -uint8_t zp_random_u8(void) { return randLIB_get_8bit(); } +uint8_t z_random_u8(void) { return randLIB_get_8bit(); } -uint16_t zp_random_u16(void) { return randLIB_get_16bit(); } +uint16_t z_random_u16(void) { return randLIB_get_16bit(); } -uint32_t zp_random_u32(void) { return randLIB_get_32bit(); } +uint32_t z_random_u32(void) { return randLIB_get_32bit(); } -uint64_t zp_random_u64(void) { return randLIB_get_64bit(); } +uint64_t z_random_u64(void) { return randLIB_get_64bit(); } -void zp_random_fill(void *buf, size_t len) { randLIB_get_n_bytes_random(buf, len); } +void z_random_fill(void *buf, size_t len) { randLIB_get_n_bytes_random(buf, len); } /*------------------ Memory ------------------*/ -void *zp_malloc(size_t size) { return malloc(size); } +void *z_malloc(size_t size) { return malloc(size); } -void *zp_realloc(void *ptr, size_t size) { return realloc(ptr, size); } +void *z_realloc(void *ptr, size_t size) { return realloc(ptr, size); } -void zp_free(void *ptr) { free(ptr); } +void z_free(void *ptr) { free(ptr); } #if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ -int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), void *arg) { +int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { *task = new Thread(); mbed::Callback c = mbed::Callback(fun, arg); return ((Thread *)*task)->start(c); } -int8_t zp_task_join(zp_task_t *task) { +int8_t z_task_join(z_task_t *task) { int res = ((Thread *)*task)->join(); delete ((Thread *)*task); return res; } -int8_t zp_task_cancel(zp_task_t *task) { +int8_t zp_task_cancel(z_task_t *task) { int res = ((Thread *)*task)->terminate(); delete ((Thread *)*task); return res; } -void zp_task_free(zp_task_t **task) { - zp_task_t *ptr = *task; - zp_free(ptr); +void z_task_free(z_task_t **task) { + z_task_t *ptr = *task; + z_free(ptr); *task = NULL; } /*------------------ Mutex ------------------*/ -int8_t zp_mutex_init(zp_mutex_t *m) { +int8_t z_mutex_init(z_mutex_t *m) { *m = new Mutex(); return 0; } -int8_t zp_mutex_free(zp_mutex_t *m) { +int8_t z_mutex_free(z_mutex_t *m) { delete ((Mutex *)*m); return 0; } -int8_t zp_mutex_lock(zp_mutex_t *m) { +int8_t z_mutex_lock(z_mutex_t *m) { ((Mutex *)*m)->lock(); return 0; } -int8_t zp_mutex_trylock(zp_mutex_t *m) { return (((Mutex *)*m)->trylock() == true) ? 0 : -1; } +int8_t z_mutex_trylock(z_mutex_t *m) { return (((Mutex *)*m)->trylock() == true) ? 0 : -1; } -int8_t zp_mutex_unlock(zp_mutex_t *m) { +int8_t z_mutex_unlock(z_mutex_t *m) { ((Mutex *)*m)->unlock(); return 0; } /*------------------ Condvar ------------------*/ -int8_t zp_condvar_init(zp_condvar_t *cv) { return 0; } +int8_t z_condvar_init(z_condvar_t *cv) { return 0; } -int8_t zp_condvar_free(zp_condvar_t *cv) { +int8_t z_condvar_free(z_condvar_t *cv) { delete ((ConditionVariable *)*cv); return 0; } -int8_t zp_condvar_signal(zp_condvar_t *cv) { +int8_t z_condvar_signal(z_condvar_t *cv) { ((ConditionVariable *)*cv)->notify_all(); return 0; } -int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { +int8_t z_condvar_wait(z_condvar_t *cv, z_mutex_t *m) { *cv = new ConditionVariable(*((Mutex *)*m)); ((ConditionVariable *)*cv)->wait(); return 0; @@ -109,75 +109,75 @@ int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ -int zp_sleep_us(size_t time) { +int z_sleep_us(size_t time) { ThisThread::sleep_for(chrono::milliseconds(((time / 1000) + (time % 1000 == 0 ? 0 : 1)))); return 0; } -int zp_sleep_ms(size_t time) { +int z_sleep_ms(size_t time) { ThisThread::sleep_for(chrono::milliseconds(time)); return 0; } -int zp_sleep_s(size_t time) { +int z_sleep_s(size_t time) { ThisThread::sleep_for(chrono::seconds(time)); return 0; } /*------------------ Instant ------------------*/ -zp_clock_t zp_clock_now(void) { +z_clock_t z_clock_now(void) { // Not supported by default return NULL; } -unsigned long zp_clock_elapsed_us(zp_clock_t *instant) { +unsigned long z_clock_elapsed_us(z_clock_t *instant) { // Not supported by default return -1; } -unsigned long zp_clock_elapsed_ms(zp_clock_t *instant) { +unsigned long z_clock_elapsed_ms(z_clock_t *instant) { // Not supported by default return -1; } -unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { +unsigned long z_clock_elapsed_s(z_clock_t *instant) { // Not supported by default return -1; } /*------------------ Time ------------------*/ -zp_time_t zp_time_now(void) { - zp_time_t now; +z_time_t z_time_now(void) { + z_time_t now; gettimeofday(&now, NULL); return now; } -const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { - zp_time_t tv = zp_time_now(); +const char *z_time_now_as_str(char *const buf, unsigned long buflen) { + z_time_t tv = z_time_now(); struct tm ts; ts = *localtime(&tv.tv_sec); strftime(buf, buflen, "%Y-%m-%dT%H:%M:%SZ", &ts); return buf; } -unsigned long zp_time_elapsed_us(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_us(z_time_t *time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = (1000000 * (now.tv_sec - time->tv_sec) + (now.tv_usec - time->tv_usec)); return elapsed; } -unsigned long zp_time_elapsed_ms(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_ms(z_time_t *time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = (1000 * (now.tv_sec - time->tv_sec) + (now.tv_usec - time->tv_usec) / 1000); return elapsed; } -unsigned long zp_time_elapsed_s(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_s(z_time_t *time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = now.tv_sec - time->tv_sec; diff --git a/src/system/unix/network.c b/src/system/unix/network.c index 5f0cc4b96..d5ec40393 100644 --- a/src/system/unix/network.c +++ b/src/system/unix/network.c @@ -59,7 +59,7 @@ int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, u sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { - zp_time_t tv; + z_time_t tv; tv.tv_sec = tout / (uint32_t)1000; tv.tv_usec = (tout % (uint32_t)1000) * (uint32_t)1000; if ((ret == _Z_RES_OK) && (setsockopt(sock->_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { @@ -186,7 +186,7 @@ int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_ sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { - zp_time_t tv; + z_time_t tv; tv.tv_sec = tout / (uint32_t)1000; tv.tv_usec = (tout % (uint32_t)1000) * (uint32_t)1000; if ((ret == _Z_RES_OK) && (setsockopt(sock->_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { @@ -264,14 +264,14 @@ unsigned int __get_ip_from_iface(const char *iface, int sa_family, struct sockad if (_z_str_eq(tmp->ifa_name, iface) == true) { if (tmp->ifa_addr->sa_family == sa_family) { if (tmp->ifa_addr->sa_family == AF_INET) { - *lsockaddr = (struct sockaddr *)zp_malloc(sizeof(struct sockaddr_in)); + *lsockaddr = (struct sockaddr *)z_malloc(sizeof(struct sockaddr_in)); if (lsockaddr != NULL) { (void)memset(*lsockaddr, 0, sizeof(struct sockaddr_in)); (void)memcpy(*lsockaddr, tmp->ifa_addr, sizeof(struct sockaddr_in)); addrlen = sizeof(struct sockaddr_in); } } else if (tmp->ifa_addr->sa_family == AF_INET6) { - *lsockaddr = (struct sockaddr *)zp_malloc(sizeof(struct sockaddr_in6)); + *lsockaddr = (struct sockaddr *)z_malloc(sizeof(struct sockaddr_in6)); if (lsockaddr != NULL) { (void)memset(*lsockaddr, 0, sizeof(struct sockaddr_in6)); (void)memcpy(*lsockaddr, tmp->ifa_addr, sizeof(struct sockaddr_in6)); @@ -300,7 +300,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin if (addrlen != 0U) { sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { - zp_time_t tv; + z_time_t tv; tv.tv_sec = tout / (uint32_t)1000; tv.tv_usec = (tout % (uint32_t)1000) * (uint32_t)1000; if ((ret == _Z_RES_OK) && (setsockopt(sock->_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { @@ -336,7 +336,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin // Create lep endpoint if (ret == _Z_RES_OK) { - struct addrinfo *laddr = (struct addrinfo *)zp_malloc(sizeof(struct addrinfo)); + struct addrinfo *laddr = (struct addrinfo *)z_malloc(sizeof(struct addrinfo)); if (laddr != NULL) { laddr->ai_flags = 0; laddr->ai_family = rep._iptcp->ai_family; @@ -360,7 +360,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin } if (ret != _Z_RES_OK) { - zp_free(lsockaddr); + z_free(lsockaddr); } } else { ret = _Z_ERR_GENERIC; @@ -378,7 +378,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo if (addrlen != 0U) { sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { - zp_time_t tv; + z_time_t tv; tv.tv_sec = tout / (uint32_t)1000; tv.tv_usec = (tout % (uint32_t)1000) * (uint32_t)1000; if ((ret == _Z_RES_OK) && (setsockopt(sock->_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { @@ -462,7 +462,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo } } } - zp_free(joins); + z_free(joins); } if (ret != _Z_RES_OK) { @@ -472,7 +472,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo ret = _Z_ERR_GENERIC; } - zp_free(lsockaddr); + z_free(lsockaddr); } else { ret = _Z_ERR_GENERIC; } @@ -500,7 +500,7 @@ void _z_close_udp_multicast(_z_sys_net_socket_t *sockrecv, _z_sys_net_socket_t * // Required to be compliant with MISRA 15.7 rule } #if defined(ZENOH_LINUX) - zp_free(lep._iptcp->ai_addr); + z_free(lep._iptcp->ai_addr); #else _ZP_UNUSED(lep); #endif diff --git a/src/system/unix/system.c b/src/system/unix/system.c index 4389a5190..799b60519 100644 --- a/src/system/unix/system.c +++ b/src/system/unix/system.c @@ -28,33 +28,33 @@ #include "zenoh-pico/system/platform.h" /*------------------ Random ------------------*/ -uint8_t zp_random_u8(void) { +uint8_t z_random_u8(void) { uint8_t ret = 0; #if defined(ZENOH_LINUX) while (getrandom(&ret, sizeof(uint8_t), 0) <= 0) { ZP_ASM_NOP; } #elif defined(ZENOH_MACOS) || defined(ZENOH_BSD) - ret = zp_random_u32(); + ret = z_random_u32(); #endif return ret; } -uint16_t zp_random_u16(void) { +uint16_t z_random_u16(void) { uint16_t ret = 0; #if defined(ZENOH_LINUX) while (getrandom(&ret, sizeof(uint16_t), 0) <= 0) { ZP_ASM_NOP; } #elif defined(ZENOH_MACOS) || defined(ZENOH_BSD) - ret = zp_random_u32(); + ret = z_random_u32(); #endif return ret; } -uint32_t zp_random_u32(void) { +uint32_t z_random_u32(void) { uint32_t ret = 0; #if defined(ZENOH_LINUX) while (getrandom(&ret, sizeof(uint32_t), 0) <= 0) { @@ -67,22 +67,22 @@ uint32_t zp_random_u32(void) { return ret; } -uint64_t zp_random_u64(void) { +uint64_t z_random_u64(void) { uint64_t ret = 0; #if defined(ZENOH_LINUX) while (getrandom(&ret, sizeof(uint64_t), 0) <= 0) { ZP_ASM_NOP; } #elif defined(ZENOH_MACOS) || defined(ZENOH_BSD) - ret |= zp_random_u32(); + ret |= z_random_u32(); ret = ret << 32; - ret |= zp_random_u32(); + ret |= z_random_u32(); #endif return ret; } -void zp_random_fill(void *buf, size_t len) { +void z_random_fill(void *buf, size_t len) { #if defined(ZENOH_LINUX) while (getrandom(buf, len, 0) <= 0) { ZP_ASM_NOP; @@ -93,92 +93,92 @@ void zp_random_fill(void *buf, size_t len) { } /*------------------ Memory ------------------*/ -void *zp_malloc(size_t size) { return malloc(size); } +void *z_malloc(size_t size) { return malloc(size); } -void *zp_realloc(void *ptr, size_t size) { return realloc(ptr, size); } +void *z_realloc(void *ptr, size_t size) { return realloc(ptr, size); } -void zp_free(void *ptr) { free(ptr); } +void z_free(void *ptr) { free(ptr); } #if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ -int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), void *arg) { +int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { return pthread_create(task, attr, fun, arg); } -int8_t zp_task_join(zp_task_t *task) { return pthread_join(*task, NULL); } +int8_t z_task_join(z_task_t *task) { return pthread_join(*task, NULL); } -int8_t zp_task_cancel(zp_task_t *task) { return pthread_cancel(*task); } +int8_t zp_task_cancel(z_task_t *task) { return pthread_cancel(*task); } -void zp_task_free(zp_task_t **task) { - zp_task_t *ptr = *task; - zp_free(ptr); +void z_task_free(z_task_t **task) { + z_task_t *ptr = *task; + z_free(ptr); *task = NULL; } /*------------------ Mutex ------------------*/ -int8_t zp_mutex_init(zp_mutex_t *m) { return pthread_mutex_init(m, 0); } +int8_t z_mutex_init(z_mutex_t *m) { return pthread_mutex_init(m, 0); } -int8_t zp_mutex_free(zp_mutex_t *m) { return pthread_mutex_destroy(m); } +int8_t z_mutex_free(z_mutex_t *m) { return pthread_mutex_destroy(m); } -int8_t zp_mutex_lock(zp_mutex_t *m) { return pthread_mutex_lock(m); } +int8_t z_mutex_lock(z_mutex_t *m) { return pthread_mutex_lock(m); } -int8_t zp_mutex_trylock(zp_mutex_t *m) { return pthread_mutex_trylock(m); } +int8_t z_mutex_trylock(z_mutex_t *m) { return pthread_mutex_trylock(m); } -int8_t zp_mutex_unlock(zp_mutex_t *m) { return pthread_mutex_unlock(m); } +int8_t z_mutex_unlock(z_mutex_t *m) { return pthread_mutex_unlock(m); } /*------------------ Condvar ------------------*/ -int8_t zp_condvar_init(zp_condvar_t *cv) { return pthread_cond_init(cv, 0); } +int8_t z_condvar_init(z_condvar_t *cv) { return pthread_cond_init(cv, 0); } -int8_t zp_condvar_free(zp_condvar_t *cv) { return pthread_cond_destroy(cv); } +int8_t z_condvar_free(z_condvar_t *cv) { return pthread_cond_destroy(cv); } -int8_t zp_condvar_signal(zp_condvar_t *cv) { return pthread_cond_signal(cv); } +int8_t z_condvar_signal(z_condvar_t *cv) { return pthread_cond_signal(cv); } -int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return pthread_cond_wait(cv, m); } +int8_t z_condvar_wait(z_condvar_t *cv, z_mutex_t *m) { return pthread_cond_wait(cv, m); } #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ -int zp_sleep_us(size_t time) { return usleep(time); } +int z_sleep_us(size_t time) { return usleep(time); } -int zp_sleep_ms(size_t time) { - zp_time_t start = zp_time_now(); +int z_sleep_ms(size_t time) { + z_time_t start = z_time_now(); // Most sleep APIs promise to sleep at least whatever you asked them to. // This may compound, so this approach may make sleeps longer than expected. // This extra check tries to minimize the amount of extra time it might sleep. - while (zp_time_elapsed_ms(&start) < time) { - zp_sleep_us(1000); + while (z_time_elapsed_ms(&start) < time) { + z_sleep_us(1000); } return 0; } -int zp_sleep_s(size_t time) { return sleep(time); } +int z_sleep_s(size_t time) { return sleep(time); } /*------------------ Instant ------------------*/ -zp_clock_t zp_clock_now(void) { - zp_clock_t now; +z_clock_t z_clock_now(void) { + z_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); return now; } -unsigned long zp_clock_elapsed_us(zp_clock_t *instant) { - zp_clock_t now; +unsigned long z_clock_elapsed_us(z_clock_t *instant) { + z_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = (1000000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000); return elapsed; } -unsigned long zp_clock_elapsed_ms(zp_clock_t *instant) { - zp_clock_t now; +unsigned long z_clock_elapsed_ms(z_clock_t *instant) { + z_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = (1000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000000); return elapsed; } -unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { - zp_clock_t now; +unsigned long z_clock_elapsed_s(z_clock_t *instant) { + z_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = now.tv_sec - instant->tv_sec; @@ -186,38 +186,38 @@ unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { } /*------------------ Time ------------------*/ -zp_time_t zp_time_now(void) { - zp_time_t now; +z_time_t z_time_now(void) { + z_time_t now; gettimeofday(&now, NULL); return now; } -const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { - zp_time_t tv = zp_time_now(); +const char *z_time_now_as_str(char *const buf, unsigned long buflen) { + z_time_t tv = z_time_now(); struct tm ts; ts = *localtime(&tv.tv_sec); strftime(buf, buflen, "%Y-%m-%dT%H:%M:%SZ", &ts); return buf; } -unsigned long zp_time_elapsed_us(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_us(z_time_t *time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = (1000000 * (now.tv_sec - time->tv_sec) + (now.tv_usec - time->tv_usec)); return elapsed; } -unsigned long zp_time_elapsed_ms(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_ms(z_time_t *time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = (1000 * (now.tv_sec - time->tv_sec) + (now.tv_usec - time->tv_usec) / 1000); return elapsed; } -unsigned long zp_time_elapsed_s(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_s(z_time_t *time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = now.tv_sec - time->tv_sec; diff --git a/src/system/windows/network.c b/src/system/windows/network.c index 0d10466d6..833e43a97 100644 --- a/src/system/windows/network.c +++ b/src/system/windows/network.c @@ -64,7 +64,7 @@ int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, u sock->_sock._fd = socket(rep._ep._iptcp->ai_family, rep._ep._iptcp->ai_socktype, rep._ep._iptcp->ai_protocol); if (sock->_sock._fd != INVALID_SOCKET) { - zp_time_t tv; + z_time_t tv; tv.time = tout / (uint32_t)1000; tv.millitm = tout % (uint32_t)1000; if ((ret == _Z_RES_OK) && (setsockopt(sock->_sock._fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { @@ -200,7 +200,7 @@ int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_ sock->_sock._fd = socket(rep._ep._iptcp->ai_family, rep._ep._iptcp->ai_socktype, rep._ep._iptcp->ai_protocol); if (sock->_sock._fd != INVALID_SOCKET) { - zp_time_t tv; + z_time_t tv; tv.time = tout / (uint32_t)1000; tv.millitm = tout % (uint32_t)1000; if ((ret == _Z_RES_OK) && (setsockopt(sock->_sock._fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { @@ -277,20 +277,20 @@ unsigned int __get_ip_from_iface(const char *iface, int sa_family, SOCKADDR **ls unsigned int addrlen = 0U; unsigned long outBufLen = 15000; - IP_ADAPTER_ADDRESSES *l_ifaddr = (IP_ADAPTER_ADDRESSES *)zp_malloc(outBufLen); + IP_ADAPTER_ADDRESSES *l_ifaddr = (IP_ADAPTER_ADDRESSES *)z_malloc(outBufLen); if (l_ifaddr != NULL) { if (GetAdaptersAddresses(sa_family, 0, NULL, l_ifaddr, &outBufLen) != ERROR_BUFFER_OVERFLOW) { for (IP_ADAPTER_ADDRESSES *tmp = l_ifaddr; tmp != NULL; tmp = tmp->Next) { if (_z_str_eq(tmp->AdapterName, iface) == true) { if (sa_family == AF_INET) { - *lsockaddr = (SOCKADDR *)zp_malloc(sizeof(SOCKADDR_IN)); + *lsockaddr = (SOCKADDR *)z_malloc(sizeof(SOCKADDR_IN)); if (lsockaddr != NULL) { (void)memset(*lsockaddr, 0, sizeof(SOCKADDR_IN)); (void)memcpy(*lsockaddr, tmp->FirstUnicastAddress->Address.lpSockaddr, sizeof(SOCKADDR_IN)); addrlen = sizeof(SOCKADDR_IN); } } else if (sa_family == AF_INET6) { - *lsockaddr = (SOCKADDR *)zp_malloc(sizeof(SOCKADDR_IN6)); + *lsockaddr = (SOCKADDR *)z_malloc(sizeof(SOCKADDR_IN6)); if (lsockaddr != NULL) { (void)memset(*lsockaddr, 0, sizeof(SOCKADDR_IN6)); (void)memcpy(*lsockaddr, tmp->FirstUnicastAddress->Address.lpSockaddr, @@ -306,7 +306,7 @@ unsigned int __get_ip_from_iface(const char *iface, int sa_family, SOCKADDR **ls } } - zp_free(l_ifaddr); + z_free(l_ifaddr); l_ifaddr = NULL; } @@ -326,7 +326,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin if (addrlen != 0U) { sock->_sock._fd = socket(rep._ep._iptcp->ai_family, rep._ep._iptcp->ai_socktype, rep._ep._iptcp->ai_protocol); if (sock->_sock._fd != INVALID_SOCKET) { - zp_time_t tv; + z_time_t tv; tv.time = tout / (uint32_t)1000; tv.millitm = tout % (uint32_t)1000; if ((ret == _Z_RES_OK) && @@ -374,7 +374,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin // Create lep endpoint if (ret == _Z_RES_OK) { - ADDRINFOA *laddr = (ADDRINFOA *)zp_malloc(sizeof(ADDRINFOA)); + ADDRINFOA *laddr = (ADDRINFOA *)z_malloc(sizeof(ADDRINFOA)); if (laddr != NULL) { laddr->ai_flags = 0; laddr->ai_family = rep._ep._iptcp->ai_family; @@ -391,7 +391,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin // https://lists.debian.org/debian-glibc/2016/03/msg00241.html // To avoid a fix to break zenoh-pico, we are let it leak for the moment. // #if defined(ZENOH_LINUX) - // zp_free(lsockaddr); + // z_free(lsockaddr); // #endif } else { ret = _Z_ERR_GENERIC; @@ -407,7 +407,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin } if (ret != _Z_RES_OK) { - zp_free(lsockaddr); + z_free(lsockaddr); } } else { ret = _Z_ERR_GENERIC; @@ -430,7 +430,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo if (addrlen != 0U) { sock->_sock._fd = socket(rep._ep._iptcp->ai_family, rep._ep._iptcp->ai_socktype, rep._ep._iptcp->ai_protocol); if (sock->_sock._fd != INVALID_SOCKET) { - zp_time_t tv; + z_time_t tv; tv.time = tout / (uint32_t)1000; tv.millitm = tout % (uint32_t)1000; if ((ret == _Z_RES_OK) && @@ -497,7 +497,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo ret = _Z_ERR_GENERIC; } - zp_free(lsockaddr); + z_free(lsockaddr); } else { ret = _Z_ERR_GENERIC; } diff --git a/src/system/windows/system.c b/src/system/windows/system.c index 217b815ec..3997df9ab 100644 --- a/src/system/windows/system.c +++ b/src/system/windows/system.c @@ -23,44 +23,44 @@ #include "zenoh-pico/utils/result.h" /*------------------ Random ------------------*/ -uint8_t zp_random_u8(void) { +uint8_t z_random_u8(void) { uint8_t ret = 0; - zp_random_fill(&ret, sizeof(ret)); + z_random_fill(&ret, sizeof(ret)); return ret; } -uint16_t zp_random_u16(void) { +uint16_t z_random_u16(void) { uint16_t ret = 0; - zp_random_fill(&ret, sizeof(ret)); + z_random_fill(&ret, sizeof(ret)); return ret; } -uint32_t zp_random_u32(void) { +uint32_t z_random_u32(void) { uint32_t ret = 0; - zp_random_fill(&ret, sizeof(ret)); + z_random_fill(&ret, sizeof(ret)); return ret; } -uint64_t zp_random_u64(void) { +uint64_t z_random_u64(void) { uint64_t ret = 0; - zp_random_fill(&ret, sizeof(ret)); + z_random_fill(&ret, sizeof(ret)); return ret; } -void zp_random_fill(void *buf, size_t len) { RtlGenRandom(buf, (unsigned long)len); } +void z_random_fill(void *buf, size_t len) { RtlGenRandom(buf, (unsigned long)len); } /*------------------ Memory ------------------*/ // #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x)) // #define FREE(x) HeapFree(GetProcessHeap(), 0, (x)) -void *zp_malloc(size_t size) { return malloc(size); } +void *z_malloc(size_t size) { return malloc(size); } -void *zp_realloc(void *ptr, size_t size) { return realloc(ptr, size); } +void *z_realloc(void *ptr, size_t size) { return realloc(ptr, size); } -void zp_free(void *ptr) { free(ptr); } +void z_free(void *ptr) { free(ptr); } #if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ -int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), void *arg) { +int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { (void)(attr); int8_t ret = _Z_RES_OK; *task = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)fun, arg, 0, NULL); @@ -70,45 +70,45 @@ int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), return ret; } -int8_t zp_task_join(zp_task_t *task) { +int8_t z_task_join(z_task_t *task) { int8_t ret = _Z_RES_OK; WaitForSingleObject(*task, INFINITE); return ret; } -int8_t zp_task_cancel(zp_task_t *task) { +int8_t zp_task_cancel(z_task_t *task) { int8_t ret = _Z_RES_OK; TerminateThread(*task, 0); return ret; } -void zp_task_free(zp_task_t **task) { - zp_task_t *ptr = *task; +void z_task_free(z_task_t **task) { + z_task_t *ptr = *task; CloseHandle(*ptr); - zp_free(ptr); + z_free(ptr); *task = NULL; } /*------------------ Mutex ------------------*/ -int8_t zp_mutex_init(zp_mutex_t *m) { +int8_t z_mutex_init(z_mutex_t *m) { int8_t ret = _Z_RES_OK; InitializeSRWLock(m); return ret; } -int8_t zp_mutex_free(zp_mutex_t *m) { +int8_t z_mutex_free(z_mutex_t *m) { (void)(m); int8_t ret = _Z_RES_OK; return ret; } -int8_t zp_mutex_lock(zp_mutex_t *m) { +int8_t z_mutex_lock(z_mutex_t *m) { int8_t ret = _Z_RES_OK; AcquireSRWLockExclusive(m); return ret; } -int8_t zp_mutex_trylock(zp_mutex_t *m) { +int8_t z_mutex_trylock(z_mutex_t *m) { int8_t ret = _Z_RES_OK; if (TryAcquireSRWLockExclusive(m) == 0) { ret = _Z_ERR_GENERIC; @@ -116,32 +116,32 @@ int8_t zp_mutex_trylock(zp_mutex_t *m) { return ret; } -int8_t zp_mutex_unlock(zp_mutex_t *m) { +int8_t z_mutex_unlock(z_mutex_t *m) { int8_t ret = _Z_RES_OK; ReleaseSRWLockExclusive(m); return ret; } /*------------------ Condvar ------------------*/ -int8_t zp_condvar_init(zp_condvar_t *cv) { +int8_t z_condvar_init(z_condvar_t *cv) { int8_t ret = _Z_RES_OK; InitializeConditionVariable(cv); return ret; } -int8_t zp_condvar_free(zp_condvar_t *cv) { +int8_t z_condvar_free(z_condvar_t *cv) { (void)(cv); int8_t ret = _Z_RES_OK; return ret; } -int8_t zp_condvar_signal(zp_condvar_t *cv) { +int8_t z_condvar_signal(z_condvar_t *cv) { int8_t ret = _Z_RES_OK; WakeConditionVariable(cv); return ret; } -int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { +int8_t z_condvar_wait(z_condvar_t *cv, z_mutex_t *m) { int8_t ret = _Z_RES_OK; SleepConditionVariableSRW(cv, m, INFINITE, 0); return ret; @@ -149,9 +149,9 @@ int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ -int zp_sleep_us(size_t time) { return zp_sleep_ms((time / 1000) + (time % 1000 == 0 ? 0 : 1)); } +int z_sleep_us(size_t time) { return z_sleep_ms((time / 1000) + (time % 1000 == 0 ? 0 : 1)); } -int zp_sleep_ms(size_t time) { +int z_sleep_ms(size_t time) { // Guarantees that size_t is split into DWORD segments for Sleep uint8_t ratio = sizeof(size_t) / sizeof(DWORD); DWORD ratio_time = (DWORD)((time / ratio) + (time % ratio == 0 ? 0 : 1)); @@ -161,28 +161,28 @@ int zp_sleep_ms(size_t time) { return 0; } -int zp_sleep_s(size_t time) { - zp_time_t start = zp_time_now(); +int z_sleep_s(size_t time) { + z_time_t start = z_time_now(); // Most sleep APIs promise to sleep at least whatever you asked them to. // This may compound, so this approach may make sleeps longer than expected. // This extra check tries to minimize the amount of extra time it might sleep. - while (zp_time_elapsed_s(&start) < time) { - zp_sleep_ms(1000); + while (z_time_elapsed_s(&start) < time) { + z_sleep_ms(1000); } return 0; } /*------------------ Instant ------------------*/ -zp_clock_t zp_clock_now(void) { - zp_clock_t now; +z_clock_t z_clock_now(void) { + z_clock_t now; QueryPerformanceCounter(&now); return now; } -unsigned long zp_clock_elapsed_us(zp_clock_t *instant) { - zp_clock_t now; +unsigned long z_clock_elapsed_us(z_clock_t *instant) { + z_clock_t now; LARGE_INTEGER frequency; QueryPerformanceCounter(&now); QueryPerformanceFrequency(&frequency); // ticks per second @@ -196,8 +196,8 @@ unsigned long zp_clock_elapsed_us(zp_clock_t *instant) { return (unsigned long)elapsed; } -unsigned long zp_clock_elapsed_ms(zp_clock_t *instant) { - zp_clock_t now; +unsigned long z_clock_elapsed_ms(z_clock_t *instant) { + z_clock_t now; LARGE_INTEGER frequency; QueryPerformanceCounter(&now); QueryPerformanceFrequency(&frequency); // ticks per second @@ -211,8 +211,8 @@ unsigned long zp_clock_elapsed_ms(zp_clock_t *instant) { return (unsigned long)elapsed; } -unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { - zp_clock_t now; +unsigned long z_clock_elapsed_s(z_clock_t *instant) { + z_clock_t now; LARGE_INTEGER frequency; QueryPerformanceCounter(&now); QueryPerformanceFrequency(&frequency); // ticks per second @@ -226,32 +226,32 @@ unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { } /*------------------ Time ------------------*/ -zp_time_t zp_time_now(void) { - zp_time_t now; +z_time_t z_time_now(void) { + z_time_t now; ftime(&now); return now; } -const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { - zp_time_t tv = zp_time_now(); +const char *z_time_now_as_str(char *const buf, unsigned long buflen) { + z_time_t tv = z_time_now(); struct tm ts; ts = *localtime(&tv.time); strftime(buf, buflen, "%Y-%m-%dT%H:%M:%SZ", &ts); return buf; } -unsigned long zp_time_elapsed_us(zp_time_t *time) { return zp_time_elapsed_ms(time) * 1000; } +unsigned long z_time_elapsed_us(z_time_t *time) { return z_time_elapsed_ms(time) * 1000; } -unsigned long zp_time_elapsed_ms(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_ms(z_time_t *time) { + z_time_t now; ftime(&now); unsigned long elapsed = ((unsigned long)(now.time - time->time) * 1000) + (now.millitm - time->millitm); return elapsed; } -unsigned long zp_time_elapsed_s(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_s(z_time_t *time) { + z_time_t now; ftime(&now); unsigned long elapsed = (unsigned long)(now.time - time->time); diff --git a/src/system/zephyr/network.c b/src/system/zephyr/network.c index ae95b1e72..00d3ec1ce 100644 --- a/src/system/zephyr/network.c +++ b/src/system/zephyr/network.c @@ -60,7 +60,7 @@ int8_t _z_open_tcp(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_t rep, u sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { - zp_time_t tv; + z_time_t tv; tv.tv_sec = tout / (uint32_t)1000; tv.tv_usec = (tout % (uint32_t)1000) * (uint32_t)1000; if ((ret == _Z_RES_OK) && (setsockopt(sock->_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { @@ -175,7 +175,7 @@ int8_t _z_open_udp_unicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoint_ sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { - zp_time_t tv; + z_time_t tv; tv.tv_sec = tout / (uint32_t)1000; tv.tv_usec = (tout % (uint32_t)1000) * (uint32_t)1000; if ((ret == _Z_RES_OK) && (setsockopt(sock->_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { @@ -251,7 +251,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin struct sockaddr *lsockaddr = NULL; unsigned int addrlen = 0; if (rep._iptcp->ai_family == AF_INET) { - lsockaddr = (struct sockaddr *)zp_malloc(sizeof(struct sockaddr_in)); + lsockaddr = (struct sockaddr *)z_malloc(sizeof(struct sockaddr_in)); if (lsockaddr != NULL) { (void)memset(lsockaddr, 0, sizeof(struct sockaddr_in)); addrlen = sizeof(struct sockaddr_in); @@ -264,7 +264,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin ret = _Z_ERR_GENERIC; } } else if (rep._iptcp->ai_family == AF_INET6) { - lsockaddr = (struct sockaddr *)zp_malloc(sizeof(struct sockaddr_in6)); + lsockaddr = (struct sockaddr *)z_malloc(sizeof(struct sockaddr_in6)); if (lsockaddr != NULL) { (void)memset(lsockaddr, 0, sizeof(struct sockaddr_in6)); addrlen = sizeof(struct sockaddr_in6); @@ -284,7 +284,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin if (addrlen != 0U) { sock->_fd = socket(rep._iptcp->ai_family, rep._iptcp->ai_socktype, rep._iptcp->ai_protocol); if (sock->_fd != -1) { - zp_time_t tv; + z_time_t tv; tv.tv_sec = tout / (uint32_t)1000; tv.tv_usec = (tout % (uint32_t)1000) * (uint32_t)1000; if ((ret == _Z_RES_OK) && (setsockopt(sock->_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { @@ -303,7 +303,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin // Create lep endpoint if (ret == _Z_RES_OK) { - struct addrinfo *laddr = (struct addrinfo *)zp_malloc(sizeof(struct addrinfo)); + struct addrinfo *laddr = (struct addrinfo *)z_malloc(sizeof(struct addrinfo)); if (laddr != NULL) { laddr->ai_flags = 0; laddr->ai_family = rep._iptcp->ai_family; @@ -327,7 +327,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin } if (ret != _Z_RES_OK) { - zp_free(lsockaddr); + z_free(lsockaddr); } } else { ret = _Z_ERR_GENERIC; @@ -344,7 +344,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo struct sockaddr *lsockaddr = NULL; unsigned int addrlen = 0; if (rep._iptcp->ai_family == AF_INET) { - lsockaddr = (struct sockaddr *)zp_malloc(sizeof(struct sockaddr_in)); + lsockaddr = (struct sockaddr *)z_malloc(sizeof(struct sockaddr_in)); if (lsockaddr != NULL) { (void)memset(lsockaddr, 0, sizeof(struct sockaddr_in)); addrlen = sizeof(struct sockaddr_in); @@ -357,7 +357,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo ret = _Z_ERR_GENERIC; } } else if (rep._iptcp->ai_family == AF_INET6) { - lsockaddr = (struct sockaddr *)zp_malloc(sizeof(struct sockaddr_in6)); + lsockaddr = (struct sockaddr *)z_malloc(sizeof(struct sockaddr_in6)); if (lsockaddr != NULL) { (void)memset(lsockaddr, 0, sizeof(struct sockaddr_in6)); addrlen = sizeof(struct sockaddr_in6); @@ -382,7 +382,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo ret = _Z_ERR_GENERIC; } - zp_time_t tv; + z_time_t tv; tv.tv_sec = tout / (uint32_t)1000; tv.tv_usec = (tout % (uint32_t)1000) * (uint32_t)1000; if ((ret == _Z_RES_OK) && (setsockopt(sock->_fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) < 0)) { @@ -431,7 +431,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo } } - zp_free(lsockaddr); + z_free(lsockaddr); } else { ret = _Z_ERR_GENERIC; } @@ -619,7 +619,7 @@ void _z_close_serial(_z_sys_net_socket_t *sock) {} size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) { int8_t ret = _Z_RES_OK; - uint8_t *before_cobs = (uint8_t *)zp_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); + uint8_t *before_cobs = (uint8_t *)z_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); size_t rb = 0; for (size_t i = 0; i < _Z_SERIAL_MAX_COBS_BUF_SIZE; i++) { int res = -1; @@ -633,7 +633,7 @@ size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) } } - uint8_t *after_cobs = (uint8_t *)zp_malloc(_Z_SERIAL_MFS_SIZE); + uint8_t *after_cobs = (uint8_t *)z_malloc(_Z_SERIAL_MFS_SIZE); size_t trb = _z_cobs_decode(before_cobs, rb, after_cobs); size_t i = 0; @@ -660,8 +660,8 @@ size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) ret = _Z_ERR_GENERIC; } - zp_free(before_cobs); - zp_free(after_cobs); + z_free(before_cobs); + z_free(after_cobs); rb = payload_len; if (ret != _Z_RES_OK) { @@ -692,7 +692,7 @@ size_t _z_read_exact_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t len) { int8_t ret = _Z_RES_OK; - uint8_t *before_cobs = (uint8_t *)zp_malloc(_Z_SERIAL_MFS_SIZE); + uint8_t *before_cobs = (uint8_t *)z_malloc(_Z_SERIAL_MFS_SIZE); size_t i = 0; for (; i < sizeof(uint16_t); ++i) { before_cobs[i] = (len >> (i * (size_t)8)) & (size_t)0XFF; @@ -707,15 +707,15 @@ size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t i = i + (size_t)1; } - uint8_t *after_cobs = (uint8_t *)zp_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); + uint8_t *after_cobs = (uint8_t *)z_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); ssize_t twb = _z_cobs_encode(before_cobs, i, after_cobs); after_cobs[twb] = 0x00; // Manually add the COBS delimiter for (ssize_t i = 0; i < (twb + (ssize_t)1); i++) { uart_poll_out(sock._serial, after_cobs[i]); } - zp_free(before_cobs); - zp_free(after_cobs); + z_free(before_cobs); + z_free(after_cobs); size_t sb = len; if (ret != _Z_RES_OK) { diff --git a/src/system/zephyr/system.c b/src/system/zephyr/system.c index 3d1b0b9d5..ec1dccb6e 100644 --- a/src/system/zephyr/system.c +++ b/src/system/zephyr/system.c @@ -28,32 +28,32 @@ #include "zenoh-pico/system/platform.h" /*------------------ Random ------------------*/ -uint8_t zp_random_u8(void) { return zp_random_u32(); } +uint8_t z_random_u8(void) { return z_random_u32(); } -uint16_t zp_random_u16(void) { return zp_random_u32(); } +uint16_t z_random_u16(void) { return z_random_u32(); } -uint32_t zp_random_u32(void) { return sys_rand32_get(); } +uint32_t z_random_u32(void) { return sys_rand32_get(); } -uint64_t zp_random_u64(void) { +uint64_t z_random_u64(void) { uint64_t ret = 0; - ret |= zp_random_u32(); + ret |= z_random_u32(); ret = ret << 32; - ret |= zp_random_u32(); + ret |= z_random_u32(); return ret; } -void zp_random_fill(void *buf, size_t len) { sys_rand_get(buf, len); } +void z_random_fill(void *buf, size_t len) { sys_rand_get(buf, len); } /*------------------ Memory ------------------*/ -void *zp_malloc(size_t size) { return k_malloc(size); } +void *z_malloc(size_t size) { return k_malloc(size); } -void *zp_realloc(void *ptr, size_t size) { +void *z_realloc(void *ptr, size_t size) { // k_realloc not implemented in Zephyr return NULL; } -void zp_free(void *ptr) { k_free(ptr); } +void z_free(void *ptr) { k_free(ptr); } #if Z_FEATURE_MULTI_THREAD == 1 @@ -71,9 +71,9 @@ K_THREAD_STACK_ARRAY_DEFINE(thread_stack_area, Z_THREADS_NUM, Z_PTHREAD_STACK_SI static int thread_index = 0; /*------------------ Task ------------------*/ -int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), void *arg) { - zp_task_attr_t *lattr = NULL; - zp_task_attr_t tmp; +int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { + z_task_attr_t *lattr = NULL; + z_task_attr_t tmp; if (attr == NULL) { (void)pthread_attr_init(&tmp); (void)pthread_attr_setstack(&tmp, &thread_stack_area[thread_index++], Z_PTHREAD_STACK_SIZE_DEFAULT); @@ -83,39 +83,39 @@ int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), return pthread_create(task, lattr, fun, arg); } -int8_t zp_task_join(zp_task_t *task) { return pthread_join(*task, NULL); } +int8_t z_task_join(z_task_t *task) { return pthread_join(*task, NULL); } -int8_t zp_task_cancel(zp_task_t *task) { return pthread_cancel(*task); } +int8_t zp_task_cancel(z_task_t *task) { return pthread_cancel(*task); } -void zp_task_free(zp_task_t **task) { - zp_task_t *ptr = *task; - zp_free(ptr); +void z_task_free(z_task_t **task) { + z_task_t *ptr = *task; + z_free(ptr); *task = NULL; } /*------------------ Mutex ------------------*/ -int8_t zp_mutex_init(zp_mutex_t *m) { return pthread_mutex_init(m, 0); } +int8_t z_mutex_init(z_mutex_t *m) { return pthread_mutex_init(m, 0); } -int8_t zp_mutex_free(zp_mutex_t *m) { return pthread_mutex_destroy(m); } +int8_t z_mutex_free(z_mutex_t *m) { return pthread_mutex_destroy(m); } -int8_t zp_mutex_lock(zp_mutex_t *m) { return pthread_mutex_lock(m); } +int8_t z_mutex_lock(z_mutex_t *m) { return pthread_mutex_lock(m); } -int8_t zp_mutex_trylock(zp_mutex_t *m) { return pthread_mutex_trylock(m); } +int8_t z_mutex_trylock(z_mutex_t *m) { return pthread_mutex_trylock(m); } -int8_t zp_mutex_unlock(zp_mutex_t *m) { return pthread_mutex_unlock(m); } +int8_t z_mutex_unlock(z_mutex_t *m) { return pthread_mutex_unlock(m); } /*------------------ Condvar ------------------*/ -int8_t zp_condvar_init(zp_condvar_t *cv) { return pthread_cond_init(cv, 0); } +int8_t z_condvar_init(z_condvar_t *cv) { return pthread_cond_init(cv, 0); } -int8_t zp_condvar_free(zp_condvar_t *cv) { return pthread_cond_destroy(cv); } +int8_t z_condvar_free(z_condvar_t *cv) { return pthread_cond_destroy(cv); } -int8_t zp_condvar_signal(zp_condvar_t *cv) { return pthread_cond_signal(cv); } +int8_t z_condvar_signal(z_condvar_t *cv) { return pthread_cond_signal(cv); } -int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return pthread_cond_wait(cv, m); } +int8_t z_condvar_wait(z_condvar_t *cv, z_mutex_t *m) { return pthread_cond_wait(cv, m); } #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ -int zp_sleep_us(size_t time) { +int z_sleep_us(size_t time) { int32_t rem = time; while (rem > 0) { rem = k_usleep(rem); // This function is unlikely to work as expected without kernel tuning. @@ -129,7 +129,7 @@ int zp_sleep_us(size_t time) { return 0; } -int zp_sleep_ms(size_t time) { +int z_sleep_ms(size_t time) { int32_t rem = time; while (rem > 0) { rem = k_msleep(rem); @@ -138,7 +138,7 @@ int zp_sleep_ms(size_t time) { return 0; } -int zp_sleep_s(size_t time) { +int z_sleep_s(size_t time) { int32_t rem = time; while (rem > 0) { rem = k_sleep(K_SECONDS(rem)); @@ -148,30 +148,30 @@ int zp_sleep_s(size_t time) { } /*------------------ Instant ------------------*/ -zp_clock_t zp_clock_now(void) { - zp_clock_t now; +z_clock_t z_clock_now(void) { + z_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); return now; } -unsigned long zp_clock_elapsed_us(zp_clock_t *instant) { - zp_clock_t now; +unsigned long z_clock_elapsed_us(z_clock_t *instant) { + z_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = (1000000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000); return elapsed; } -unsigned long zp_clock_elapsed_ms(zp_clock_t *instant) { - zp_clock_t now; +unsigned long z_clock_elapsed_ms(z_clock_t *instant) { + z_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = (1000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000000); return elapsed; } -unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { - zp_clock_t now; +unsigned long z_clock_elapsed_s(z_clock_t *instant) { + z_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = now.tv_sec - instant->tv_sec; @@ -179,38 +179,38 @@ unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { } /*------------------ Time ------------------*/ -zp_time_t zp_time_now(void) { - zp_time_t now; +z_time_t z_time_now(void) { + z_time_t now; gettimeofday(&now, NULL); return now; } -const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { - zp_time_t tv = zp_time_now(); +const char *z_time_now_as_str(char *const buf, unsigned long buflen) { + z_time_t tv = z_time_now(); struct tm ts; ts = *localtime(&tv.tv_sec); strftime(buf, buflen, "%Y-%m-%dT%H:%M:%SZ", &ts); return buf; } -unsigned long zp_time_elapsed_us(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_us(z_time_t *time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = (1000000 * (now.tv_sec - time->tv_sec) + (now.tv_usec - time->tv_usec)); return elapsed; } -unsigned long zp_time_elapsed_ms(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_ms(z_time_t *time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = (1000 * (now.tv_sec - time->tv_sec) + (now.tv_usec - time->tv_usec) / 1000); return elapsed; } -unsigned long zp_time_elapsed_s(zp_time_t *time) { - zp_time_t now; +unsigned long z_time_elapsed_s(z_time_t *time) { + z_time_t now; gettimeofday(&now, NULL); unsigned long elapsed = now.tv_sec - time->tv_sec; diff --git a/src/transport/multicast/lease.c b/src/transport/multicast/lease.c index 5c7ef21d6..f728535f6 100644 --- a/src/transport/multicast/lease.c +++ b/src/transport/multicast/lease.c @@ -99,7 +99,7 @@ void *_zp_multicast_lease_task(void *ztm_arg) { _z_transport_peer_entry_list_t *it = NULL; while (ztm->_lease_task_running == true) { - zp_mutex_lock(&ztm->_mutex_peer); + z_mutex_lock(&ztm->_mutex_peer); if (next_lease <= 0) { it = ztm->_peers; @@ -158,13 +158,13 @@ void *_zp_multicast_lease_task(void *ztm_arg) { } } - zp_mutex_unlock(&ztm->_mutex_peer); + z_mutex_unlock(&ztm->_mutex_peer); // The keep alive and lease intervals are expressed in milliseconds - zp_sleep_ms(interval); + z_sleep_ms(interval); // Decrement all intervals - zp_mutex_lock(&ztm->_mutex_peer); + z_mutex_lock(&ztm->_mutex_peer); it = ztm->_peers; while (it != NULL) { @@ -176,16 +176,16 @@ void *_zp_multicast_lease_task(void *ztm_arg) { next_keep_alive = next_keep_alive - interval; next_join = next_join - interval; - zp_mutex_unlock(&ztm->_mutex_peer); + z_mutex_unlock(&ztm->_mutex_peer); } return 0; } -int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, zp_task_attr_t *attr, zp_task_t *task) { +int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, z_task_attr_t *attr, z_task_t *task) { // Init memory - (void)memset(task, 0, sizeof(zp_task_t)); + (void)memset(task, 0, sizeof(z_task_t)); // Init task - if (zp_task_init(task, attr, _zp_multicast_lease_task, ztm) != _Z_RES_OK) { + if (z_task_init(task, attr, _zp_multicast_lease_task, ztm) != _Z_RES_OK) { return _Z_ERR_SYSTEM_TASK_FAILED; } // Attach task diff --git a/src/transport/multicast/read.c b/src/transport/multicast/read.c index 830ae11c1..9e293f990 100644 --- a/src/transport/multicast/read.c +++ b/src/transport/multicast/read.c @@ -51,7 +51,7 @@ void *_zp_multicast_read_task(void *ztm_arg) { _z_transport_multicast_t *ztm = (_z_transport_multicast_t *)ztm_arg; // Acquire and keep the lock - zp_mutex_lock(&ztm->_mutex_rx); + z_mutex_lock(&ztm->_mutex_rx); // Prepare the buffer _z_zbuf_reset(&ztm->_zbuf); @@ -124,15 +124,15 @@ void *_zp_multicast_read_task(void *ztm_arg) { // Move the read position of the read buffer _z_zbuf_set_rpos(&ztm->_zbuf, _z_zbuf_get_rpos(&ztm->_zbuf) + to_read); } - zp_mutex_unlock(&ztm->_mutex_rx); + z_mutex_unlock(&ztm->_mutex_rx); return NULL; } -int8_t _zp_multicast_start_read_task(_z_transport_t *zt, zp_task_attr_t *attr, zp_task_t *task) { +int8_t _zp_multicast_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, z_task_t *task) { // Init memory - (void)memset(task, 0, sizeof(zp_task_t)); + (void)memset(task, 0, sizeof(z_task_t)); // Init task - if (zp_task_init(task, attr, _zp_multicast_read_task, &zt->_transport._multicast) != _Z_RES_OK) { + if (z_task_init(task, attr, _zp_multicast_read_task, &zt->_transport._multicast) != _Z_RES_OK) { return _Z_ERR_SYSTEM_TASK_FAILED; } // Attach task diff --git a/src/transport/multicast/rx.c b/src/transport/multicast/rx.c index 9fb789045..048a6563f 100644 --- a/src/transport/multicast/rx.c +++ b/src/transport/multicast/rx.c @@ -35,7 +35,7 @@ static int8_t _z_multicast_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_trans #if Z_FEATURE_MULTI_THREAD == 1 // Acquire the lock - zp_mutex_lock(&ztm->_mutex_rx); + z_mutex_lock(&ztm->_mutex_rx); #endif // Z_FEATURE_MULTI_THREAD == 1 size_t to_read = 0; @@ -82,7 +82,7 @@ static int8_t _z_multicast_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_trans } #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&ztm->_mutex_rx); + z_mutex_unlock(&ztm->_mutex_rx); #endif // Z_FEATURE_MULTI_THREAD == 1 return ret; @@ -125,7 +125,7 @@ int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_t int8_t ret = _Z_RES_OK; #if Z_FEATURE_MULTI_THREAD == 1 // Acquire and keep the lock - zp_mutex_lock(&ztm->_mutex_peer); + z_mutex_lock(&ztm->_mutex_peer); #endif // Z_FEATURE_MULTI_THREAD == 1 // Mark the session that we have received data from this peer @@ -257,7 +257,7 @@ int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_t if (entry == NULL) // New peer { - entry = (_z_transport_peer_entry_t *)zp_malloc(sizeof(_z_transport_peer_entry_t)); + entry = (_z_transport_peer_entry_t *)z_malloc(sizeof(_z_transport_peer_entry_t)); if (entry != NULL) { entry->_sn_res = _z_sn_max(t_msg->_body._join._seq_num_res); @@ -296,7 +296,7 @@ int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_t ztm->_peers = _z_transport_peer_entry_list_insert(ztm->_peers, entry); } else { - zp_free(entry); + z_free(entry); } } else { ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; @@ -341,7 +341,7 @@ int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_t } #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&ztm->_mutex_peer); + z_mutex_unlock(&ztm->_mutex_peer); #endif // Z_FEATURE_MULTI_THREAD == 1 return ret; diff --git a/src/transport/multicast/transport.c b/src/transport/multicast/transport.c index f7c07a61a..6f6057fd8 100644 --- a/src/transport/multicast/transport.c +++ b/src/transport/multicast/transport.c @@ -52,17 +52,17 @@ int8_t _z_multicast_transport_create(_z_transport_t *zt, _z_link_t *zl, } #if Z_FEATURE_MULTI_THREAD == 1 // Initialize the mutexes - ret = zp_mutex_init(&ztm->_mutex_tx); + ret = z_mutex_init(&ztm->_mutex_tx); if (ret == _Z_RES_OK) { - ret = zp_mutex_init(&ztm->_mutex_rx); + ret = z_mutex_init(&ztm->_mutex_rx); if (ret == _Z_RES_OK) { - ret = zp_mutex_init(&ztm->_mutex_peer); + ret = z_mutex_init(&ztm->_mutex_peer); if (ret != _Z_RES_OK) { - zp_mutex_free(&ztm->_mutex_tx); - zp_mutex_free(&ztm->_mutex_rx); + z_mutex_free(&ztm->_mutex_tx); + z_mutex_free(&ztm->_mutex_rx); } } else { - zp_mutex_free(&ztm->_mutex_tx); + z_mutex_free(&ztm->_mutex_tx); } } #endif // Z_FEATURE_MULTI_THREAD == 1 @@ -79,9 +79,9 @@ int8_t _z_multicast_transport_create(_z_transport_t *zt, _z_link_t *zl, _Z_ERROR("Not enough memory to allocate transport tx rx buffers!"); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_free(&ztm->_mutex_tx); - zp_mutex_free(&ztm->_mutex_rx); - zp_mutex_free(&ztm->_mutex_peer); + z_mutex_free(&ztm->_mutex_tx); + z_mutex_free(&ztm->_mutex_rx); + z_mutex_free(&ztm->_mutex_peer); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_wbuf_clear(&ztm->_wbuf); @@ -124,7 +124,7 @@ int8_t _z_multicast_open_peer(_z_transport_multicast_establish_param_t *param, c int8_t ret = _Z_RES_OK; _z_zint_t initial_sn_tx = 0; - zp_random_fill(&initial_sn_tx, sizeof(initial_sn_tx)); + z_random_fill(&initial_sn_tx, sizeof(initial_sn_tx)); initial_sn_tx = initial_sn_tx & !_z_sn_modulo_mask(Z_SN_RESOLUTION); _z_conduit_sn_list_t next_sn; @@ -184,17 +184,17 @@ void _z_multicast_transport_clear(_z_transport_t *zt) { #if Z_FEATURE_MULTI_THREAD == 1 // Clean up tasks if (ztm->_read_task != NULL) { - zp_task_join(ztm->_read_task); - zp_task_free(&ztm->_read_task); + z_task_join(ztm->_read_task); + z_task_free(&ztm->_read_task); } if (ztm->_lease_task != NULL) { - zp_task_join(ztm->_lease_task); - zp_task_free(&ztm->_lease_task); + z_task_join(ztm->_lease_task); + z_task_free(&ztm->_lease_task); } // Clean up the mutexes - zp_mutex_free(&ztm->_mutex_tx); - zp_mutex_free(&ztm->_mutex_rx); - zp_mutex_free(&ztm->_mutex_peer); + z_mutex_free(&ztm->_mutex_tx); + z_mutex_free(&ztm->_mutex_rx); + z_mutex_free(&ztm->_mutex_peer); #endif // Z_FEATURE_MULTI_THREAD == 1 // Clean up the buffers diff --git a/src/transport/multicast/tx.c b/src/transport/multicast/tx.c index 18aefa3e4..5de35fe4f 100644 --- a/src/transport/multicast/tx.c +++ b/src/transport/multicast/tx.c @@ -46,7 +46,7 @@ int8_t _z_multicast_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport #if Z_FEATURE_MULTI_THREAD == 1 // Acquire the lock - zp_mutex_lock(&ztm->_mutex_tx); + z_mutex_lock(&ztm->_mutex_tx); #endif // Z_FEATURE_MULTI_THREAD == 1 // Prepare the buffer eventually reserving space for the message length @@ -65,7 +65,7 @@ int8_t _z_multicast_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport } #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&ztm->_mutex_tx); + z_mutex_unlock(&ztm->_mutex_tx); #endif // Z_FEATURE_MULTI_THREAD == 1 return ret; @@ -82,11 +82,11 @@ int8_t _z_multicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_m _Bool drop = false; if (cong_ctrl == Z_CONGESTION_CONTROL_BLOCK) { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&ztm->_mutex_tx); + z_mutex_lock(&ztm->_mutex_tx); #endif // Z_FEATURE_MULTI_THREAD == 1 } else { #if Z_FEATURE_MULTI_THREAD == 1 - int8_t locked = zp_mutex_trylock(&ztm->_mutex_tx); + int8_t locked = z_mutex_trylock(&ztm->_mutex_tx); if (locked != (int8_t)0) { _Z_INFO("Dropping zenoh message because of congestion control"); // We failed to acquire the lock, drop the message @@ -153,7 +153,7 @@ int8_t _z_multicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_m } #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&ztm->_mutex_tx); + z_mutex_unlock(&ztm->_mutex_tx); #endif // Z_FEATURE_MULTI_THREAD == 1 } diff --git a/src/transport/raweth/link.c b/src/transport/raweth/link.c index 8eb42abc9..a616b4f8e 100644 --- a/src/transport/raweth/link.c +++ b/src/transport/raweth/link.c @@ -73,7 +73,7 @@ static _Bool _z_valid_address_raweth(const char *address) { static uint8_t *_z_parse_address_raweth(const char *address) { size_t len = strlen(address); // Allocate data - uint8_t *ret = (uint8_t *)zp_malloc(_ZP_MAC_ADDR_LENGTH); + uint8_t *ret = (uint8_t *)z_malloc(_ZP_MAC_ADDR_LENGTH); if (ret == NULL) { return ret; } @@ -93,7 +93,7 @@ static int8_t _z_f_link_open_raweth(_z_link_t *self) { if (_z_valid_address_raweth(self->_endpoint._locator._address)) { uint8_t *addr = _z_parse_address_raweth(self->_endpoint._locator._address); memcpy(&self->_socket._raweth._smac, addr, _ZP_MAC_ADDR_LENGTH); - zp_free(addr); + z_free(addr); } else { memcpy(&self->_socket._raweth._smac, _ZP_RAWETH_CFG_SMAC, _ZP_MAC_ADDR_LENGTH); } diff --git a/src/transport/raweth/read.c b/src/transport/raweth/read.c index 431af3c4f..778a3b966 100644 --- a/src/transport/raweth/read.c +++ b/src/transport/raweth/read.c @@ -83,11 +83,11 @@ void *_zp_raweth_read_task(void *ztm_arg) { return NULL; } -int8_t _zp_raweth_start_read_task(_z_transport_t *zt, zp_task_attr_t *attr, zp_task_t *task) { +int8_t _zp_raweth_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, z_task_t *task) { // Init memory - (void)memset(task, 0, sizeof(zp_task_t)); + (void)memset(task, 0, sizeof(z_task_t)); // Init task - if (zp_task_init(task, attr, _zp_raweth_read_task, &zt->_transport._raweth) != _Z_RES_OK) { + if (z_task_init(task, attr, _zp_raweth_read_task, &zt->_transport._raweth) != _Z_RES_OK) { return _Z_ERR_SYSTEM_TASK_FAILED; } // Attach task diff --git a/src/transport/raweth/rx.c b/src/transport/raweth/rx.c index 162c66c28..93dd68b11 100644 --- a/src/transport/raweth/rx.c +++ b/src/transport/raweth/rx.c @@ -78,7 +78,7 @@ int8_t _z_raweth_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_transport_messa #if Z_FEATURE_MULTI_THREAD == 1 // Acquire the lock - zp_mutex_lock(&ztm->_mutex_rx); + z_mutex_lock(&ztm->_mutex_rx); #endif // Z_FEATURE_MULTI_THREAD == 1 // Prepare the buffer @@ -106,7 +106,7 @@ int8_t _z_raweth_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_transport_messa } #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&ztm->_mutex_rx); + z_mutex_unlock(&ztm->_mutex_rx); #endif // Z_FEATURE_MULTI_THREAD == 1 return ret; diff --git a/src/transport/raweth/tx.c b/src/transport/raweth/tx.c index ac360cc9e..bdfd138f0 100644 --- a/src/transport/raweth/tx.c +++ b/src/transport/raweth/tx.c @@ -32,7 +32,7 @@ #if Z_FEATURE_RAWETH_TRANSPORT == 1 #if Z_FEATURE_MULTI_THREAD == 1 -static void _zp_raweth_unlock_tx_mutex(_z_transport_multicast_t *ztm) { zp_mutex_unlock(&ztm->_mutex_tx); } +static void _zp_raweth_unlock_tx_mutex(_z_transport_multicast_t *ztm) { z_mutex_unlock(&ztm->_mutex_tx); } #else static void _zp_raweth_unlock_tx_mutex(_z_transport_multicast_t *ztm) { _ZP_UNUSED(ztm); } #endif @@ -195,7 +195,7 @@ int8_t _z_raweth_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport_me _Z_DEBUG(">> send session message"); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&ztm->_mutex_tx); + z_mutex_lock(&ztm->_mutex_tx); #endif // Reset wbuf _z_wbuf_reset(&ztm->_wbuf); @@ -213,7 +213,7 @@ int8_t _z_raweth_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport_me ztm->_transmitted = true; #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&ztm->_mutex_tx); + z_mutex_unlock(&ztm->_mutex_tx); #endif return ret; @@ -228,9 +228,9 @@ int8_t _z_raweth_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg, // Acquire the lock and drop the message if needed #if Z_FEATURE_MULTI_THREAD == 1 if (cong_ctrl == Z_CONGESTION_CONTROL_BLOCK) { - zp_mutex_lock(&ztm->_mutex_tx); + z_mutex_lock(&ztm->_mutex_tx); } else { - if (zp_mutex_trylock(&ztm->_mutex_tx) != (int8_t)0) { + if (z_mutex_trylock(&ztm->_mutex_tx) != (int8_t)0) { _Z_INFO("Dropping zenoh message because of congestion control"); // We failed to acquire the lock, drop the message return ret; @@ -313,7 +313,7 @@ int8_t _z_raweth_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg, #endif } #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&ztm->_mutex_tx); + z_mutex_unlock(&ztm->_mutex_tx); #endif // Z_FEATURE_MULTI_THREAD == 1 return ret; } diff --git a/src/transport/transport.c b/src/transport/transport.c index 3ced940ca..a53b7e364 100644 --- a/src/transport/transport.c +++ b/src/transport/transport.c @@ -73,7 +73,7 @@ void _z_transport_free(_z_transport_t **zt) { } // Clear and free transport _z_transport_clear(ptr); - zp_free(ptr); + z_free(ptr); *zt = NULL; } diff --git a/src/transport/unicast/lease.c b/src/transport/unicast/lease.c index a8d929f63..03d0ffd1b 100644 --- a/src/transport/unicast/lease.c +++ b/src/transport/unicast/lease.c @@ -87,7 +87,7 @@ void *_zp_unicast_lease_task(void *ztu_arg) { } // The keep alive and lease intervals are expressed in milliseconds - zp_sleep_ms(interval); + z_sleep_ms(interval); next_lease = next_lease - interval; next_keep_alive = next_keep_alive - interval; @@ -95,11 +95,11 @@ void *_zp_unicast_lease_task(void *ztu_arg) { return 0; } -int8_t _zp_unicast_start_lease_task(_z_transport_t *zt, zp_task_attr_t *attr, zp_task_t *task) { +int8_t _zp_unicast_start_lease_task(_z_transport_t *zt, z_task_attr_t *attr, z_task_t *task) { // Init memory - (void)memset(task, 0, sizeof(zp_task_t)); + (void)memset(task, 0, sizeof(z_task_t)); // Init task - if (zp_task_init(task, attr, _zp_unicast_lease_task, &zt->_transport._unicast) != _Z_RES_OK) { + if (z_task_init(task, attr, _zp_unicast_lease_task, &zt->_transport._unicast) != _Z_RES_OK) { return _Z_ERR_SYSTEM_TASK_FAILED; } // Attach task diff --git a/src/transport/unicast/read.c b/src/transport/unicast/read.c index 3b02ff597..80e35180c 100644 --- a/src/transport/unicast/read.c +++ b/src/transport/unicast/read.c @@ -49,7 +49,7 @@ void *_zp_unicast_read_task(void *ztu_arg) { _z_transport_unicast_t *ztu = (_z_transport_unicast_t *)ztu_arg; // Acquire and keep the lock - zp_mutex_lock(&ztu->_mutex_rx); + z_mutex_lock(&ztu->_mutex_rx); // Prepare the buffer _z_zbuf_reset(&ztu->_zbuf); @@ -117,15 +117,15 @@ void *_zp_unicast_read_task(void *ztu_arg) { // Move the read position of the read buffer _z_zbuf_set_rpos(&ztu->_zbuf, _z_zbuf_get_rpos(&ztu->_zbuf) + to_read); } - zp_mutex_unlock(&ztu->_mutex_rx); + z_mutex_unlock(&ztu->_mutex_rx); return NULL; } -int8_t _zp_unicast_start_read_task(_z_transport_t *zt, zp_task_attr_t *attr, zp_task_t *task) { +int8_t _zp_unicast_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, z_task_t *task) { // Init memory - (void)memset(task, 0, sizeof(zp_task_t)); + (void)memset(task, 0, sizeof(z_task_t)); // Init task - if (zp_task_init(task, attr, _zp_unicast_read_task, &zt->_transport._unicast) != _Z_RES_OK) { + if (z_task_init(task, attr, _zp_unicast_read_task, &zt->_transport._unicast) != _Z_RES_OK) { return _Z_ERR_SYSTEM_TASK_FAILED; } // Attach task diff --git a/src/transport/unicast/rx.c b/src/transport/unicast/rx.c index 3ed08a0a6..6278ca735 100644 --- a/src/transport/unicast/rx.c +++ b/src/transport/unicast/rx.c @@ -32,7 +32,7 @@ int8_t _z_unicast_recv_t_msg_na(_z_transport_unicast_t *ztu, _z_transport_messag int8_t ret = _Z_RES_OK; #if Z_FEATURE_MULTI_THREAD == 1 // Acquire the lock - zp_mutex_lock(&ztu->_mutex_rx); + z_mutex_lock(&ztu->_mutex_rx); #endif // Z_FEATURE_MULTI_THREAD == 1 size_t to_read = 0; @@ -85,7 +85,7 @@ int8_t _z_unicast_recv_t_msg_na(_z_transport_unicast_t *ztu, _z_transport_messag } #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&ztu->_mutex_rx); + z_mutex_unlock(&ztu->_mutex_rx); #endif // Z_FEATURE_MULTI_THREAD == 1 return ret; diff --git a/src/transport/unicast/transport.c b/src/transport/unicast/transport.c index b919e3339..2c321f7a7 100644 --- a/src/transport/unicast/transport.c +++ b/src/transport/unicast/transport.c @@ -38,11 +38,11 @@ int8_t _z_unicast_transport_create(_z_transport_t *zt, _z_link_t *zl, _z_transpo #if Z_FEATURE_MULTI_THREAD == 1 // Initialize the mutexes - ret = zp_mutex_init(&zt->_transport._unicast._mutex_tx); + ret = z_mutex_init(&zt->_transport._unicast._mutex_tx); if (ret == _Z_RES_OK) { - ret = zp_mutex_init(&zt->_transport._unicast._mutex_rx); + ret = z_mutex_init(&zt->_transport._unicast._mutex_rx); if (ret != _Z_RES_OK) { - zp_mutex_free(&zt->_transport._unicast._mutex_tx); + z_mutex_free(&zt->_transport._unicast._mutex_tx); } } #endif // Z_FEATURE_MULTI_THREAD == 1 @@ -86,8 +86,8 @@ int8_t _z_unicast_transport_create(_z_transport_t *zt, _z_link_t *zl, _z_transpo _Z_ERROR("Not enough memory to allocate transport tx rx buffers!"); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_free(&zt->_transport._unicast._mutex_tx); - zp_mutex_free(&zt->_transport._unicast._mutex_rx); + z_mutex_free(&zt->_transport._unicast._mutex_tx); + z_mutex_free(&zt->_transport._unicast._mutex_rx); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_wbuf_clear(&zt->_transport._unicast._wbuf); @@ -115,8 +115,8 @@ int8_t _z_unicast_transport_create(_z_transport_t *zt, _z_link_t *zl, _z_transpo _z_wbuf_clear(&zt->_transport._unicast._dbuf_best_effort); #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_free(&zt->_transport._unicast._mutex_tx); - zp_mutex_free(&zt->_transport._unicast._mutex_rx); + z_mutex_free(&zt->_transport._unicast._mutex_tx); + z_mutex_free(&zt->_transport._unicast._mutex_rx); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_wbuf_clear(&zt->_transport._unicast._wbuf); @@ -212,7 +212,7 @@ int8_t _z_unicast_open_client(_z_transport_unicast_establish_param_t *param, con param->_req_id_res = 0x08 << param->_req_id_res; // The initial SN at TX side - zp_random_fill(¶m->_initial_sn_tx, sizeof(param->_initial_sn_tx)); + z_random_fill(¶m->_initial_sn_tx, sizeof(param->_initial_sn_tx)); param->_initial_sn_tx = param->_initial_sn_tx & !_z_sn_modulo_mask(param->_seq_num_res); // Initialize the Local and Remote Peer IDs @@ -287,17 +287,17 @@ void _z_unicast_transport_clear(_z_transport_t *zt) { #if Z_FEATURE_MULTI_THREAD == 1 // Clean up tasks if (ztu->_read_task != NULL) { - zp_task_join(ztu->_read_task); - zp_task_free(&ztu->_read_task); + z_task_join(ztu->_read_task); + z_task_free(&ztu->_read_task); } if (ztu->_lease_task != NULL) { - zp_task_join(ztu->_lease_task); - zp_task_free(&ztu->_lease_task); + z_task_join(ztu->_lease_task); + z_task_free(&ztu->_lease_task); } // Clean up the mutexes - zp_mutex_free(&ztu->_mutex_tx); - zp_mutex_free(&ztu->_mutex_rx); + z_mutex_free(&ztu->_mutex_tx); + z_mutex_free(&ztu->_mutex_rx); #endif // Z_FEATURE_MULTI_THREAD == 1 // Clean up the buffers diff --git a/src/transport/unicast/tx.c b/src/transport/unicast/tx.c index b89b7c0e9..3eb220e56 100644 --- a/src/transport/unicast/tx.c +++ b/src/transport/unicast/tx.c @@ -49,7 +49,7 @@ int8_t _z_unicast_send_t_msg(_z_transport_unicast_t *ztu, const _z_transport_mes #if Z_FEATURE_MULTI_THREAD == 1 // Acquire the lock - zp_mutex_lock(&ztu->_mutex_tx); + z_mutex_lock(&ztu->_mutex_tx); #endif // Z_FEATURE_MULTI_THREAD == 1 // Prepare the buffer eventually reserving space for the message length @@ -68,7 +68,7 @@ int8_t _z_unicast_send_t_msg(_z_transport_unicast_t *ztu, const _z_transport_mes } #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&ztu->_mutex_tx); + z_mutex_unlock(&ztu->_mutex_tx); #endif // Z_FEATURE_MULTI_THREAD == 1 return ret; @@ -85,11 +85,11 @@ int8_t _z_unicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg _Bool drop = false; if (cong_ctrl == Z_CONGESTION_CONTROL_BLOCK) { #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_lock(&ztu->_mutex_tx); + z_mutex_lock(&ztu->_mutex_tx); #endif // Z_FEATURE_MULTI_THREAD == 1 } else { #if Z_FEATURE_MULTI_THREAD == 1 - int8_t locked = zp_mutex_trylock(&ztu->_mutex_tx); + int8_t locked = z_mutex_trylock(&ztu->_mutex_tx); if (locked != (int8_t)0) { _Z_INFO("Dropping zenoh message because of congestion control"); // We failed to acquire the lock, drop the message @@ -163,7 +163,7 @@ int8_t _z_unicast_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg } #if Z_FEATURE_MULTI_THREAD == 1 - zp_mutex_unlock(&ztu->_mutex_tx); + z_mutex_unlock(&ztu->_mutex_tx); #endif // Z_FEATURE_MULTI_THREAD == 1 } diff --git a/tests/z_api_alignment_test.c b/tests/z_api_alignment_test.c index f95fb38e3..dd0be80da 100644 --- a/tests/z_api_alignment_test.c +++ b/tests/z_api_alignment_test.c @@ -215,9 +215,9 @@ int main(int argc, char **argv) { assert(hellos >= 1); uint32_t _scouting_timeout = strtoul(SCOUTING_TIMEOUT, NULL, 10); - zp_sleep_ms(_scouting_timeout); + z_sleep_ms(_scouting_timeout); printf("Ok\n"); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); z_owned_session_t s1 = z_open(z_move(_ret_config)); assert(z_check(s1)); diff --git a/tests/z_client_test.c b/tests/z_client_test.c index bbb73bd30..023798062 100644 --- a/tests/z_client_test.c +++ b/tests/z_client_test.c @@ -130,7 +130,7 @@ int main(int argc, char **argv) { zp_start_read_task(z_loan(s1), NULL); zp_start_lease_task(z_loan(s1), NULL); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); config = z_config_default(); zp_config_insert(z_loan(config), Z_CONFIG_CONNECT_KEY, z_string_make(argv[1])); @@ -145,7 +145,7 @@ int main(int argc, char **argv) { zp_start_read_task(z_loan(s2), NULL); zp_start_lease_task(z_loan(s2), NULL); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); // Declare resources on both sessions char *s1_res = (char *)malloc(64); @@ -156,7 +156,7 @@ int main(int argc, char **argv) { rids1[i] = expr; } - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); for (unsigned int i = 0; i < SET; i++) { snprintf(s1_res, 64, "%s%u", uri, i); @@ -165,12 +165,12 @@ int main(int argc, char **argv) { rids2[i] = expr; } - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); // Declare subscribers and queryabales on second session for (unsigned int i = 0; i < SET; i++) { z_owned_closure_sample_t callback = z_closure(data_handler, NULL, &idx[i]); - z_owned_subscriber_t *sub = (z_owned_subscriber_t *)zp_malloc(sizeof(z_owned_subscriber_t)); + z_owned_subscriber_t *sub = (z_owned_subscriber_t *)z_malloc(sizeof(z_owned_subscriber_t)); *sub = z_declare_subscriber(z_loan(s2), z_loan(rids2[i]), &callback, NULL); assert(z_check(*sub)); printf("Declared subscription on session 2: %ju %u %s\n", (uintmax_t)z_subscriber_loan(sub)._val->_entity_id, @@ -178,12 +178,12 @@ int main(int argc, char **argv) { subs2 = _z_list_push(subs2, sub); } - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); for (unsigned int i = 0; i < SET; i++) { snprintf(s1_res, 64, "%s%u", uri, i); z_owned_closure_query_t callback = z_closure(query_handler, NULL, &idx[i]); - z_owned_queryable_t *qle = (z_owned_queryable_t *)zp_malloc(sizeof(z_owned_queryable_t)); + z_owned_queryable_t *qle = (z_owned_queryable_t *)z_malloc(sizeof(z_owned_queryable_t)); *qle = z_declare_queryable(z_loan(s2), z_keyexpr(s1_res), &callback, NULL); assert(z_check(*qle)); printf("Declared queryable on session 2: %ju %zu %s\n", (uintmax_t)qle->_value->_entity_id, (z_zint_t)0, @@ -191,21 +191,21 @@ int main(int argc, char **argv) { qles2 = _z_list_push(qles2, qle); } - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); // Declare publisher on first session for (unsigned int i = 0; i < SET; i++) { - z_owned_publisher_t *pub = (z_owned_publisher_t *)zp_malloc(sizeof(z_owned_publisher_t)); + z_owned_publisher_t *pub = (z_owned_publisher_t *)z_malloc(sizeof(z_owned_publisher_t)); *pub = z_declare_publisher(z_loan(s1), z_loan(rids1[i]), NULL); if (!z_check(*pub)) printf("Declared publisher on session 1: %zu\n", z_loan(*pub)._val->_id); pubs1 = _z_list_push(pubs1, pub); } - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); // Write data from first session size_t len = MSG_LEN; - uint8_t *payload = (uint8_t *)zp_malloc(len); + uint8_t *payload = (uint8_t *)z_malloc(len); memset(payload, 1, MSG_LEN); total = MSG * SET; @@ -220,12 +220,12 @@ int main(int argc, char **argv) { } // Wait to receive all the data - zp_clock_t now = zp_clock_now(); + z_clock_t now = z_clock_now(); unsigned int expected = is_reliable ? total : 1; while (datas < expected) { - assert(zp_clock_elapsed_s(&now) < TIMEOUT); + assert(z_clock_elapsed_s(&now) < TIMEOUT); printf("Waiting for datas... %u/%u\n", datas, expected); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); } if (is_reliable == true) assert(datas == expected); @@ -233,13 +233,13 @@ int main(int argc, char **argv) { assert(datas >= expected); datas = 0; - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); // Write fragment data from first session if (is_reliable) { - zp_free((uint8_t *)payload); + z_free((uint8_t *)payload); len = FRAGMENT_MSG_LEN; - payload = (uint8_t *)zp_malloc(len); + payload = (uint8_t *)z_malloc(len); memset(payload, 1, FRAGMENT_MSG_LEN); total = FRAGMENT_MSG_NB * SET; @@ -253,17 +253,17 @@ int main(int argc, char **argv) { } } // Wait to receive all the data - now = zp_clock_now(); + now = z_clock_now(); while (datas < total) { - assert(zp_clock_elapsed_s(&now) < TIMEOUT); + assert(z_clock_elapsed_s(&now) < TIMEOUT); printf("Waiting for fragment datas... %u/%u\n", datas, total); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); } if (is_reliable == true) { assert(datas == total); } datas = 0; - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); } // Query data from first session @@ -278,12 +278,12 @@ int main(int argc, char **argv) { } // Wait to receive all the expected queries - now = zp_clock_now(); + now = z_clock_now(); expected = is_reliable ? total : 1; while (queries < expected) { - assert(zp_clock_elapsed_s(&now) < TIMEOUT); + assert(z_clock_elapsed_s(&now) < TIMEOUT); printf("Waiting for queries... %u/%u\n", queries, expected); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); } if (is_reliable == true) assert(queries == expected); @@ -292,11 +292,11 @@ int main(int argc, char **argv) { queries = 0; // Wait to receive all the expected replies - now = zp_clock_now(); + now = z_clock_now(); while (replies < expected) { - assert(zp_clock_elapsed_s(&now) < TIMEOUT); + assert(z_clock_elapsed_s(&now) < TIMEOUT); printf("Waiting for replies... %u/%u\n", replies, expected); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); } if (is_reliable == true) assert(replies == expected); @@ -304,7 +304,7 @@ int main(int argc, char **argv) { assert(replies >= expected); replies = 0; - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); // Undeclare publishers on first session while (pubs1) { @@ -314,7 +314,7 @@ int main(int argc, char **argv) { pubs1 = _z_list_pop(pubs1, _z_noop_elem_free, NULL); } - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); // Undeclare subscribers and queryables on second session while (subs2) { @@ -324,7 +324,7 @@ int main(int argc, char **argv) { subs2 = _z_list_pop(subs2, _z_noop_elem_free, NULL); } - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); while (qles2) { z_owned_queryable_t *qle = _z_list_head(qles2); @@ -333,7 +333,7 @@ int main(int argc, char **argv) { qles2 = _z_list_pop(qles2, _z_noop_elem_free, NULL); } - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); // Undeclare resources on both sessions for (unsigned int i = 0; i < SET; i++) { @@ -341,14 +341,14 @@ int main(int argc, char **argv) { z_undeclare_keyexpr(z_loan(s1), z_move(rids1[i])); } - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); for (unsigned int i = 0; i < SET; i++) { printf("Undeclared resource on session 2: %u\n", z_loan(rids2[i])._id); z_undeclare_keyexpr(z_loan(s2), z_move(rids2[i])); } - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); // Stop both sessions printf("Stopping threads on session 1\n"); @@ -363,12 +363,12 @@ int main(int argc, char **argv) { printf("Closing session 1\n"); z_close(z_move(s1)); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); printf("Closing session 2\n"); z_close(z_move(s2)); - zp_free((uint8_t *)payload); + z_free((uint8_t *)payload); payload = NULL; free(s1_res); diff --git a/tests/z_data_struct_test.c b/tests/z_data_struct_test.c index b877d08ae..461ee92ca 100644 --- a/tests/z_data_struct_test.c +++ b/tests/z_data_struct_test.c @@ -27,7 +27,7 @@ void entry_list_test(void) { _z_transport_peer_entry_list_t *root = _z_transport_peer_entry_list_new(); for (int i = 0; i < 10; i++) { - _z_transport_peer_entry_t *entry = (_z_transport_peer_entry_t *)zp_malloc(sizeof(_z_transport_peer_entry_t)); + _z_transport_peer_entry_t *entry = (_z_transport_peer_entry_t *)z_malloc(sizeof(_z_transport_peer_entry_t)); root = _z_transport_peer_entry_list_insert(root, entry); } _z_transport_peer_entry_list_t *list = root; @@ -37,7 +37,7 @@ void entry_list_test(void) { _z_transport_peer_entry_list_head(root)->_peer_id = _Z_KEYEXPR_MAPPING_UNKNOWN_REMOTE - 1; for (int i = 0; i < 11; i++) { - _z_transport_peer_entry_t *entry = (_z_transport_peer_entry_t *)zp_malloc(sizeof(_z_transport_peer_entry_t)); + _z_transport_peer_entry_t *entry = (_z_transport_peer_entry_t *)z_malloc(sizeof(_z_transport_peer_entry_t)); root = _z_transport_peer_entry_list_insert(root, entry); } assert(_z_transport_peer_entry_list_head(root)->_peer_id == _Z_KEYEXPR_MAPPING_UNKNOWN_REMOTE - 1); diff --git a/tests/z_iobuf_test.c b/tests/z_iobuf_test.c index 88fe777b7..3a851efc0 100644 --- a/tests/z_iobuf_test.c +++ b/tests/z_iobuf_test.c @@ -46,13 +46,13 @@ void print_iosli(_z_iosli_t *ios) { /*=============================*/ /* Generating functions */ /*=============================*/ -int gen_bool(void) { return zp_random_u8() % 2; } +int gen_bool(void) { return z_random_u8() % 2; } -uint8_t gen_uint8(void) { return zp_random_u8() % 255; } +uint8_t gen_uint8(void) { return z_random_u8() % 255; } size_t gen_size_t(void) { size_t ret = 0; - zp_random_fill(&ret, sizeof(ret)); + z_random_fill(&ret, sizeof(ret)); return ret; } @@ -154,7 +154,7 @@ void iosli_writable_readable(void) { assert(_z_iosli_readable(cios) == 0); printf(" - IOSli bytes\n"); - uint8_t *payload = (uint8_t *)zp_malloc(len); + uint8_t *payload = (uint8_t *)z_malloc(len); memset((uint8_t *)payload, 1, len); for (size_t i = 0; i < len; i++) { @@ -172,7 +172,7 @@ void iosli_writable_readable(void) { assert(readable == i + 1); } - uint8_t *buffer = (uint8_t *)zp_malloc(len); + uint8_t *buffer = (uint8_t *)z_malloc(len); memset((uint8_t *)buffer, 1, len); _z_iosli_write_bytes(&ios, payload, 0, len); @@ -203,12 +203,12 @@ void iosli_writable_readable(void) { assert(_z_iosli_readable(&wios) == 0); _z_iosli_clear(pios); - zp_free(pios); + z_free(pios); _z_iosli_clear(cios); - zp_free(cios); + z_free(cios); - zp_free(buffer); - zp_free(payload); + z_free(buffer); + z_free(payload); } void zbuf_writable_readable(void) { @@ -382,7 +382,7 @@ void wbuf_write_zbuf_read_bytes(void) { print_wbuf_overview(&wbf); printf(" Writing %zu bytes\n", len); - uint8_t *buf01 = (uint8_t *)zp_malloc(len); + uint8_t *buf01 = (uint8_t *)z_malloc(len); for (size_t i = 0; i < len; i++) { buf01[i] = (uint8_t)i % 255; } @@ -402,7 +402,7 @@ void wbuf_write_zbuf_read_bytes(void) { } printf(" ]\n"); - zp_free(buf01); + z_free(buf01); _z_zbuf_clear(&zbf); _z_wbuf_clear(&wbf); } @@ -442,7 +442,7 @@ void wbuf_put_zbuf_get(void) { void wbuf_reusable_write_zbuf_read(void) { _z_wbuf_t wbf = gen_wbuf(128); for (int i = 1; i <= 10; i++) { - size_t len = zp_random_u8() % 128; + size_t len = z_random_u8() % 128; printf("\n>>> WBuf => Write and Read round %d\n", i); print_wbuf_overview(&wbf); printf(" Writing %zu bytes\n", len); diff --git a/tests/z_msgcodec_test.c b/tests/z_msgcodec_test.c index 4e4511baa..db4347f41 100644 --- a/tests/z_msgcodec_test.c +++ b/tests/z_msgcodec_test.c @@ -133,27 +133,27 @@ void print_scouting_message_type(uint8_t header) { /*=============================*/ /* Generating functions */ /*=============================*/ -_Bool gen_bool(void) { return zp_random_u8() % 2; } +_Bool gen_bool(void) { return z_random_u8() % 2; } -uint8_t gen_uint8(void) { return zp_random_u8(); } +uint8_t gen_uint8(void) { return z_random_u8(); } -uint16_t gen_uint16(void) { return zp_random_u16(); } +uint16_t gen_uint16(void) { return z_random_u16(); } uint64_t gen_uint64(void) { uint64_t ret = 0; - zp_random_fill(&ret, sizeof(ret)); + z_random_fill(&ret, sizeof(ret)); return ret; } unsigned int gen_uint(void) { unsigned int ret = 0; - zp_random_fill(&ret, sizeof(ret)); + z_random_fill(&ret, sizeof(ret)); return ret; } _z_zint_t gen_zint(void) { _z_zint_t ret = 0; - zp_random_fill(&ret, sizeof(ret)); + z_random_fill(&ret, sizeof(ret)); return ret; } @@ -172,8 +172,8 @@ _z_bytes_t gen_payload(size_t len) { _z_bytes_t pld; pld._is_alloc = true; pld.len = len; - pld.start = (uint8_t *)zp_malloc(len); - zp_random_fill((uint8_t *)pld.start, pld.len); + pld.start = (uint8_t *)z_malloc(len); + z_random_fill((uint8_t *)pld.start, pld.len); return pld; } @@ -185,7 +185,7 @@ _z_bytes_t gen_bytes(size_t len) { arr.start = NULL; if (len == 0) return arr; - arr.start = (uint8_t *)zp_malloc(sizeof(uint8_t) * len); + arr.start = (uint8_t *)z_malloc(sizeof(uint8_t) * len); for (_z_zint_t i = 0; i < len; i++) { ((uint8_t *)arr.start)[i] = gen_uint8() & 0x7f; // 0b01111111 } @@ -208,9 +208,9 @@ _z_id_t gen_zid(void) { char *gen_str(size_t size) { char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - char *str = (char *)zp_malloc(size + 1); + char *str = (char *)z_malloc(size + 1); for (_z_zint_t i = 0; i < size; i++) { - uint32_t key = zp_random_u32() % (sizeof(charset) - 1); + uint32_t key = z_random_u32() % (sizeof(charset) - 1); str[i] = charset[key]; } str[size] = '\0'; @@ -328,8 +328,8 @@ void assert_eq_locator_array(const _z_locator_array_t *left, const _z_locator_ar printf("%s:%s", ls, rs); if (i < left->_len - 1) printf(" "); - zp_free(ls); - zp_free(rs); + z_free(ls); + z_free(rs); assert(_z_locator_eq(l, r) == true); } @@ -1660,7 +1660,7 @@ void assert_eq_net_msg(const _z_network_message_t *left, const _z_network_messag _z_network_message_vec_t gen_net_msgs(size_t n) { _z_network_message_vec_t ret = _z_network_message_vec_make(n); for (size_t i = 0; i < n; i++) { - _z_network_message_t *msg = (_z_network_message_t *)zp_malloc(sizeof(_z_network_message_t)); + _z_network_message_t *msg = (_z_network_message_t *)z_malloc(sizeof(_z_network_message_t)); *msg = gen_net_msg(); _z_network_message_vec_append(&ret, msg); } diff --git a/tests/z_peer_multicast_test.c b/tests/z_peer_multicast_test.c index f0448ad41..cd8b28f05 100644 --- a/tests/z_peer_multicast_test.c +++ b/tests/z_peer_multicast_test.c @@ -83,7 +83,7 @@ int main(int argc, char **argv) { zp_start_read_task(z_loan(s1), NULL); zp_start_lease_task(z_loan(s1), NULL); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); config = z_config_default(); zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make("peer")); @@ -100,7 +100,7 @@ int main(int argc, char **argv) { zp_start_read_task(z_loan(s2), NULL); zp_start_lease_task(z_loan(s2), NULL); - zp_sleep_s(SLEEP * 5); + z_sleep_s(SLEEP * 5); // Declare subscribers on second session char *s1_res = (char *)malloc(64); @@ -108,7 +108,7 @@ int main(int argc, char **argv) { memset(s1_res, 0, 64); snprintf(s1_res, 64, "%s%u", uri, i); z_owned_closure_sample_t callback = z_closure(data_handler, NULL, &idx[i]); - z_owned_subscriber_t *sub = (z_owned_subscriber_t *)zp_malloc(sizeof(z_owned_subscriber_t)); + z_owned_subscriber_t *sub = (z_owned_subscriber_t *)z_malloc(sizeof(z_owned_subscriber_t)); *sub = z_declare_subscriber(z_loan(s2), z_keyexpr(s1_res), &callback, NULL); assert(z_check(*sub)); printf("Declared subscription on session 2: %ju %zu %s\n", (uintmax_t)z_subscriber_loan(sub)._val->_entity_id, @@ -118,7 +118,7 @@ int main(int argc, char **argv) { // Write data from first session size_t len = MSG_LEN; - uint8_t *payload = (uint8_t *)zp_malloc(len); + uint8_t *payload = (uint8_t *)z_malloc(len); memset(payload, 1, MSG_LEN); total = MSG * SET; @@ -134,13 +134,13 @@ int main(int argc, char **argv) { } // Wait to receive all the data - zp_time_t now = zp_time_now(); + z_time_t now = z_time_now(); unsigned int expected = is_reliable ? total : 1; while (datas < expected) { - assert(zp_time_elapsed_s(&now) < TIMEOUT); + assert(z_time_elapsed_s(&now) < TIMEOUT); (void)(now); printf("Waiting for datas... %u/%u\n", datas, expected); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); } if (is_reliable == true) assert(datas == expected); @@ -148,7 +148,7 @@ int main(int argc, char **argv) { assert(datas >= expected); datas = 0; - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); // Undeclare subscribers and queryables on second session while (subs2) { @@ -158,7 +158,7 @@ int main(int argc, char **argv) { subs2 = _z_list_pop(subs2, _z_noop_elem_free, NULL); } - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); // Stop both sessions printf("Stopping threads on session 1\n"); @@ -173,12 +173,12 @@ int main(int argc, char **argv) { printf("Closing session 1\n"); z_close(z_move(s1)); - zp_sleep_s(SLEEP); + z_sleep_s(SLEEP); printf("Closing session 2\n"); z_close(z_move(s2)); - zp_free((uint8_t *)payload); + z_free((uint8_t *)payload); payload = NULL; free(s1_res); diff --git a/tests/z_perf_rx.c b/tests/z_perf_rx.c index 2eadf731c..58d5959c1 100644 --- a/tests/z_perf_rx.c +++ b/tests/z_perf_rx.c @@ -21,7 +21,7 @@ typedef struct { volatile unsigned long count; unsigned long curr_len; - zp_clock_t start; + z_clock_t start; } z_stats_t; static z_stats_t test_stats; @@ -34,7 +34,7 @@ void z_stats_stop(z_stats_t *stats) { return; } // Print values - unsigned long elapsed_ms = zp_clock_elapsed_ms(&stats->start); + unsigned long elapsed_ms = z_clock_elapsed_ms(&stats->start); printf("End test for pkt len: %lu, msg nb: %lu, time ms: %lu\n", stats->curr_len, stats->count, elapsed_ms); stats->count = 0; } @@ -53,7 +53,7 @@ void on_sample(const z_sample_t *sample, void *context) { } // Start new measurement printf("Starting test for pkt len: %lu\n", stats->curr_len); - stats->start = zp_clock_now(); + stats->start = z_clock_now(); } stats->count++; } @@ -109,7 +109,7 @@ int main(int argc, char **argv) { } // Wait for everything to settle printf("End of test\n"); - zp_sleep_s(1); + z_sleep_s(1); // Clean up z_undeclare_subscriber(z_move(sub)); zp_stop_read_task(z_loan(s)); diff --git a/tests/z_perf_tx.c b/tests/z_perf_tx.c index 168294d28..1852ecf37 100644 --- a/tests/z_perf_tx.c +++ b/tests/z_perf_tx.c @@ -23,11 +23,11 @@ #if Z_FEATURE_PUBLICATION == 1 int send_packets(unsigned long pkt_len, z_owned_publisher_t *pub, uint8_t *value) { - zp_clock_t test_start = zp_clock_now(); + z_clock_t test_start = z_clock_now(); unsigned long elapsed_us = 0; while (elapsed_us < TEST_DURATION_US) { z_publisher_put(z_loan(*pub), (const uint8_t *)value, pkt_len, NULL); - elapsed_us = zp_clock_elapsed_us(&test_start); + elapsed_us = z_clock_elapsed_us(&test_start); } return 0; } @@ -83,7 +83,7 @@ int main(int argc, char **argv) { // Wait for joins if (strcmp(mode, "peer") == 0) { printf("Waiting for JOIN messages\n"); - zp_sleep_s(3); + z_sleep_s(3); } // Send packets for (size_t i = 0; i < ARRAY_SIZE(len_array); i++) { diff --git a/tests/z_session_test.c b/tests/z_session_test.c index 33b1977bc..40058e102 100644 --- a/tests/z_session_test.c +++ b/tests/z_session_test.c @@ -40,7 +40,7 @@ int main(void) { } // Commented out wait for 1 second. Stopping should work without it. - // zp_sleep_ms(1000); + // z_sleep_ms(1000); // Stop read and lease tasks for zenoh-pico zp_stop_read_task(z_loan(s));