diff --git a/examples/freertos_plus_tcp/z_get.c b/examples/freertos_plus_tcp/z_get.c index 9da9bb624..39545dc2a 100644 --- a/examples/freertos_plus_tcp/z_get.c +++ b/examples/freertos_plus_tcp/z_get.c @@ -75,7 +75,7 @@ void app_main(void) { } while (1) { - z_sleep_s(5); + zp_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 565a4a576..a71557045 100644 --- a/examples/freertos_plus_tcp/z_pub.c +++ b/examples/freertos_plus_tcp/z_pub.c @@ -88,7 +88,7 @@ void app_main(void) { char *buf = (char *)pvPortMalloc(256); for (int idx = 0; 1; ++idx) { - z_sleep_s(1); + zp_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 03311e25c..49b7761eb 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); - z_clock_t now = z_clock_now(); + zp_clock_t now = zp_clock_now(); for (int idx = 0; 1;) { - if (z_clock_elapsed_ms(&now) > 1000) { + if (zp_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 = z_clock_now(); + now = zp_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 601bfe720..04d2c3e34 100644 --- a/examples/freertos_plus_tcp/z_pull.c +++ b/examples/freertos_plus_tcp/z_pull.c @@ -65,7 +65,7 @@ void app_main(void) { } while (1) { - z_sleep_s(5); + zp_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 43c6a4975..40b142645 100644 --- a/examples/freertos_plus_tcp/z_put.c +++ b/examples/freertos_plus_tcp/z_put.c @@ -64,7 +64,7 @@ void app_main(void) { } while (1) { - z_sleep_s(1); + zp_sleep_s(1); } z_undeclare_keyexpr(z_loan(s), z_move(ke)); diff --git a/examples/freertos_plus_tcp/z_queryable.c b/examples/freertos_plus_tcp/z_queryable.c index 19f960eac..ea46660d1 100644 --- a/examples/freertos_plus_tcp/z_queryable.c +++ b/examples/freertos_plus_tcp/z_queryable.c @@ -79,7 +79,7 @@ void app_main(void) { } while (1) { - z_sleep_s(5); + zp_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 7f403d58a..ce4a90b1a 100644 --- a/examples/freertos_plus_tcp/z_sub.c +++ b/examples/freertos_plus_tcp/z_sub.c @@ -65,7 +65,7 @@ void app_main(void) { } while (1) { - z_sleep_s(5); + zp_sleep_s(5); } z_undeclare_subscriber(z_move(sub)); diff --git a/examples/mbed/z_get.cpp b/examples/mbed/z_get.cpp index 905ac4e1c..21e77c33d 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) { - z_sleep_s(5); + zp_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 0fb939071..7ef9f1dc4 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) { - z_sleep_s(1); + zp_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 d6b82c1d0..4bcd33ed5 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) { - z_sleep_s(5); + zp_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 08ade9084..b2f597d58 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) { - z_sleep_s(5); + zp_sleep_s(5); } printf("Closing Zenoh Session..."); diff --git a/examples/mbed/z_sub.cpp b/examples/mbed/z_sub.cpp index 0b3cbdd47..62ac126d3 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) { - z_sleep_s(5); + zp_sleep_s(5); } printf("Closing Zenoh Session..."); diff --git a/examples/unix/c11/z_ping.c b/examples/unix/c11/z_ping.c index 21dca9325..65a871f05 100644 --- a/examples/unix/c11/z_ping.c +++ b/examples/unix/c11/z_ping.c @@ -33,11 +33,11 @@ static zp_mutex_t mutex; void callback(const z_sample_t* sample, void* context) { (void)sample; (void)context; - z_condvar_signal(&cond); + zp_condvar_signal(&cond); } void drop(void* context) { (void)context; - z_condvar_free(&cond); + zp_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; } - z_mutex_init(&mutex); - z_condvar_init(&cond); + zp_mutex_init(&mutex); + zp_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 = z_malloc(args.size); + uint8_t* data = zp_malloc(args.size); for (unsigned int i = 0; i < args.size; i++) { data[i] = i % 10; } - z_mutex_lock(&mutex); + zp_mutex_lock(&mutex); if (args.warmup_ms) { printf("Warming up for %dms...\n", args.warmup_ms); - z_clock_t warmup_start = z_clock_now(); + zp_clock_t warmup_start = zp_clock_now(); unsigned long elapsed_us = 0; while (elapsed_us < args.warmup_ms * 1000) { z_publisher_put(z_loan(pub), data, args.size, NULL); - z_condvar_wait(&cond, &mutex); - elapsed_us = z_clock_elapsed_us(&warmup_start); + zp_condvar_wait(&cond, &mutex); + elapsed_us = zp_clock_elapsed_us(&warmup_start); } } - unsigned long* results = z_malloc(sizeof(unsigned long) * args.number_of_pings); + unsigned long* results = zp_malloc(sizeof(unsigned long) * args.number_of_pings); for (unsigned int i = 0; i < args.number_of_pings; i++) { - z_clock_t measure_start = z_clock_now(); + zp_clock_t measure_start = zp_clock_now(); z_publisher_put(z_loan(pub), data, args.size, NULL); - z_condvar_wait(&cond, &mutex); - results[i] = z_clock_elapsed_us(&measure_start); + zp_condvar_wait(&cond, &mutex); + results[i] = zp_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); } - z_mutex_unlock(&mutex); - z_free(results); - z_free(data); + zp_mutex_unlock(&mutex); + zp_free(results); + zp_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 676d37d9c..347a70848 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; - z_clock_t start; - z_clock_t first_start; + zp_clock_t start; + zp_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 = z_clock_now(); + stats->start = zp_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 = z_clock_elapsed_ms(&stats->start); + unsigned long elapsed_ms = zp_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 = z_clock_elapsed_ms(&stats->first_start); + unsigned long elapsed_ms = zp_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); @@ -105,7 +105,7 @@ int main(int argc, char **argv) { } // Wait for everything to settle printf("End of test\n"); - z_sleep_s(1); + zp_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 2aff0b00f..0ab80b8ba 100644 --- a/examples/unix/c99/z_ping.c +++ b/examples/unix/c99/z_ping.c @@ -34,11 +34,11 @@ static zp_mutex_t mutex; void callback(const z_sample_t* sample, void* context) { (void)sample; (void)context; - z_condvar_signal(&cond); + zp_condvar_signal(&cond); } void drop(void* context) { (void)context; - z_condvar_free(&cond); + zp_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; } - z_mutex_init(&mutex); - z_condvar_init(&cond); + zp_mutex_init(&mutex); + zp_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)) { @@ -93,34 +93,34 @@ int main(int argc, char** argv) { return -1; } - uint8_t* data = z_malloc(args.size); + uint8_t* data = zp_malloc(args.size); for (unsigned int i = 0; i < args.size; i++) { data[i] = i % 10; } - z_mutex_lock(&mutex); + zp_mutex_lock(&mutex); if (args.warmup_ms) { printf("Warming up for %dms...\n", args.warmup_ms); - z_clock_t warmup_start = z_clock_now(); + zp_clock_t warmup_start = zp_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); - z_condvar_wait(&cond, &mutex); - elapsed_us = z_clock_elapsed_us(&warmup_start); + zp_condvar_wait(&cond, &mutex); + elapsed_us = zp_clock_elapsed_us(&warmup_start); } } - unsigned long* results = z_malloc(sizeof(unsigned long) * args.number_of_pings); + unsigned long* results = zp_malloc(sizeof(unsigned long) * args.number_of_pings); for (unsigned int i = 0; i < args.number_of_pings; i++) { - z_clock_t measure_start = z_clock_now(); + zp_clock_t measure_start = zp_clock_now(); z_publisher_put(z_publisher_loan(&pub), data, args.size, NULL); - z_condvar_wait(&cond, &mutex); - results[i] = z_clock_elapsed_us(&measure_start); + zp_condvar_wait(&cond, &mutex); + results[i] = zp_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); } - z_mutex_unlock(&mutex); - z_free(results); - z_free(data); + zp_mutex_unlock(&mutex); + zp_free(results); + zp_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 785ffe01c..f62a1bd78 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); - z_clock_t now = z_clock_now(); + zp_clock_t now = zp_clock_now(); for (int idx = 0; 1;) { - if (z_clock_elapsed_ms(&now) > 1000) { + if (zp_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 = z_clock_now(); + now = zp_clock_now(); } zp_read(z_session_loan(&s), NULL); diff --git a/examples/windows/z_ping.c b/examples/windows/z_ping.c index 89467fc7c..e260f5459 100644 --- a/examples/windows/z_ping.c +++ b/examples/windows/z_ping.c @@ -33,11 +33,11 @@ static zp_mutex_t mutex; void callback(const z_sample_t* sample, void* context) { (void)sample; (void)context; - z_condvar_signal(&cond); + zp_condvar_signal(&cond); } void drop(void* context) { (void)context; - z_condvar_free(&cond); + zp_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; } - z_mutex_init(&mutex); - z_condvar_init(&cond); + zp_mutex_init(&mutex); + zp_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)) { @@ -90,34 +90,34 @@ int main(int argc, char** argv) { return -1; } - uint8_t* data = z_malloc(args.size); + uint8_t* data = zp_malloc(args.size); for (unsigned int i = 0; i < args.size; i++) { data[i] = i % 10; } - z_mutex_lock(&mutex); + zp_mutex_lock(&mutex); if (args.warmup_ms) { printf("Warming up for %dms...\n", args.warmup_ms); - z_clock_t warmup_start = z_clock_now(); + zp_clock_t warmup_start = zp_clock_now(); unsigned long elapsed_us = 0; while (elapsed_us < args.warmup_ms * 1000) { z_publisher_put(z_loan(pub), data, args.size, NULL); - z_condvar_wait(&cond, &mutex); - elapsed_us = z_clock_elapsed_us(&warmup_start); + zp_condvar_wait(&cond, &mutex); + elapsed_us = zp_clock_elapsed_us(&warmup_start); } } - unsigned long* results = z_malloc(sizeof(unsigned long) * args.number_of_pings); + unsigned long* results = zp_malloc(sizeof(unsigned long) * args.number_of_pings); for (unsigned int i = 0; i < args.number_of_pings; i++) { - z_clock_t measure_start = z_clock_now(); + zp_clock_t measure_start = zp_clock_now(); z_publisher_put(z_loan(pub), data, args.size, NULL); - z_condvar_wait(&cond, &mutex); - results[i] = z_clock_elapsed_us(&measure_start); + zp_condvar_wait(&cond, &mutex); + results[i] = zp_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); } - z_mutex_unlock(&mutex); - z_free(results); - z_free(data); + zp_mutex_unlock(&mutex); + zp_free(results); + zp_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 cc6f41361..8adea5c53 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); - z_clock_t now = z_clock_now(); + zp_clock_t now = zp_clock_now(); for (int idx = 0; 1;) { - if (z_clock_elapsed_ms(&now) > 1000) { + if (zp_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 = z_clock_now(); + now = zp_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 c96937518..15119e3d0 100644 --- a/include/zenoh-pico/api/primitives.h +++ b/include/zenoh-pico/api/primitives.h @@ -99,7 +99,7 @@ z_bytes_t z_keyexpr_as_bytes(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 ``z_free``. + * The user is responsible of dropping the returned string using ``zp_free``. * * Parameters: * zs: A loaned instance of the the :c:type:`z_session_t` to resolve the keyexpr. diff --git a/include/zenoh-pico/collections/array.h b/include/zenoh-pico/collections/array.h index fe2b3f306..a54a66af3 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 *)z_malloc(capacity * sizeof(type)); \ + a._val = (type *)zp_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]); \ } \ - z_free(a->_val); \ + zp_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); \ - z_free(ptr); \ + zp_free(ptr); \ *a = NULL; \ } \ } diff --git a/include/zenoh-pico/collections/element.h b/include/zenoh-pico/collections/element.h index 96a62e4eb..5e8997954 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); \ - z_free(ptr); \ + zp_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 *)z_malloc(elem_size_f((type *)src)); \ + type *dst = (type *)zp_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 caa54e035..1d33d8afc 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); \ - z_free(ptr); \ + zp_free(ptr); \ *e = NULL; \ } \ } \ diff --git a/include/zenoh-pico/collections/pointer.h b/include/zenoh-pico/collections/pointer.h index 9dc4c4859..aa8e6c782 100644 --- a/include/zenoh-pico/collections/pointer.h +++ b/include/zenoh-pico/collections/pointer.h @@ -48,14 +48,14 @@ } name##_sptr_t; \ static inline name##_sptr_t name##_sptr_new(type##_t val) { \ name##_sptr_t p; \ - p.ptr = (type##_t *)z_malloc(sizeof(type##_t)); \ + p.ptr = (type##_t *)zp_malloc(sizeof(type##_t)); \ if (p.ptr != NULL) { \ - p._cnt = (_z_atomic(unsigned int) *)z_malloc(sizeof(_z_atomic(unsigned int) *)); \ + p._cnt = (_z_atomic(unsigned int) *)zp_malloc(sizeof(_z_atomic(unsigned int) *)); \ if (p._cnt != NULL) { \ *p.ptr = val; \ _z_atomic_store_explicit(p._cnt, 1, _z_memory_order_relaxed); \ } else { \ - z_free(p.ptr); \ + zp_free(p.ptr); \ } \ } \ return p; \ @@ -68,7 +68,7 @@ return c; \ } \ static inline name##_sptr_t *name##_sptr_clone_as_ptr(name##_sptr_t *p) { \ - name##_sptr_t *c = (name##_sptr_t *)z_malloc(sizeof(name##_sptr_t)); \ + name##_sptr_t *c = (name##_sptr_t *)zp_malloc(sizeof(name##_sptr_t)); \ if (c != NULL) { \ c->_cnt = p->_cnt; \ c->ptr = p->ptr; \ @@ -88,8 +88,8 @@ atomic_thread_fence(_z_memory_order_acquire); \ if (p->ptr != NULL) { \ type##_clear(p->ptr); \ - z_free(p->ptr); \ - z_free((void *)p->_cnt); \ + zp_free(p->ptr); \ + zp_free((void *)p->_cnt); \ } \ } \ } \ @@ -104,14 +104,14 @@ } name##_sptr_t; \ static inline name##_sptr_t name##_sptr_new(type##_t val) { \ name##_sptr_t p; \ - p.ptr = (type##_t *)z_malloc(sizeof(type##_t)); \ + p.ptr = (type##_t *)zp_malloc(sizeof(type##_t)); \ if (p.ptr != NULL) { \ - p._cnt = (uint8_t *)z_malloc(sizeof(uint8_t)); \ + p._cnt = (uint8_t *)zp_malloc(sizeof(uint8_t)); \ if (p._cnt != NULL) { \ *p.ptr = val; \ *p._cnt = 1; \ } else { \ - z_free(p.ptr); \ + zp_free(p.ptr); \ } \ } \ return p; \ @@ -124,7 +124,7 @@ return c; \ } \ static inline name##_sptr_t *name##_sptr_clone_as_ptr(name##_sptr_t *p) { \ - name##_sptr_t *c = (name##_sptr_t *)z_malloc(sizeof(name##_sptr_t)); \ + name##_sptr_t *c = (name##_sptr_t *)zp_malloc(sizeof(name##_sptr_t)); \ if (c != NULL) { \ c->_cnt = p->_cnt; \ c->ptr = p->ptr; \ @@ -143,8 +143,8 @@ if (dropped == true) { \ if (p->ptr != NULL) { \ type##_clear(p->ptr); \ - z_free(p->ptr); \ - z_free((void *)p->_cnt); \ + zp_free(p->ptr); \ + zp_free((void *)p->_cnt); \ } \ } \ } \ diff --git a/include/zenoh-pico/system/platform.h b/include/zenoh-pico/system/platform.h index 508dd251a..5852928de 100644 --- a/include/zenoh-pico/system/platform.h +++ b/include/zenoh-pico/system/platform.h @@ -47,16 +47,16 @@ 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); +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 *z_malloc(size_t size); -void *z_realloc(void *ptr, size_t size); -void z_free(void *ptr); +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 ------------------*/ @@ -66,38 +66,38 @@ int8_t zp_task_cancel(zp_task_t *task); void zp_task_free(zp_task_t **task); /*------------------ Mutex ------------------*/ -int8_t z_mutex_init(zp_mutex_t *m); -int8_t z_mutex_free(zp_mutex_t *m); +int8_t zp_mutex_init(zp_mutex_t *m); +int8_t zp_mutex_free(zp_mutex_t *m); -int8_t z_mutex_lock(zp_mutex_t *m); +int8_t zp_mutex_lock(zp_mutex_t *m); int8_t zp_mutex_trylock(zp_mutex_t *m); -int8_t z_mutex_unlock(zp_mutex_t *m); +int8_t zp_mutex_unlock(zp_mutex_t *m); /*------------------ CondVar ------------------*/ -int8_t z_condvar_init(zp_condvar_t *cv); -int8_t z_condvar_free(zp_condvar_t *cv); +int8_t zp_condvar_init(zp_condvar_t *cv); +int8_t zp_condvar_free(zp_condvar_t *cv); -int8_t z_condvar_signal(zp_condvar_t *cv); -int8_t z_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m); +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 z_sleep_us(size_t time); -int z_sleep_ms(size_t time); -int z_sleep_s(size_t time); +int zp_sleep_us(size_t time); +int zp_sleep_ms(size_t time); +int zp_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); +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 ------------------*/ -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); +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 } diff --git a/include/zenoh-pico/system/platform/arduino/esp32.h b/include/zenoh-pico/system/platform/arduino/esp32.h index d5d131f62..c26c99a88 100644 --- a/include/zenoh-pico/system/platform/arduino/esp32.h +++ b/include/zenoh-pico/system/platform/arduino/esp32.h @@ -30,8 +30,8 @@ typedef pthread_mutex_t zp_mutex_t; typedef pthread_cond_t zp_condvar_t; #endif // Z_FEATURE_MULTI_THREAD == 1 -typedef struct timespec z_clock_t; -typedef struct timeval z_time_t; +typedef struct timespec zp_clock_t; +typedef struct timeval zp_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 e9bfa3815..ebc054164 100644 --- a/include/zenoh-pico/system/platform/arduino/opencr.h +++ b/include/zenoh-pico/system/platform/arduino/opencr.h @@ -27,8 +27,8 @@ typedef void *zp_mutex_t; typedef void *zp_condvar_t; #endif // Z_FEATURE_MULTI_THREAD == 1 -typedef struct timespec z_clock_t; -typedef struct timeval z_time_t; +typedef struct timespec zp_clock_t; +typedef struct timeval zp_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 0517139cc..e74216bf5 100644 --- a/include/zenoh-pico/system/platform/emscripten.h +++ b/include/zenoh-pico/system/platform/emscripten.h @@ -28,8 +28,8 @@ typedef pthread_mutex_t zp_mutex_t; typedef pthread_cond_t zp_condvar_t; #endif // Z_FEATURE_MULTI_THREAD == 1 -typedef double z_clock_t; -typedef double z_time_t; +typedef double zp_clock_t; +typedef double zp_time_t; typedef struct { union { diff --git a/include/zenoh-pico/system/platform/espidf.h b/include/zenoh-pico/system/platform/espidf.h index ccbfd0b2b..6210a9abc 100644 --- a/include/zenoh-pico/system/platform/espidf.h +++ b/include/zenoh-pico/system/platform/espidf.h @@ -30,8 +30,8 @@ typedef pthread_mutex_t zp_mutex_t; typedef pthread_cond_t zp_condvar_t; #endif // Z_FEATURE_MULTI_THREAD == 1 -typedef struct timespec z_clock_t; -typedef struct timeval z_time_t; +typedef struct timespec zp_clock_t; +typedef struct timeval zp_time_t; typedef struct { union { diff --git a/include/zenoh-pico/system/platform/freertos_plus_tcp.h b/include/zenoh-pico/system/platform/freertos_plus_tcp.h index 80d4cafee..8af5d8041 100644 --- a/include/zenoh-pico/system/platform/freertos_plus_tcp.h +++ b/include/zenoh-pico/system/platform/freertos_plus_tcp.h @@ -39,8 +39,8 @@ typedef SemaphoreHandle_t zp_mutex_t; typedef void *zp_condvar_t; #endif // Z_MULTI_THREAD == 1 -typedef TickType_t z_clock_t; -typedef TickType_t z_time_t; +typedef TickType_t zp_clock_t; +typedef TickType_t zp_time_t; typedef struct { union { diff --git a/include/zenoh-pico/system/platform/mbed.h b/include/zenoh-pico/system/platform/mbed.h index 559ae794b..922e95fee 100644 --- a/include/zenoh-pico/system/platform/mbed.h +++ b/include/zenoh-pico/system/platform/mbed.h @@ -29,8 +29,8 @@ 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_clock_t; // Not defined -typedef struct timeval z_time_t; +typedef void *zp_clock_t; // Not defined +typedef struct timeval zp_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 96fdcc42f..d3344a73f 100644 --- a/include/zenoh-pico/system/platform/unix.h +++ b/include/zenoh-pico/system/platform/unix.h @@ -31,8 +31,8 @@ typedef pthread_mutex_t zp_mutex_t; typedef pthread_cond_t zp_condvar_t; #endif // Z_FEATURE_MULTI_THREAD == 1 -typedef struct timespec z_clock_t; -typedef struct timeval z_time_t; +typedef struct timespec zp_clock_t; +typedef struct timeval zp_time_t; typedef struct { union { diff --git a/include/zenoh-pico/system/platform/void.h b/include/zenoh-pico/system/platform/void.h index e35a7a877..b124bbc8f 100644 --- a/include/zenoh-pico/system/platform/void.h +++ b/include/zenoh-pico/system/platform/void.h @@ -24,7 +24,7 @@ typedef void *zp_mutex_t; typedef void *zp_condvar_t; #endif // Z_FEATURE_MULTI_THREAD == 1 -typedef void *z_clock_t; -typedef void *z_time_t; +typedef void *zp_clock_t; +typedef void *zp_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 9ce5fe45e..44e3b5a25 100644 --- a/include/zenoh-pico/system/platform/windows.h +++ b/include/zenoh-pico/system/platform/windows.h @@ -27,8 +27,8 @@ typedef SRWLOCK zp_mutex_t; typedef CONDITION_VARIABLE zp_condvar_t; #endif // Z_FEATURE_MULTI_THREAD == 1 -typedef LARGE_INTEGER z_clock_t; -typedef struct timeb z_time_t; +typedef LARGE_INTEGER zp_clock_t; +typedef struct timeb zp_time_t; typedef struct { union { diff --git a/include/zenoh-pico/system/platform/zephyr.h b/include/zenoh-pico/system/platform/zephyr.h index e2bd18e26..830f7f2f4 100644 --- a/include/zenoh-pico/system/platform/zephyr.h +++ b/include/zenoh-pico/system/platform/zephyr.h @@ -37,8 +37,8 @@ typedef pthread_mutex_t zp_mutex_t; typedef pthread_cond_t zp_condvar_t; #endif // Z_FEATURE_MULTI_THREAD == 1 -typedef struct timespec z_clock_t; -typedef struct timeval z_time_t; +typedef struct timespec zp_clock_t; +typedef struct timeval zp_time_t; typedef struct { union { diff --git a/include/zenoh-pico/utils/logging.h b/include/zenoh-pico/utils/logging.h index f3a5467a3..5b8f73136 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 ", z_time_now_as_str(ret, sizeof(ret))); + printf("[%s ", zp_time_now_as_str(ret, sizeof(ret))); } // Logging macros diff --git a/src/api/api.c b/src/api/api.c index 9455a6a2e..a09e1f1b4 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -58,7 +58,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 *)z_malloc(ke_len); + ret._value = (char *)zp_malloc(ke_len); if (ret._value != NULL) { _z_str_n_copy(ret._value, keyexpr._suffix, ke_len); } @@ -338,7 +338,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 *)z_malloc(sizeof(type)); \ + ret._value = (type *)zp_malloc(sizeof(type)); \ if (ret._value != NULL) { \ f_copy(ret._value, val->_value); \ } \ @@ -359,7 +359,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 *)z_malloc(sizeof(_##type)); \ + ret._value = (_##type *)zp_malloc(sizeof(_##type)); \ if (ret._value != NULL) { \ f_copy(ret._value, val->_value); \ } \ @@ -381,7 +381,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)z_malloc(size); \ + ret._value = (_##type)zp_malloc(size); \ if (ret._value != NULL) { \ f_copy(ret._value, val->_value, size); \ } \ @@ -478,7 +478,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 *)z_malloc(sizeof(__z_hello_handler_wrapper_t)); + (__z_hello_handler_wrapper_t *)zp_malloc(sizeof(__z_hello_handler_wrapper_t)); if (wrapped_ctx != NULL) { wrapped_ctx->user_call = callback->call; wrapped_ctx->ctx = ctx; @@ -509,7 +509,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); - z_free(wrapped_ctx); + zp_free(wrapped_ctx); z_scouting_config_drop(config); } else { ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; @@ -519,12 +519,12 @@ int8_t z_scout(z_owned_scouting_config_t *config, z_owned_closure_hello_t *callb } z_owned_session_t z_open(z_owned_config_t *config) { - z_owned_session_t zs = {._value = (_z_session_t *)z_malloc(sizeof(_z_session_t))}; + z_owned_session_t zs = {._value = (_z_session_t *)zp_malloc(sizeof(_z_session_t))}; memset(zs._value, 0, sizeof(_z_session_t)); if (zs._value != NULL) { if (_z_open(zs._value, config->_value) != _Z_RES_OK) { - z_free(zs._value); + zp_free(zs._value); zs._value = NULL; } @@ -695,7 +695,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 = z_malloc(sizeof(_z_keyexpr_t))}; + z_owned_keyexpr_t ret = {._value = zp_malloc(sizeof(_z_keyexpr_t))}; if (ret._value != NULL && publisher._val != NULL) { *ret._value = _z_keyexpr_duplicate(publisher._val->_key); } @@ -750,7 +750,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 *)z_malloc(sizeof(__z_reply_handler_wrapper_t)); + (__z_reply_handler_wrapper_t *)zp_malloc(sizeof(__z_reply_handler_wrapper_t)); if (wrapped_ctx != NULL) { wrapped_ctx->user_call = callback->call; wrapped_ctx->ctx = ctx; @@ -842,7 +842,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 *)z_malloc(sizeof(z_keyexpr_t)) : NULL; + key._value = name ? (z_keyexpr_t *)zp_malloc(sizeof(z_keyexpr_t)) : NULL; if (key._value != NULL) { *key._value = _z_rid_with_suffix(Z_RESOURCE_ID_NONE, name); } @@ -853,7 +853,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 *)z_malloc(sizeof(z_keyexpr_t)); + key._value = (z_keyexpr_t *)zp_malloc(sizeof(z_keyexpr_t)); if (key._value != NULL) { uint16_t id = _z_declare_resource(zs._val, keyexpr); *key._value = _z_rid_with_suffix(id, NULL); @@ -906,7 +906,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 = z_malloc(len + 1); + suffix = zp_malloc(len + 1); if (suffix != NULL) { memcpy(suffix, keyexpr._suffix, len); suffix[len] = 0; @@ -929,7 +929,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) { - z_free(suffix); + zp_free(suffix); } return (z_owned_subscriber_t){._value = sub}; @@ -988,7 +988,7 @@ z_owned_keyexpr_t z_subscriber_keyexpr(z_subscriber_t sub) { _z_subscription_sptr_t *head = _z_subscription_sptr_list_head(tail); if (head->ptr->_id == lookup) { _z_keyexpr_t key = _z_keyexpr_duplicate(head->ptr->_key); - ret = (z_owned_keyexpr_t){._value = z_malloc(sizeof(_z_keyexpr_t))}; + ret = (z_owned_keyexpr_t){._value = zp_malloc(sizeof(_z_keyexpr_t))}; if (ret._value != NULL) { *ret._value = key; } else { diff --git a/src/collections/bytes.c b/src/collections/bytes.c index d2a8939b0..d4e7a7c00 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 *)z_malloc(capacity); + bs->start = (uint8_t *)zp_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)) { - z_free((uint8_t *)bs->start); + zp_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); - z_free(ptr); + zp_free(ptr); *bs = NULL; } } diff --git a/src/collections/intmap.c b/src/collections/intmap.c index 5abeab4f7..203052b9e 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 **)z_malloc(len); + map->_vals = (_z_list_t **)zp_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 *)z_malloc(sizeof(_z_int_void_map_entry_t)); + _z_int_void_map_entry_t *entry = (_z_int_void_map_entry_t *)zp_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); } - z_free(map->_vals); + zp_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); - z_free(ptr); + zp_free(ptr); *map = NULL; } } diff --git a/src/collections/list.c b/src/collections/list.c index c3d4f8deb..10c18c508 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 *)z_malloc(sizeof(_z_list_t)); + _z_list_t *xs = (_z_list_t *)zp_malloc(sizeof(_z_list_t)); if (xs != NULL) { xs->_val = x; xs->_tail = NULL; @@ -57,7 +57,7 @@ _z_list_t *_z_list_pop(_z_list_t *xs, z_element_free_f f_f, void **x) { } else { f_f(&head->_val); } - z_free(head); + zp_free(head); return l; } @@ -99,7 +99,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); - z_free(this); + zp_free(this); break; } else { previous = current; diff --git a/src/collections/string.c b/src/collections/string.c index 51a19c38b..98d7dda3d 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) { - z_free(str->val); + zp_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); - z_free(ptr); + zp_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 *)z_malloc((len + (size_t)1) * sizeof(char)); + char *s_val = (char *)zp_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) { z_free(src); } +void _z_str_clear(char *src) { zp_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 *)z_malloc(len); + char *dst = (char *)zp_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 *)z_malloc(len * sizeof(char *)); + *val = (char *)zp_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++) { - z_free(sa->val[i]); + zp_free(sa->val[i]); } - z_free(sa->val); + zp_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); - z_free(ptr); + zp_free(ptr); *sa = NULL; } } diff --git a/src/collections/vec.c b/src/collections/vec.c index 20afff6ca..fabd490fb 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 **)z_malloc(sizeof(void *) * capacity); + v._val = (void **)zp_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 **)z_malloc(sizeof(void *) * src->_capacity); + dst->_val = (void **)zp_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]); } - z_free(v->_val); + zp_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); - z_free(ptr); + zp_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 **)z_malloc(_capacity * sizeof(void *)); + void **_val = (void **)zp_malloc(_capacity * sizeof(void *)); if (_val != NULL) { (void)memcpy(_val, v->_val, v->_capacity * sizeof(void *)); // Free the old vector - z_free(v->_val); + zp_free(v->_val); // Update the current vector v->_val = _val; diff --git a/src/link/endpoint.c b/src/link/endpoint.c index 035e646a6..dc44a0b30 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); - z_free(ptr); + zp_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 *)z_malloc(p_len); + ret = (char *)zp_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 *)z_malloc(a_len); + ret = (char *)zp_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 *)z_malloc(len); + char *dst = (char *)zp_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); - z_free(ptr); + zp_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 *)z_malloc(len); + ret = (char *)zp_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 ff63ec689..3ccc27697 100644 --- a/src/link/link.c +++ b/src/link/link.c @@ -126,7 +126,7 @@ void _z_link_free(_z_link_t **l) { if (ptr != NULL) { _z_link_clear(ptr); - z_free(ptr); + zp_free(ptr); *l = NULL; } } diff --git a/src/link/multicast/udp.c b/src/link/multicast/udp.c index dd0cd108b..ea1f4c6b0 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 *)z_malloc(len); + ret = (char *)zp_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 *)z_malloc(len); + ret = (char *)zp_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 *)z_malloc(len); + ret = (char *)zp_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 { - z_free(s_address); + zp_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; } - z_free(s_port); + zp_free(s_port); } } @@ -182,8 +182,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)); - z_free(s_address); - z_free(s_port); + zp_free(s_address); + zp_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 a6cf3de7a..dfec4dd6a 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 *)z_malloc(len); + ret = (char *)zp_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 *)z_malloc(len); + ret = (char *)zp_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 *)z_malloc(len); + ret = (char *)zp_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 { - z_free(s_address); + zp_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; } - z_free(s_port); + zp_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); - z_free(s_address); - z_free(s_port); + zp_free(s_address); + zp_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 2317c1fd4..82ce77d13 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 *)z_malloc(len); + ret = (char *)zp_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 *)z_malloc(len); + ret = (char *)zp_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 *)z_malloc(len); + ret = (char *)zp_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 { - z_free(s_address); + zp_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; } - z_free(s_port); + zp_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); - z_free(s_address); - z_free(s_port); + zp_free(s_address); + zp_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 f59fde872..f67d1aeda 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 *)z_malloc(len); + ret = (char *)zp_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 *)z_malloc(len); + ret = (char *)zp_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 *)z_malloc(len); + ret = (char *)zp_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 { - z_free(s_addr); + zp_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; } - z_free(s_port); + zp_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); - z_free(s_addr); - z_free(s_port); + zp_free(s_addr); + zp_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 7b0457836..58bd252c3 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 *)z_malloc(sizeof(_z_config_t)); + _z_config_t *config = (_z_config_t *)zp_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 1b90e7f55..bbbd53aba 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); - z_free(ptr); + zp_free(ptr); *sample = NULL; } } @@ -61,7 +61,7 @@ void _z_hello_free(_z_hello_t **hello) { if (ptr != NULL) { _z_hello_clear(ptr); - z_free(ptr); + zp_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); - z_free(ptr); + zp_free(ptr); *reply_data = NULL; } } @@ -93,7 +93,7 @@ void _z_value_free(_z_value_t **value) { if (ptr != NULL) { _z_value_clear(ptr); - z_free(ptr); + zp_free(ptr); *value = NULL; } } \ No newline at end of file diff --git a/src/net/primitives.c b/src/net/primitives.c index 1ad25d86a..232cf102b 100644 --- a/src/net/primitives.c +++ b/src/net/primitives.c @@ -100,7 +100,7 @@ int8_t _z_undeclare_resource(_z_session_t *zn, uint16_t rid) { /*------------------ Publisher Declaration ------------------*/ _z_publisher_t *_z_declare_publisher(_z_session_t *zn, _z_keyexpr_t keyexpr, z_congestion_control_t congestion_control, z_priority_t priority) { - _z_publisher_t *ret = (_z_publisher_t *)z_malloc(sizeof(_z_publisher_t)); + _z_publisher_t *ret = (_z_publisher_t *)zp_malloc(sizeof(_z_publisher_t)); if (ret != NULL) { ret->_zn = zn; ret->_key = _z_keyexpr_duplicate(keyexpr); @@ -189,7 +189,7 @@ _z_subscriber_t *_z_declare_subscriber(_z_session_t *zn, _z_keyexpr_t keyexpr, _ s._dropper = dropper; s._arg = arg; - _z_subscriber_t *ret = (_z_subscriber_t *)z_malloc(sizeof(_z_subscriber_t)); + _z_subscriber_t *ret = (_z_subscriber_t *)zp_malloc(sizeof(_z_subscriber_t)); if (ret != NULL) { ret->_zn = zn; ret->_entity_id = s._id; @@ -276,7 +276,7 @@ _z_queryable_t *_z_declare_queryable(_z_session_t *zn, _z_keyexpr_t keyexpr, _Bo q._dropper = dropper; q._arg = arg; - _z_queryable_t *ret = (_z_queryable_t *)z_malloc(sizeof(_z_queryable_t)); + _z_queryable_t *ret = (_z_queryable_t *)zp_malloc(sizeof(_z_queryable_t)); if (ret != NULL) { ret->_zn = zn; ret->_entity_id = q._id; @@ -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 *)z_malloc(sizeof(_z_pending_query_t)); + _z_pending_query_t *pq = (_z_pending_query_t *)zp_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 7b2d1bffc..a17dbc97a 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); - z_free(ptr); + zp_free(ptr); *pub = NULL; } } diff --git a/src/net/query.c b/src/net/query.c index 8b6d71b97..4d626bb54 100644 --- a/src/net/query.c +++ b/src/net/query.c @@ -25,7 +25,7 @@ void _z_queryable_free(_z_queryable_t **qbl) { if (ptr != NULL) { _z_queryable_clear(ptr); - z_free(ptr); + zp_free(ptr); *qbl = NULL; } } diff --git a/src/net/session.c b/src/net/session.c index 29f85f107..4c386e3a3 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 *)z_malloc(sizeof(_z_config_t)); + _z_config_t *ps = (_z_config_t *)zp_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)); @@ -182,7 +182,7 @@ int8_t _zp_send_join(_z_session_t *zn) { return _z_send_join(&zn->_tp); } int8_t _zp_start_read_task(_z_session_t *zn, zp_task_attr_t *attr) { int8_t ret = _Z_RES_OK; // Allocate task - zp_task_t *task = (zp_task_t *)z_malloc(sizeof(zp_task_t)); + zp_task_t *task = (zp_task_t *)zp_malloc(sizeof(zp_task_t)); if (task == NULL) { ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; } @@ -203,7 +203,7 @@ 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) { - z_free(task); + zp_free(task); } return ret; } @@ -211,7 +211,7 @@ int8_t _zp_start_read_task(_z_session_t *zn, zp_task_attr_t *attr) { int8_t _zp_start_lease_task(_z_session_t *zn, zp_task_attr_t *attr) { int8_t ret = _Z_RES_OK; // Allocate task - zp_task_t *task = (zp_task_t *)z_malloc(sizeof(zp_task_t)); + zp_task_t *task = (zp_task_t *)zp_malloc(sizeof(zp_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) { - z_free(task); + zp_free(task); } return ret; } diff --git a/src/net/subscribe.c b/src/net/subscribe.c index 27e2ffe7c..856da6828 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); - z_free(ptr); + zp_free(ptr); *sub = NULL; } } diff --git a/src/protocol/codec.c b/src/protocol/codec.c index 65e13ec07..5320f12b1 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 *)z_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 *)zp_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 e78a94e2a..d43ac03f3 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 = z_malloc(len + 1); + ke->_suffix = zp_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 = z_malloc(len + 1); + ke->_suffix = zp_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 503a887f7..bd47dabb2 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 *)z_malloc(sizeof(_z_msg_ext_t)); + _z_msg_ext_t *ext = (_z_msg_ext_t *)zp_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 = z_malloc(buf.len * 2 + 1); + char *hex = zp_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); - z_free(hex); + zp_free(hex); break; } default: { diff --git a/src/protocol/codec/message.c b/src/protocol/codec/message.c index aebeeacfb..09511df6b 100644 --- a/src/protocol/codec/message.c +++ b/src/protocol/codec/message.c @@ -149,7 +149,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)) - z_free(s); + zp_free(s); } return ret; @@ -171,7 +171,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); - z_free(str); + zp_free(str); } else { a_loc->_len = i; } diff --git a/src/protocol/codec/transport.c b/src/protocol/codec/transport.c index 2e0266447..623b9c42e 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 *)z_malloc(sizeof(_z_network_message_t)); + _z_network_message_t *nm = (_z_network_message_t *)zp_malloc(sizeof(_z_network_message_t)); ret |= _z_network_message_decode(nm, zbf); if (ret == _Z_RES_OK) { _z_network_message_vec_append(&msg->_messages, nm); diff --git a/src/protocol/config.c b/src/protocol/config.c index 3c70a27e6..ffee65656 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 *)z_malloc(p_value_len); + char *p_value = (char *)zp_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 *)z_malloc(len); + char *dst = (char *)zp_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 56855657c..634984ea2 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); - z_free(ptr); + zp_free(ptr); *msg = NULL; } } diff --git a/src/protocol/iobuf.c b/src/protocol/iobuf.c index c5700886f..67802e9fe 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 *)z_malloc(capacity); + ios->_buf = (uint8_t *)zp_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 *)z_malloc(sizeof(_z_iosli_t)); + _z_iosli_t *pios = (_z_iosli_t *)zp_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)) { - z_free(ios->_buf); + zp_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); - z_free(ptr); + zp_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 *)z_malloc(src->_capacity); + dst->_buf = (uint8_t *)zp_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 *)z_malloc(_z_iosli_size(src)); + _z_iosli_t *dst = (_z_iosli_t *)zp_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); - z_free(ptr); + zp_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 *)z_malloc(sizeof(_z_iosli_t)); + _z_iosli_t *ios = (_z_iosli_t *)zp_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); - z_free(ptr); + zp_free(ptr); *wbf = NULL; } } diff --git a/src/protocol/keyexpr.c b/src/protocol/keyexpr.c index 5d52a4377..a33e6645a 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); - z_free(ptr); + zp_free(ptr); *rk = NULL; } } diff --git a/src/session/query.c b/src/session/query.c index a77170f32..e358ef8fd 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 *)z_malloc(sizeof(_z_reply_t)); + _z_reply_t *reply = (_z_reply_t *)zp_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); - z_free(ptr); + zp_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); } - z_free(pen_qry->_call_arg); + zp_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 - z_mutex_lock(&zn->_mutex_inner); + zp_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 - z_mutex_unlock(&zn->_mutex_inner); + zp_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 - z_mutex_lock(&zn->_mutex_inner); + zp_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 - z_mutex_unlock(&zn->_mutex_inner); + zp_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 - z_mutex_lock(&zn->_mutex_inner); + zp_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 *)z_malloc(sizeof(_z_pending_reply_t)); + pen_rep = (_z_pending_reply_t *)zp_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 - z_mutex_unlock(&zn->_mutex_inner); + zp_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 - z_mutex_lock(&zn->_mutex_inner); + zp_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 - z_mutex_unlock(&zn->_mutex_inner); + zp_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 - z_mutex_lock(&zn->_mutex_inner); + zp_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 - z_mutex_unlock(&zn->_mutex_inner); + zp_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 - z_mutex_lock(&zn->_mutex_inner); + zp_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 - z_mutex_unlock(&zn->_mutex_inner); + zp_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 } #endif \ No newline at end of file diff --git a/src/session/queryable.c b/src/session/queryable.c index 34d137aec..e2550c593 100644 --- a/src/session/queryable.c +++ b/src/session/queryable.c @@ -91,13 +91,13 @@ _z_questionable_sptr_list_t *__unsafe_z_get_questionable_by_key(_z_session_t *zn _z_questionable_sptr_t *_z_get_questionable_by_id(_z_session_t *zn, const _z_zint_t id) { #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_lock(&zn->_mutex_inner); + zp_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_questionable_sptr_t *qle = __unsafe_z_get_questionable_by_id(zn, id); #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_unlock(&zn->_mutex_inner); + zp_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 return qle; @@ -105,14 +105,14 @@ _z_questionable_sptr_t *_z_get_questionable_by_id(_z_session_t *zn, const _z_zin _z_questionable_sptr_list_t *_z_get_questionable_by_key(_z_session_t *zn, const _z_keyexpr_t *keyexpr) { #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_lock(&zn->_mutex_inner); + zp_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_questionable_sptr_list_t *qles = __unsafe_z_get_questionable_by_key(zn, key); #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_unlock(&zn->_mutex_inner); + zp_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 return qles; @@ -123,17 +123,17 @@ _z_questionable_sptr_t *_z_register_questionable(_z_session_t *zn, _z_questionab _z_questionable_sptr_t *ret = NULL; #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_lock(&zn->_mutex_inner); + zp_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 - ret = (_z_questionable_sptr_t *)z_malloc(sizeof(_z_questionable_sptr_t)); + ret = (_z_questionable_sptr_t *)zp_malloc(sizeof(_z_questionable_sptr_t)); if (ret != NULL) { *ret = _z_questionable_sptr_new(*q); zn->_local_questionable = _z_questionable_sptr_list_push(zn->_local_questionable, ret); } #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_unlock(&zn->_mutex_inner); + zp_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 return ret; @@ -143,7 +143,7 @@ int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *query, cons int8_t ret = _Z_RES_OK; #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_lock(&zn->_mutex_inner); + zp_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); @@ -151,7 +151,7 @@ int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *query, cons _z_questionable_sptr_list_t *qles = __unsafe_z_get_questionable_by_key(zn, key); #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_unlock(&zn->_mutex_inner); + zp_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 // Build the query @@ -160,7 +160,7 @@ int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *query, cons q._request_id = qid; q._key = key; #if defined(__STDC_NO_VLA__) || ((__STDC_VERSION__ < 201000L) && (defined(_WIN32) || defined(WIN32))) - char *params = z_malloc(query->_parameters.len + 1); + char *params = zp_malloc(query->_parameters.len + 1); #else char params[query->_parameters.len + 1]; #endif @@ -180,7 +180,7 @@ int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *query, cons _z_keyexpr_clear(&key); _z_questionable_sptr_list_free(&qles); #if defined(__STDC_NO_VLA__) || ((__STDC_VERSION__ < 201000L) && (defined(_WIN32) || defined(WIN32))) - z_free(params); + zp_free(params); #endif // Send the final reply @@ -192,7 +192,7 @@ int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *query, cons _z_msg_clear(&z_msg); } else { #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_unlock(&zn->_mutex_inner); + zp_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 ret = _Z_ERR_KEYEXPR_UNKNOWN; @@ -203,26 +203,26 @@ int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *query, cons void _z_unregister_questionable(_z_session_t *zn, _z_questionable_sptr_t *qle) { #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_lock(&zn->_mutex_inner); + zp_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 zn->_local_questionable = _z_questionable_sptr_list_drop_filter(zn->_local_questionable, _z_questionable_sptr_eq, qle); #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_unlock(&zn->_mutex_inner); + zp_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 } void _z_flush_questionables(_z_session_t *zn) { #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_lock(&zn->_mutex_inner); + zp_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_questionable_sptr_list_free(&zn->_local_questionable); #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_unlock(&zn->_mutex_inner); + zp_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 } diff --git a/src/session/resource.c b/src/session/resource.c index f30e26bf6..f5171e240 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); - z_free(ptr); + zp_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 *)z_malloc(len); + rname = (char *)zp_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 - z_mutex_lock(&zn->_mutex_inner); + zp_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 - z_mutex_unlock(&zn->_mutex_inner); + zp_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 - z_mutex_lock(&zn->_mutex_inner); + zp_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 - z_mutex_unlock(&zn->_mutex_inner); + zp_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 - z_mutex_lock(&zn->_mutex_inner); + zp_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 - z_mutex_unlock(&zn->_mutex_inner); + zp_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 - z_mutex_lock(&zn->_mutex_inner); + zp_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 = z_malloc(sizeof(_z_resource_t)); + _z_resource_t *res = zp_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 - z_mutex_unlock(&zn->_mutex_inner); + zp_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 - z_mutex_lock(&zn->_mutex_inner); + zp_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 - z_mutex_unlock(&zn->_mutex_inner); + zp_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 - z_mutex_lock(&zn->_mutex_inner); + zp_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 - z_mutex_unlock(&zn->_mutex_inner); + zp_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 - z_mutex_lock(&zn->_mutex_inner); + zp_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 - z_mutex_unlock(&zn->_mutex_inner); + zp_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 } diff --git a/src/session/scout.c b/src/session/scout.c index b3a8dffb8..0099552d4 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); - z_clock_t start = z_clock_now(); - while (z_clock_elapsed_ms(&start) < period) { + zp_clock_t start = zp_clock_now(); + while (zp_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 *)z_malloc(sizeof(_z_hello_t)); + _z_hello_t *hello = (_z_hello_t *)zp_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 30eff5d2d..64f7025a0 100644 --- a/src/session/subscription.c +++ b/src/session/subscription.c @@ -98,13 +98,13 @@ _z_subscription_sptr_list_t *__unsafe_z_get_subscriptions_by_key(_z_session_t *z _z_subscription_sptr_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 - z_mutex_lock(&zn->_mutex_inner); + zp_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_subscription_sptr_t *sub = __unsafe_z_get_subscription_by_id(zn, is_local, id); #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_unlock(&zn->_mutex_inner); + zp_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 return sub; @@ -112,13 +112,13 @@ _z_subscription_sptr_t *_z_get_subscription_by_id(_z_session_t *zn, uint8_t is_l _z_subscription_sptr_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 - z_mutex_lock(&zn->_mutex_inner); + zp_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_subscription_sptr_list_t *subs = __unsafe_z_get_subscriptions_by_key(zn, is_local, *key); #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_unlock(&zn->_mutex_inner); + zp_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 return subs; @@ -129,12 +129,12 @@ _z_subscription_sptr_t *_z_register_subscription(_z_session_t *zn, uint8_t is_lo _z_subscription_sptr_t *ret = NULL; #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_lock(&zn->_mutex_inner); + zp_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_subscription_sptr_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_sptr_t *)z_malloc(sizeof(_z_subscription_sptr_t)); + ret = (_z_subscription_sptr_t *)zp_malloc(sizeof(_z_subscription_sptr_t)); if (ret != NULL) { *ret = _z_subscription_sptr_new(*s); if (is_local == _Z_RESOURCE_IS_LOCAL) { @@ -146,7 +146,7 @@ _z_subscription_sptr_t *_z_register_subscription(_z_session_t *zn, uint8_t is_lo } #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_unlock(&zn->_mutex_inner); + zp_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 return ret; @@ -157,7 +157,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 - z_mutex_lock(&zn->_mutex_inner); + zp_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)); @@ -167,7 +167,7 @@ int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, co _z_subscription_sptr_list_t *subs = __unsafe_z_get_subscriptions_by_key(zn, _Z_RESOURCE_IS_LOCAL, key); #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_unlock(&zn->_mutex_inner); + zp_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 // Build the sample @@ -189,7 +189,7 @@ int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, co _z_subscription_sptr_list_free(&subs); } else { #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_unlock(&zn->_mutex_inner); + zp_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 ret = _Z_ERR_KEYEXPR_UNKNOWN; } @@ -199,7 +199,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_sptr_t *sub) { #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_lock(&zn->_mutex_inner); + zp_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 if (is_local == _Z_RESOURCE_IS_LOCAL) { @@ -211,20 +211,20 @@ void _z_unregister_subscription(_z_session_t *zn, uint8_t is_local, _z_subscript } #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_unlock(&zn->_mutex_inner); + zp_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 - z_mutex_lock(&zn->_mutex_inner); + zp_mutex_lock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_subscription_sptr_list_free(&zn->_local_subscriptions); _z_subscription_sptr_list_free(&zn->_remote_subscriptions); #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_unlock(&zn->_mutex_inner); + zp_mutex_unlock(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 } #endif \ No newline at end of file diff --git a/src/session/utils.c b/src/session/utils.c index 427ea5072..ea6fc34dc 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; - z_random_fill((uint8_t *)bs->id, size); + zp_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 = z_mutex_init(&zn->_mutex_inner); + ret = zp_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 - z_mutex_free(&zn->_mutex_inner); + zp_mutex_free(&zn->_mutex_inner); #endif // Z_FEATURE_MULTI_THREAD == 1 } @@ -127,7 +127,7 @@ void _z_session_free(_z_session_t **zn) { if (ptr != NULL) { _z_session_clear(ptr); - z_free(ptr); + zp_free(ptr); *zn = NULL; } } diff --git a/src/system/arduino/esp32/network.cpp b/src/system/arduino/esp32/network.cpp index cac67f77b..9ea66ca8d 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) { - z_time_t tv; + zp_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 *)z_malloc(sizeof(struct sockaddr_in)); + lsockaddr = (struct sockaddr *)zp_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 *)z_malloc(sizeof(struct sockaddr_in6)); + lsockaddr = (struct sockaddr *)zp_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) { - z_time_t tv; + zp_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 *)z_malloc(sizeof(struct addrinfo)); + struct addrinfo *laddr = (struct addrinfo *)zp_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) { - z_free(lsockaddr); + zp_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 *)z_malloc(sizeof(struct sockaddr_in)); + lsockaddr = (struct sockaddr *)zp_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 *)z_malloc(sizeof(struct sockaddr_in6)); + lsockaddr = (struct sockaddr *)zp_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) { - z_time_t tv; + zp_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; } - z_free(lsockaddr); + zp_free(lsockaddr); } else { ret = _Z_ERR_GENERIC; } @@ -758,7 +758,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) { - z_sleep_ms(1); // FIXME: Yield by sleeping. + zp_sleep_ms(1); // FIXME: Yield by sleeping. } before_cobs[i] = sock._serial->read(); rb = rb + (size_t)1; @@ -823,7 +823,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 *)z_malloc(_Z_SERIAL_MFS_SIZE); + uint8_t *before_cobs = (uint8_t *)zp_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; @@ -838,7 +838,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 *)z_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); + uint8_t *after_cobs = (uint8_t *)zp_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); @@ -846,8 +846,8 @@ size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t ret = _Z_ERR_GENERIC; } - z_free(before_cobs); - z_free(after_cobs); + zp_free(before_cobs); + zp_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 d54770f42..6fc6f9b68 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 z_random_u8(void) { return z_random_u32(); } +uint8_t zp_random_u8(void) { return zp_random_u32(); } -uint16_t z_random_u16(void) { return z_random_u32(); } +uint16_t zp_random_u16(void) { return zp_random_u32(); } -uint32_t z_random_u32(void) { return esp_random(); } +uint32_t zp_random_u32(void) { return esp_random(); } -uint64_t z_random_u64(void) { +uint64_t zp_random_u64(void) { uint64_t ret = 0; - ret |= z_random_u32(); + ret |= zp_random_u32(); ret = ret << 32; - ret |= z_random_u32(); + ret |= zp_random_u32(); return ret; } -void z_random_fill(void *buf, size_t len) { esp_fill_random(buf, len); } +void zp_random_fill(void *buf, size_t len) { esp_fill_random(buf, len); } /*------------------ Memory ------------------*/ -void *z_malloc(size_t size) { return heap_caps_malloc(size, MALLOC_CAP_8BIT); } +void *zp_malloc(size_t size) { return heap_caps_malloc(size, MALLOC_CAP_8BIT); } -void *z_realloc(void *ptr, size_t size) { return heap_caps_realloc(ptr, size, MALLOC_CAP_8BIT); } +void *zp_realloc(void *ptr, size_t size) { return heap_caps_realloc(ptr, size, MALLOC_CAP_8BIT); } -void z_free(void *ptr) { heap_caps_free(ptr); } +void zp_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); - z_free(targ); + zp_free(targ); } /*------------------ Task ------------------*/ int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), void *arg) { int ret = 0; - z_task_arg *z_arg = (z_task_arg *)z_malloc(sizeof(z_task_arg)); + z_task_arg *z_arg = (z_task_arg *)zp_malloc(sizeof(z_task_arg)); if (z_arg != NULL) { z_arg->_fun = fun; z_arg->_arg = arg; @@ -89,74 +89,74 @@ int8_t zp_task_cancel(zp_task_t *task) { void zp_task_free(zp_task_t **task) { zp_task_t *ptr = *task; - z_free(ptr); + zp_free(ptr); *task = NULL; } /*------------------ Mutex ------------------*/ -int8_t z_mutex_init(zp_mutex_t *m) { return pthread_mutex_init(m, NULL); } +int8_t zp_mutex_init(zp_mutex_t *m) { return pthread_mutex_init(m, NULL); } -int8_t z_mutex_free(zp_mutex_t *m) { return pthread_mutex_destroy(m); } +int8_t zp_mutex_free(zp_mutex_t *m) { return pthread_mutex_destroy(m); } -int8_t z_mutex_lock(zp_mutex_t *m) { return pthread_mutex_lock(m); } +int8_t zp_mutex_lock(zp_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_unlock(zp_mutex_t *m) { return pthread_mutex_unlock(m); } +int8_t zp_mutex_unlock(zp_mutex_t *m) { return pthread_mutex_unlock(m); } /*------------------ Condvar ------------------*/ -int8_t z_condvar_init(zp_condvar_t *cv) { return pthread_cond_init(cv, NULL); } +int8_t zp_condvar_init(zp_condvar_t *cv) { return pthread_cond_init(cv, NULL); } -int8_t z_condvar_free(zp_condvar_t *cv) { return pthread_cond_destroy(cv); } +int8_t zp_condvar_free(zp_condvar_t *cv) { return pthread_cond_destroy(cv); } -int8_t z_condvar_signal(zp_condvar_t *cv) { return pthread_cond_signal(cv); } +int8_t zp_condvar_signal(zp_condvar_t *cv) { return pthread_cond_signal(cv); } -int8_t z_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return pthread_cond_wait(cv, m); } +int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return pthread_cond_wait(cv, m); } #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ -int z_sleep_us(size_t time) { return usleep(time); } +int zp_sleep_us(size_t time) { return usleep(time); } -int z_sleep_ms(size_t time) { - z_time_t start = z_time_now(); +int zp_sleep_ms(size_t time) { + zp_time_t start = zp_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 (z_time_elapsed_ms(&start) < time) { - z_sleep_us(1000); + while (zp_time_elapsed_ms(&start) < time) { + zp_sleep_us(1000); } return 0; } -int z_sleep_s(size_t time) { return sleep(time); } +int zp_sleep_s(size_t time) { return sleep(time); } /*------------------ Instant ------------------*/ -z_clock_t z_clock_now(void) { - z_clock_t now; +zp_clock_t zp_clock_now(void) { + zp_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); return now; } -unsigned long z_clock_elapsed_us(z_clock_t *instant) { - z_clock_t now; +unsigned long zp_clock_elapsed_us(zp_clock_t *instant) { + zp_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 z_clock_elapsed_ms(z_clock_t *instant) { - z_clock_t now; +unsigned long zp_clock_elapsed_ms(zp_clock_t *instant) { + zp_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 z_clock_elapsed_s(z_clock_t *instant) { - z_clock_t now; +unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { + zp_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = now.tv_sec - instant->tv_sec; @@ -164,38 +164,38 @@ unsigned long z_clock_elapsed_s(z_clock_t *instant) { } /*------------------ Time ------------------*/ -z_time_t z_time_now(void) { - z_time_t now; +zp_time_t zp_time_now(void) { + zp_time_t now; gettimeofday(&now, NULL); return now; } -const char *z_time_now_as_str(char *const buf, unsigned long buflen) { - z_time_t tv = z_time_now(); +const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { + zp_time_t tv = zp_time_now(); struct tm ts; ts = *localtime(&tv.tv_sec); strftime(buf, buflen, "%Y-%m-%dT%H:%M:%SZ", &ts); return buf; } -unsigned long z_time_elapsed_us(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_us(zp_time_t *time) { + zp_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 z_time_elapsed_ms(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_ms(zp_time_t *time) { + zp_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 z_time_elapsed_s(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_s(zp_time_t *time) { + zp_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 2e6b05fef..93612bf2e 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 z_random_u8(void) { return random(0xFF); } +uint8_t zp_random_u8(void) { return random(0xFF); } -uint16_t z_random_u16(void) { return random(0xFFFF); } +uint16_t zp_random_u16(void) { return random(0xFFFF); } -uint32_t z_random_u32(void) { return random(0xFFFFFFFF); } +uint32_t zp_random_u32(void) { return random(0xFFFFFFFF); } -uint64_t z_random_u64(void) { +uint64_t zp_random_u64(void) { uint64_t ret = 0; - ret |= z_random_u32(); + ret |= zp_random_u32(); ret = ret << 32; - ret |= z_random_u32(); + ret |= zp_random_u32(); return ret; } -void z_random_fill(void *buf, size_t len) { +void zp_random_fill(void *buf, size_t len) { for (size_t i = 0; i < len; i++) { - ((uint8_t *)buf)[i] = z_random_u8(); + ((uint8_t *)buf)[i] = zp_random_u8(); } } /*------------------ Memory ------------------*/ -void *z_malloc(size_t size) { +void *zp_malloc(size_t size) { // return pvPortMalloc(size); // FIXME: Further investigation is required to understand // why pvPortMalloc or pvPortMallocAligned are failing return malloc(size); } -void *z_realloc(void *ptr, size_t size) { +void *zp_realloc(void *ptr, size_t size) { // Not implemented by the platform return NULL; } -void z_free(void *ptr) { +void zp_free(void *ptr) { // vPortFree(ptr); // FIXME: Further investigation is required to understand // why vPortFree or vPortFreeAligned are failing return free(ptr); @@ -71,125 +71,125 @@ int8_t zp_task_cancel(zp_task_t *task) { return -1; } void zp_task_free(zp_task_t **task) { zp_task_t *ptr = *task; - z_free(ptr); + zp_free(ptr); *task = NULL; } /*------------------ Mutex ------------------*/ -int8_t z_mutex_init(zp_mutex_t *m) { return -1; } +int8_t zp_mutex_init(zp_mutex_t *m) { return -1; } -int8_t z_mutex_free(zp_mutex_t *m) { return -1; } +int8_t zp_mutex_free(zp_mutex_t *m) { return -1; } -int8_t z_mutex_lock(zp_mutex_t *m) { return -1; } +int8_t zp_mutex_lock(zp_mutex_t *m) { return -1; } int8_t zp_mutex_trylock(zp_mutex_t *m) { return -1; } -int8_t z_mutex_unlock(zp_mutex_t *m) { return -1; } +int8_t zp_mutex_unlock(zp_mutex_t *m) { return -1; } /*------------------ Condvar ------------------*/ -int8_t z_condvar_init(zp_condvar_t *cv) { return -1; } +int8_t zp_condvar_init(zp_condvar_t *cv) { return -1; } -int8_t z_condvar_free(zp_condvar_t *cv) { return -1; } +int8_t zp_condvar_free(zp_condvar_t *cv) { return -1; } -int8_t z_condvar_signal(zp_condvar_t *cv) { return -1; } +int8_t zp_condvar_signal(zp_condvar_t *cv) { return -1; } -int8_t z_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return -1; } +int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return -1; } #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ -int z_sleep_us(size_t time) { +int zp_sleep_us(size_t time) { delay_us(time); return 0; } -int z_sleep_ms(size_t time) { +int zp_sleep_ms(size_t time) { delay_ms(time); return 0; } -int z_sleep_s(size_t time) { - z_time_t start = z_time_now(); +int zp_sleep_s(size_t time) { + zp_time_t start = zp_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 (z_time_elapsed_s(&start) < time) { - z_sleep_ms(1000); + while (zp_time_elapsed_s(&start) < time) { + zp_sleep_ms(1000); } return 0; } /*------------------ Instant ------------------*/ -void __z_clock_gettime(z_clock_t *ts) { +void __zp_clock_gettime(zp_clock_t *ts) { uint64_t m = millis(); ts->tv_sec = m / (uint64_t)1000000; ts->tv_nsec = (m % (uint64_t)1000000) * (uint64_t)1000; } -z_clock_t z_clock_now(void) { - z_clock_t now; - __z_clock_gettime(&now); +zp_clock_t zp_clock_now(void) { + zp_clock_t now; + __zp_clock_gettime(&now); return now; } -unsigned long z_clock_elapsed_us(z_clock_t *instant) { - z_clock_t now; - __z_clock_gettime(&now); +unsigned long zp_clock_elapsed_us(zp_clock_t *instant) { + zp_clock_t now; + __zp_clock_gettime(&now); unsigned long elapsed = (1000000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000); return elapsed; } -unsigned long z_clock_elapsed_ms(z_clock_t *instant) { - z_clock_t now; - __z_clock_gettime(&now); +unsigned long zp_clock_elapsed_ms(zp_clock_t *instant) { + zp_clock_t now; + __zp_clock_gettime(&now); unsigned long elapsed = (1000 * (now.tv_sec - instant->tv_sec) + (now.tv_nsec - instant->tv_nsec) / 1000000); return elapsed; } -unsigned long z_clock_elapsed_s(z_clock_t *instant) { - z_clock_t now; - __z_clock_gettime(&now); +unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { + zp_clock_t now; + __zp_clock_gettime(&now); unsigned long elapsed = now.tv_sec - instant->tv_sec; return elapsed; } /*------------------ Time ------------------*/ -z_time_t z_time_now(void) { - z_time_t now; +zp_time_t zp_time_now(void) { + zp_time_t now; gettimeofday(&now, NULL); return now; } -const char *z_time_now_as_str(char *const buf, unsigned long buflen) { - z_time_t tv = z_time_now(); +const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { + zp_time_t tv = zp_time_now(); struct tm ts; ts = *localtime(&tv.tv_sec); strftime(buf, buflen, "%Y-%m-%dT%H:%M:%SZ", &ts); return buf; } -unsigned long z_time_elapsed_us(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_us(zp_time_t *time) { + zp_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 z_time_elapsed_ms(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_ms(zp_time_t *time) { + zp_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 z_time_elapsed_s(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_s(zp_time_t *time) { + zp_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 95c0d2f09..262217495 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. - z_sleep_ms(100); + zp_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; - 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 + 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 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; - 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 + 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 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 607aa8823..dc2396575 100644 --- a/src/system/emscripten/system.c +++ b/src/system/emscripten/system.c @@ -21,26 +21,26 @@ #include "zenoh-pico/system/platform.h" /*------------------ Random ------------------*/ -uint8_t z_random_u8(void) { return (emscripten_random() * 255.0); } +uint8_t zp_random_u8(void) { return (emscripten_random() * 255.0); } -uint16_t z_random_u16(void) { return (emscripten_random() * 65535.0); } +uint16_t zp_random_u16(void) { return (emscripten_random() * 65535.0); } -uint32_t z_random_u32(void) { return (emscripten_random() * 4294967295.0); } +uint32_t zp_random_u32(void) { return (emscripten_random() * 4294967295.0); } -uint64_t z_random_u64(void) { return (emscripten_random() * 18446744073709551615.0); } +uint64_t zp_random_u64(void) { return (emscripten_random() * 18446744073709551615.0); } -void z_random_fill(void *buf, size_t len) { +void zp_random_fill(void *buf, size_t len) { for (size_t i = 0; i < len; i++) { - *((uint8_t *)buf) = z_random_u8(); + *((uint8_t *)buf) = zp_random_u8(); } } /*------------------ Memory ------------------*/ -void *z_malloc(size_t size) { return malloc(size); } +void *zp_malloc(size_t size) { return malloc(size); } -void *z_realloc(void *ptr, size_t size) { return realloc(ptr, size); } +void *zp_realloc(void *ptr, size_t size) { return realloc(ptr, size); } -void z_free(void *ptr) { free(ptr); } +void zp_free(void *ptr) { free(ptr); } #if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ @@ -54,79 +54,79 @@ int8_t zp_task_cancel(zp_task_t *task) { return pthread_cancel(*task); } void zp_task_free(zp_task_t **task) { zp_task_t *ptr = *task; - z_free(ptr); + zp_free(ptr); *task = NULL; } /*------------------ Mutex ------------------*/ -int8_t z_mutex_init(zp_mutex_t *m) { return pthread_mutex_init(m, 0); } +int8_t zp_mutex_init(zp_mutex_t *m) { return pthread_mutex_init(m, 0); } -int8_t z_mutex_free(zp_mutex_t *m) { return pthread_mutex_destroy(m); } +int8_t zp_mutex_free(zp_mutex_t *m) { return pthread_mutex_destroy(m); } -int8_t z_mutex_lock(zp_mutex_t *m) { return pthread_mutex_lock(m); } +int8_t zp_mutex_lock(zp_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_unlock(zp_mutex_t *m) { return pthread_mutex_unlock(m); } +int8_t zp_mutex_unlock(zp_mutex_t *m) { return pthread_mutex_unlock(m); } /*------------------ Condvar ------------------*/ -int8_t z_condvar_init(zp_condvar_t *cv) { return pthread_cond_init(cv, 0); } +int8_t zp_condvar_init(zp_condvar_t *cv) { return pthread_cond_init(cv, 0); } -int8_t z_condvar_free(zp_condvar_t *cv) { return pthread_cond_destroy(cv); } +int8_t zp_condvar_free(zp_condvar_t *cv) { return pthread_cond_destroy(cv); } -int8_t z_condvar_signal(zp_condvar_t *cv) { return pthread_cond_signal(cv); } +int8_t zp_condvar_signal(zp_condvar_t *cv) { return pthread_cond_signal(cv); } -int8_t z_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return pthread_cond_wait(cv, m); } +int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return pthread_cond_wait(cv, m); } #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ -int z_sleep_us(size_t time) { +int zp_sleep_us(size_t time) { emscripten_sleep((time / 1000) + (time % 1000 == 0 ? 0 : 1)); return 0; } -int z_sleep_ms(size_t time) { +int zp_sleep_ms(size_t time) { emscripten_sleep(time); return 0; } -int z_sleep_s(size_t time) { - z_time_t start = z_time_now(); +int zp_sleep_s(size_t time) { + zp_time_t start = zp_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 (z_time_elapsed_s(&start) < time) { - z_sleep_ms(1000); + while (zp_time_elapsed_s(&start) < time) { + zp_sleep_ms(1000); } return 0; } /*------------------ Instant ------------------*/ -z_clock_t z_clock_now(void) { return z_time_now(); } +zp_clock_t zp_clock_now(void) { return zp_time_now(); } -unsigned long z_clock_elapsed_us(z_clock_t *instant) { return z_clock_elapsed_ms(instant) * 1000; } +unsigned long zp_clock_elapsed_us(zp_clock_t *instant) { return zp_clock_elapsed_ms(instant) * 1000; } -unsigned long z_clock_elapsed_ms(z_clock_t *instant) { return z_time_elapsed_ms(instant); } +unsigned long zp_clock_elapsed_ms(zp_clock_t *instant) { return zp_time_elapsed_ms(instant); } -unsigned long z_clock_elapsed_s(z_clock_t *instant) { return z_time_elapsed_ms(instant) * 1000; } +unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { return zp_time_elapsed_ms(instant) * 1000; } /*------------------ Time ------------------*/ -z_time_t z_time_now(void) { return emscripten_get_now(); } +zp_time_t zp_time_now(void) { return emscripten_get_now(); } -const char *z_time_now_as_str(char *const buf, unsigned long buflen) { - snprintf(buf, buflen, "%f", z_time_now()); +const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { + snprintf(buf, buflen, "%f", zp_time_now()); return buf; } -unsigned long z_time_elapsed_us(z_time_t *time) { return z_time_elapsed_ms(time) * 1000; } +unsigned long zp_time_elapsed_us(zp_time_t *time) { return zp_time_elapsed_ms(time) * 1000; } -unsigned long z_time_elapsed_ms(z_time_t *time) { - z_time_t now = emscripten_get_now(); +unsigned long zp_time_elapsed_ms(zp_time_t *time) { + zp_time_t now = emscripten_get_now(); unsigned long elapsed = now - *time; return elapsed; } -unsigned long z_time_elapsed_s(z_time_t *time) { return z_time_elapsed_ms(time) * 1000; } +unsigned long zp_time_elapsed_s(zp_time_t *time) { return zp_time_elapsed_ms(time) * 1000; } diff --git a/src/system/espidf/network.c b/src/system/espidf/network.c index ad40e5078..803264a72 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) { - z_time_t tv; + zp_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 *)z_malloc(sizeof(struct sockaddr_in)); + lsockaddr = (struct sockaddr *)zp_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 *)z_malloc(sizeof(struct sockaddr_in6)); + lsockaddr = (struct sockaddr *)zp_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) { - z_time_t tv; + zp_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 *)z_malloc(sizeof(struct addrinfo)); + struct addrinfo *laddr = (struct addrinfo *)zp_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) { - z_free(lsockaddr); + zp_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 *)z_malloc(sizeof(struct sockaddr_in)); + lsockaddr = (struct sockaddr *)zp_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 *)z_malloc(sizeof(struct sockaddr_in6)); + lsockaddr = (struct sockaddr *)zp_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) { - z_time_t tv; + zp_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; } - z_free(lsockaddr); + zp_free(lsockaddr); } else { ret = _Z_ERR_GENERIC; } @@ -626,14 +626,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 *)z_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); + uint8_t *before_cobs = (uint8_t *)zp_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) { - z_sleep_ms(10); // FIXME: Yield by sleeping. + zp_sleep_ms(10); // FIXME: Yield by sleeping. } else { break; } @@ -645,7 +645,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 *)z_malloc(_Z_SERIAL_MFS_SIZE); + uint8_t *after_cobs = (uint8_t *)zp_malloc(_Z_SERIAL_MFS_SIZE); size_t trb = _z_cobs_decode(before_cobs, rb, after_cobs); size_t i = 0; @@ -672,8 +672,8 @@ size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) ret = _Z_ERR_GENERIC; } - z_free(before_cobs); - z_free(after_cobs); + zp_free(before_cobs); + zp_free(after_cobs); rb = payload_len; if (ret != _Z_RES_OK) { @@ -701,7 +701,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 *)z_malloc(_Z_SERIAL_MFS_SIZE); + uint8_t *before_cobs = (uint8_t *)zp_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; @@ -716,7 +716,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 *)z_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); + uint8_t *after_cobs = (uint8_t *)zp_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); @@ -724,8 +724,8 @@ size_t _z_send_serial(const _z_sys_net_socket_t sock, const uint8_t *ptr, size_t ret = _Z_ERR_GENERIC; } - z_free(before_cobs); - z_free(after_cobs); + zp_free(before_cobs); + zp_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 82fd5c42c..12633ad2b 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 z_random_u8(void) { return z_random_u32(); } +uint8_t zp_random_u8(void) { return zp_random_u32(); } -uint16_t z_random_u16(void) { return z_random_u32(); } +uint16_t zp_random_u16(void) { return zp_random_u32(); } -uint32_t z_random_u32(void) { return esp_random(); } +uint32_t zp_random_u32(void) { return esp_random(); } -uint64_t z_random_u64(void) { +uint64_t zp_random_u64(void) { uint64_t ret = 0; - ret |= z_random_u32(); + ret |= zp_random_u32(); ret = ret << 32; - ret |= z_random_u32(); + ret |= zp_random_u32(); return ret; } -void z_random_fill(void *buf, size_t len) { esp_fill_random(buf, len); } +void zp_random_fill(void *buf, size_t len) { esp_fill_random(buf, len); } /*------------------ Memory ------------------*/ -void *z_malloc(size_t size) { return heap_caps_malloc(size, MALLOC_CAP_8BIT); } +void *zp_malloc(size_t size) { return heap_caps_malloc(size, MALLOC_CAP_8BIT); } -void *z_realloc(void *ptr, size_t size) { return heap_caps_realloc(ptr, size, MALLOC_CAP_8BIT); } +void *zp_realloc(void *ptr, size_t size) { return heap_caps_realloc(ptr, size, MALLOC_CAP_8BIT); } -void z_free(void *ptr) { heap_caps_free(ptr); } +void zp_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); - z_free(targ); + zp_free(targ); } /*------------------ Task ------------------*/ int8_t zp_task_init(zp_task_t *task, zp_task_attr_t *attr, void *(*fun)(void *), void *arg) { int ret = 0; - z_task_arg *z_arg = (z_task_arg *)z_malloc(sizeof(z_task_arg)); + z_task_arg *z_arg = (z_task_arg *)zp_malloc(sizeof(z_task_arg)); if (z_arg != NULL) { z_arg->_fun = fun; z_arg->_arg = arg; @@ -90,74 +90,74 @@ int8_t zp_task_cancel(zp_task_t *task) { void zp_task_free(zp_task_t **task) { zp_task_t *ptr = *task; - z_free(ptr); + zp_free(ptr); *task = NULL; } /*------------------ Mutex ------------------*/ -int8_t z_mutex_init(zp_mutex_t *m) { return pthread_mutex_init(m, NULL); } +int8_t zp_mutex_init(zp_mutex_t *m) { return pthread_mutex_init(m, NULL); } -int8_t z_mutex_free(zp_mutex_t *m) { return pthread_mutex_destroy(m); } +int8_t zp_mutex_free(zp_mutex_t *m) { return pthread_mutex_destroy(m); } -int8_t z_mutex_lock(zp_mutex_t *m) { return pthread_mutex_lock(m); } +int8_t zp_mutex_lock(zp_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_unlock(zp_mutex_t *m) { return pthread_mutex_unlock(m); } +int8_t zp_mutex_unlock(zp_mutex_t *m) { return pthread_mutex_unlock(m); } /*------------------ Condvar ------------------*/ -int8_t z_condvar_init(zp_condvar_t *cv) { return pthread_cond_init(cv, NULL); } +int8_t zp_condvar_init(zp_condvar_t *cv) { return pthread_cond_init(cv, NULL); } -int8_t z_condvar_free(zp_condvar_t *cv) { return pthread_cond_destroy(cv); } +int8_t zp_condvar_free(zp_condvar_t *cv) { return pthread_cond_destroy(cv); } -int8_t z_condvar_signal(zp_condvar_t *cv) { return pthread_cond_signal(cv); } +int8_t zp_condvar_signal(zp_condvar_t *cv) { return pthread_cond_signal(cv); } -int8_t z_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return pthread_cond_wait(cv, m); } +int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return pthread_cond_wait(cv, m); } #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ -int z_sleep_us(size_t time) { return usleep(time); } +int zp_sleep_us(size_t time) { return usleep(time); } -int z_sleep_ms(size_t time) { - z_time_t start = z_time_now(); +int zp_sleep_ms(size_t time) { + zp_time_t start = zp_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 (z_time_elapsed_ms(&start) < time) { - z_sleep_us(1000); + while (zp_time_elapsed_ms(&start) < time) { + zp_sleep_us(1000); } return 0; } -int z_sleep_s(size_t time) { return sleep(time); } +int zp_sleep_s(size_t time) { return sleep(time); } /*------------------ Instant ------------------*/ -z_clock_t z_clock_now(void) { - z_clock_t now; +zp_clock_t zp_clock_now(void) { + zp_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); return now; } -unsigned long z_clock_elapsed_us(z_clock_t *instant) { - z_clock_t now; +unsigned long zp_clock_elapsed_us(zp_clock_t *instant) { + zp_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 z_clock_elapsed_ms(z_clock_t *instant) { - z_clock_t now; +unsigned long zp_clock_elapsed_ms(zp_clock_t *instant) { + zp_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 z_clock_elapsed_s(z_clock_t *instant) { - z_clock_t now; +unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { + zp_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = now.tv_sec - instant->tv_sec; @@ -165,38 +165,38 @@ unsigned long z_clock_elapsed_s(z_clock_t *instant) { } /*------------------ Time ------------------*/ -z_time_t z_time_now(void) { - z_time_t now; +zp_time_t zp_time_now(void) { + zp_time_t now; gettimeofday(&now, NULL); return now; } -const char *z_time_now_as_str(char *const buf, unsigned long buflen) { - z_time_t tv = z_time_now(); +const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { + zp_time_t tv = zp_time_now(); struct tm ts; ts = *localtime(&tv.tv_sec); strftime(buf, buflen, "%Y-%m-%dT%H:%M:%SZ", &ts); return buf; } -unsigned long z_time_elapsed_us(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_us(zp_time_t *time) { + zp_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 z_time_elapsed_ms(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_ms(zp_time_t *time) { + zp_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 z_time_elapsed_s(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_s(zp_time_t *time) { + zp_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 f9278d3ff..a2d17992a 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 z_random_u8(void) { return z_random_u32(); } +uint8_t zp_random_u8(void) { return zp_random_u32(); } -uint16_t z_random_u16(void) { return z_random_u32(); } +uint16_t zp_random_u16(void) { return zp_random_u32(); } -uint32_t z_random_u32(void) { +uint32_t zp_random_u32(void) { uint32_t ret = 0; xApplicationGetRandomNumber(&ret); return ret; } -uint64_t z_random_u64(void) { +uint64_t zp_random_u64(void) { uint64_t ret = 0; - ret |= z_random_u32(); + ret |= zp_random_u32(); ret = ret << 32; - ret |= z_random_u32(); + ret |= zp_random_u32(); return ret; } -void z_random_fill(void *buf, size_t len) { +void zp_random_fill(void *buf, size_t len) { for (size_t i = 0; i < len; i++) { - *((uint8_t *)buf) = z_random_u8(); + *((uint8_t *)buf) = zp_random_u8(); } } /*------------------ Memory ------------------*/ -void *z_malloc(size_t size) { return pvPortMalloc(size); } +void *zp_malloc(size_t size) { return pvPortMalloc(size); } -void *z_realloc(void *ptr, size_t size) { +void *zp_realloc(void *ptr, size_t size) { // realloc not implemented in FreeRTOS return NULL; } -void z_free(void *ptr) { vPortFree(ptr); } +void zp_free(void *ptr) { vPortFree(ptr); } #if Z_FEATURE_MULTI_THREAD == 1 // In FreeRTOS, tasks created using xTaskCreate must end with vTaskDelete. @@ -86,7 +86,7 @@ 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 *)z_malloc(sizeof(z_task_arg)); + z_task_arg *z_arg = (z_task_arg *)zp_malloc(sizeof(z_task_arg)); if (z_arg == NULL) { return -1; } @@ -130,75 +130,75 @@ int8_t zp_task_cancel(zp_task_t *task) { } void zp_task_free(zp_task_t **task) { - z_free((*task)->join_event); - z_free(*task); + zp_free((*task)->join_event); + zp_free(*task); } /*------------------ Mutex ------------------*/ -int8_t z_mutex_init(zp_mutex_t *m) { +int8_t zp_mutex_init(zp_mutex_t *m) { *m = xSemaphoreCreateRecursiveMutex(); return *m == NULL ? -1 : 0; } -int8_t z_mutex_free(zp_mutex_t *m) { - z_free(*m); +int8_t zp_mutex_free(zp_mutex_t *m) { + zp_free(*m); return 0; } -int8_t z_mutex_lock(zp_mutex_t *m) { return xSemaphoreTakeRecursive(*m, portMAX_DELAY) == pdTRUE ? 0 : -1; } +int8_t zp_mutex_lock(zp_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_unlock(zp_mutex_t *m) { return xSemaphoreGiveRecursive(*m) == pdTRUE ? 0 : -1; } +int8_t zp_mutex_unlock(zp_mutex_t *m) { return xSemaphoreGiveRecursive(*m) == pdTRUE ? 0 : -1; } /*------------------ CondVar ------------------*/ // Condition variables not supported in FreeRTOS -int8_t z_condvar_init(zp_condvar_t *cv) { return -1; } -int8_t z_condvar_free(zp_condvar_t *cv) { return -1; } -int8_t z_condvar_signal(zp_condvar_t *cv) { return -1; } -int8_t z_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return -1; } +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; } #endif // Z_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ -int z_sleep_us(size_t time) { +int zp_sleep_us(size_t time) { vTaskDelay(pdMS_TO_TICKS(time / 1000)); return 0; } -int z_sleep_ms(size_t time) { +int zp_sleep_ms(size_t time) { vTaskDelay(pdMS_TO_TICKS(time)); return 0; } -int z_sleep_s(size_t time) { +int zp_sleep_s(size_t time) { vTaskDelay(pdMS_TO_TICKS(time * 1000)); return 0; } /*------------------ Clock ------------------*/ -z_clock_t z_clock_now(void) { return z_time_now(); } +zp_clock_t zp_clock_now(void) { return zp_time_now(); } -unsigned long z_clock_elapsed_us(z_clock_t *instant) { return z_clock_elapsed_ms(instant) * 1000; } +unsigned long zp_clock_elapsed_us(zp_clock_t *instant) { return zp_clock_elapsed_ms(instant) * 1000; } -unsigned long z_clock_elapsed_ms(z_clock_t *instant) { return z_time_elapsed_ms(instant); } +unsigned long zp_clock_elapsed_ms(zp_clock_t *instant) { return zp_time_elapsed_ms(instant); } -unsigned long z_clock_elapsed_s(z_clock_t *instant) { return z_clock_elapsed_ms(instant) / 1000; } +unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { return zp_clock_elapsed_ms(instant) / 1000; } /*------------------ Time ------------------*/ -z_time_t z_time_now(void) { return xTaskGetTickCount(); } +zp_time_t zp_time_now(void) { return xTaskGetTickCount(); } -const char *z_time_now_as_str(char *const buf, unsigned long buflen) { - snprintf(buf, buflen, "%u", z_time_now()); +const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { + snprintf(buf, buflen, "%u", zp_time_now()); return buf; } -unsigned long z_time_elapsed_us(z_time_t *time) { return z_time_elapsed_ms(time) * 1000; } +unsigned long zp_time_elapsed_us(zp_time_t *time) { return zp_time_elapsed_ms(time) * 1000; } -unsigned long z_time_elapsed_ms(z_time_t *time) { - z_time_t now = z_time_now(); +unsigned long zp_time_elapsed_ms(zp_time_t *time) { + zp_time_t now = zp_time_now(); unsigned long elapsed = (now - *time) * portTICK_PERIOD_MS; return elapsed; } -unsigned long z_time_elapsed_s(z_time_t *time) { return z_time_elapsed_ms(time) / 1000; } +unsigned long zp_time_elapsed_s(zp_time_t *time) { return zp_time_elapsed_ms(time) / 1000; } diff --git a/src/system/mbed/system.cpp b/src/system/mbed/system.cpp index 37df46816..9cb6e1437 100644 --- a/src/system/mbed/system.cpp +++ b/src/system/mbed/system.cpp @@ -22,22 +22,22 @@ extern "C" { #include "zenoh-pico/system/platform.h" /*------------------ Random ------------------*/ -uint8_t z_random_u8(void) { return randLIB_get_8bit(); } +uint8_t zp_random_u8(void) { return randLIB_get_8bit(); } -uint16_t z_random_u16(void) { return randLIB_get_16bit(); } +uint16_t zp_random_u16(void) { return randLIB_get_16bit(); } -uint32_t z_random_u32(void) { return randLIB_get_32bit(); } +uint32_t zp_random_u32(void) { return randLIB_get_32bit(); } -uint64_t z_random_u64(void) { return randLIB_get_64bit(); } +uint64_t zp_random_u64(void) { return randLIB_get_64bit(); } -void z_random_fill(void *buf, size_t len) { randLIB_get_n_bytes_random(buf, len); } +void zp_random_fill(void *buf, size_t len) { randLIB_get_n_bytes_random(buf, len); } /*------------------ Memory ------------------*/ -void *z_malloc(size_t size) { return malloc(size); } +void *zp_malloc(size_t size) { return malloc(size); } -void *z_realloc(void *ptr, size_t size) { return realloc(ptr, size); } +void *zp_realloc(void *ptr, size_t size) { return realloc(ptr, size); } -void z_free(void *ptr) { free(ptr); } +void zp_free(void *ptr) { free(ptr); } #if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ @@ -61,47 +61,47 @@ int8_t zp_task_cancel(zp_task_t *task) { void zp_task_free(zp_task_t **task) { zp_task_t *ptr = *task; - z_free(ptr); + zp_free(ptr); *task = NULL; } /*------------------ Mutex ------------------*/ -int8_t z_mutex_init(zp_mutex_t *m) { +int8_t zp_mutex_init(zp_mutex_t *m) { *m = new Mutex(); return 0; } -int8_t z_mutex_free(zp_mutex_t *m) { +int8_t zp_mutex_free(zp_mutex_t *m) { delete ((Mutex *)*m); return 0; } -int8_t z_mutex_lock(zp_mutex_t *m) { +int8_t zp_mutex_lock(zp_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_unlock(zp_mutex_t *m) { +int8_t zp_mutex_unlock(zp_mutex_t *m) { ((Mutex *)*m)->unlock(); return 0; } /*------------------ Condvar ------------------*/ -int8_t z_condvar_init(zp_condvar_t *cv) { return 0; } +int8_t zp_condvar_init(zp_condvar_t *cv) { return 0; } -int8_t z_condvar_free(zp_condvar_t *cv) { +int8_t zp_condvar_free(zp_condvar_t *cv) { delete ((ConditionVariable *)*cv); return 0; } -int8_t z_condvar_signal(zp_condvar_t *cv) { +int8_t zp_condvar_signal(zp_condvar_t *cv) { ((ConditionVariable *)*cv)->notify_all(); return 0; } -int8_t z_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { +int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { *cv = new ConditionVariable(*((Mutex *)*m)); ((ConditionVariable *)*cv)->wait(); return 0; @@ -109,75 +109,75 @@ int8_t z_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ -int z_sleep_us(size_t time) { +int zp_sleep_us(size_t time) { ThisThread::sleep_for(chrono::milliseconds(((time / 1000) + (time % 1000 == 0 ? 0 : 1)))); return 0; } -int z_sleep_ms(size_t time) { +int zp_sleep_ms(size_t time) { ThisThread::sleep_for(chrono::milliseconds(time)); return 0; } -int z_sleep_s(size_t time) { +int zp_sleep_s(size_t time) { ThisThread::sleep_for(chrono::seconds(time)); return 0; } /*------------------ Instant ------------------*/ -z_clock_t z_clock_now(void) { +zp_clock_t zp_clock_now(void) { // Not supported by default return NULL; } -unsigned long z_clock_elapsed_us(z_clock_t *instant) { +unsigned long zp_clock_elapsed_us(zp_clock_t *instant) { // Not supported by default return -1; } -unsigned long z_clock_elapsed_ms(z_clock_t *instant) { +unsigned long zp_clock_elapsed_ms(zp_clock_t *instant) { // Not supported by default return -1; } -unsigned long z_clock_elapsed_s(z_clock_t *instant) { +unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { // Not supported by default return -1; } /*------------------ Time ------------------*/ -z_time_t z_time_now(void) { - z_time_t now; +zp_time_t zp_time_now(void) { + zp_time_t now; gettimeofday(&now, NULL); return now; } -const char *z_time_now_as_str(char *const buf, unsigned long buflen) { - z_time_t tv = z_time_now(); +const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { + zp_time_t tv = zp_time_now(); struct tm ts; ts = *localtime(&tv.tv_sec); strftime(buf, buflen, "%Y-%m-%dT%H:%M:%SZ", &ts); return buf; } -unsigned long z_time_elapsed_us(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_us(zp_time_t *time) { + zp_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 z_time_elapsed_ms(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_ms(zp_time_t *time) { + zp_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 z_time_elapsed_s(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_s(zp_time_t *time) { + zp_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 b7e899e23..3c03459d2 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) { - z_time_t tv; + zp_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) { - z_time_t tv; + zp_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 *)z_malloc(sizeof(struct sockaddr_in)); + *lsockaddr = (struct sockaddr *)zp_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 *)z_malloc(sizeof(struct sockaddr_in6)); + *lsockaddr = (struct sockaddr *)zp_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) { - z_time_t tv; + zp_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 *)z_malloc(sizeof(struct addrinfo)); + struct addrinfo *laddr = (struct addrinfo *)zp_malloc(sizeof(struct addrinfo)); if (laddr != NULL) { laddr->ai_flags = 0; laddr->ai_family = rep._iptcp->ai_family; @@ -353,7 +353,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) - // z_free(lsockaddr); + // zp_free(lsockaddr); // #endif } else { ret = _Z_ERR_GENERIC; @@ -368,7 +368,7 @@ int8_t _z_open_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpoin } if (ret != _Z_RES_OK) { - z_free(lsockaddr); + zp_free(lsockaddr); } } else { ret = _Z_ERR_GENERIC; @@ -386,7 +386,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) { - z_time_t tv; + zp_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)) { @@ -470,7 +470,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo } } } - z_free(joins); + zp_free(joins); } if (ret != _Z_RES_OK) { @@ -480,7 +480,7 @@ int8_t _z_listen_udp_multicast(_z_sys_net_socket_t *sock, const _z_sys_net_endpo ret = _Z_ERR_GENERIC; } - z_free(lsockaddr); + zp_free(lsockaddr); } else { ret = _Z_ERR_GENERIC; } diff --git a/src/system/unix/system.c b/src/system/unix/system.c index f130769a2..4389a5190 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 z_random_u8(void) { +uint8_t zp_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 = z_random_u32(); + ret = zp_random_u32(); #endif return ret; } -uint16_t z_random_u16(void) { +uint16_t zp_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 = z_random_u32(); + ret = zp_random_u32(); #endif return ret; } -uint32_t z_random_u32(void) { +uint32_t zp_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 z_random_u32(void) { return ret; } -uint64_t z_random_u64(void) { +uint64_t zp_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 |= z_random_u32(); + ret |= zp_random_u32(); ret = ret << 32; - ret |= z_random_u32(); + ret |= zp_random_u32(); #endif return ret; } -void z_random_fill(void *buf, size_t len) { +void zp_random_fill(void *buf, size_t len) { #if defined(ZENOH_LINUX) while (getrandom(buf, len, 0) <= 0) { ZP_ASM_NOP; @@ -93,11 +93,11 @@ void z_random_fill(void *buf, size_t len) { } /*------------------ Memory ------------------*/ -void *z_malloc(size_t size) { return malloc(size); } +void *zp_malloc(size_t size) { return malloc(size); } -void *z_realloc(void *ptr, size_t size) { return realloc(ptr, size); } +void *zp_realloc(void *ptr, size_t size) { return realloc(ptr, size); } -void z_free(void *ptr) { free(ptr); } +void zp_free(void *ptr) { free(ptr); } #if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ @@ -111,74 +111,74 @@ int8_t zp_task_cancel(zp_task_t *task) { return pthread_cancel(*task); } void zp_task_free(zp_task_t **task) { zp_task_t *ptr = *task; - z_free(ptr); + zp_free(ptr); *task = NULL; } /*------------------ Mutex ------------------*/ -int8_t z_mutex_init(zp_mutex_t *m) { return pthread_mutex_init(m, 0); } +int8_t zp_mutex_init(zp_mutex_t *m) { return pthread_mutex_init(m, 0); } -int8_t z_mutex_free(zp_mutex_t *m) { return pthread_mutex_destroy(m); } +int8_t zp_mutex_free(zp_mutex_t *m) { return pthread_mutex_destroy(m); } -int8_t z_mutex_lock(zp_mutex_t *m) { return pthread_mutex_lock(m); } +int8_t zp_mutex_lock(zp_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_unlock(zp_mutex_t *m) { return pthread_mutex_unlock(m); } +int8_t zp_mutex_unlock(zp_mutex_t *m) { return pthread_mutex_unlock(m); } /*------------------ Condvar ------------------*/ -int8_t z_condvar_init(zp_condvar_t *cv) { return pthread_cond_init(cv, 0); } +int8_t zp_condvar_init(zp_condvar_t *cv) { return pthread_cond_init(cv, 0); } -int8_t z_condvar_free(zp_condvar_t *cv) { return pthread_cond_destroy(cv); } +int8_t zp_condvar_free(zp_condvar_t *cv) { return pthread_cond_destroy(cv); } -int8_t z_condvar_signal(zp_condvar_t *cv) { return pthread_cond_signal(cv); } +int8_t zp_condvar_signal(zp_condvar_t *cv) { return pthread_cond_signal(cv); } -int8_t z_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return pthread_cond_wait(cv, m); } +int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return pthread_cond_wait(cv, m); } #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ -int z_sleep_us(size_t time) { return usleep(time); } +int zp_sleep_us(size_t time) { return usleep(time); } -int z_sleep_ms(size_t time) { - z_time_t start = z_time_now(); +int zp_sleep_ms(size_t time) { + zp_time_t start = zp_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 (z_time_elapsed_ms(&start) < time) { - z_sleep_us(1000); + while (zp_time_elapsed_ms(&start) < time) { + zp_sleep_us(1000); } return 0; } -int z_sleep_s(size_t time) { return sleep(time); } +int zp_sleep_s(size_t time) { return sleep(time); } /*------------------ Instant ------------------*/ -z_clock_t z_clock_now(void) { - z_clock_t now; +zp_clock_t zp_clock_now(void) { + zp_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); return now; } -unsigned long z_clock_elapsed_us(z_clock_t *instant) { - z_clock_t now; +unsigned long zp_clock_elapsed_us(zp_clock_t *instant) { + zp_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 z_clock_elapsed_ms(z_clock_t *instant) { - z_clock_t now; +unsigned long zp_clock_elapsed_ms(zp_clock_t *instant) { + zp_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 z_clock_elapsed_s(z_clock_t *instant) { - z_clock_t now; +unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { + zp_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = now.tv_sec - instant->tv_sec; @@ -186,38 +186,38 @@ unsigned long z_clock_elapsed_s(z_clock_t *instant) { } /*------------------ Time ------------------*/ -z_time_t z_time_now(void) { - z_time_t now; +zp_time_t zp_time_now(void) { + zp_time_t now; gettimeofday(&now, NULL); return now; } -const char *z_time_now_as_str(char *const buf, unsigned long buflen) { - z_time_t tv = z_time_now(); +const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { + zp_time_t tv = zp_time_now(); struct tm ts; ts = *localtime(&tv.tv_sec); strftime(buf, buflen, "%Y-%m-%dT%H:%M:%SZ", &ts); return buf; } -unsigned long z_time_elapsed_us(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_us(zp_time_t *time) { + zp_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 z_time_elapsed_ms(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_ms(zp_time_t *time) { + zp_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 z_time_elapsed_s(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_s(zp_time_t *time) { + zp_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 833e43a97..0d10466d6 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) { - z_time_t tv; + zp_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) { - z_time_t tv; + zp_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 *)z_malloc(outBufLen); + IP_ADAPTER_ADDRESSES *l_ifaddr = (IP_ADAPTER_ADDRESSES *)zp_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 *)z_malloc(sizeof(SOCKADDR_IN)); + *lsockaddr = (SOCKADDR *)zp_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 *)z_malloc(sizeof(SOCKADDR_IN6)); + *lsockaddr = (SOCKADDR *)zp_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 } } - z_free(l_ifaddr); + zp_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) { - z_time_t tv; + zp_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 *)z_malloc(sizeof(ADDRINFOA)); + ADDRINFOA *laddr = (ADDRINFOA *)zp_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) - // z_free(lsockaddr); + // zp_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) { - z_free(lsockaddr); + zp_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) { - z_time_t tv; + zp_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; } - z_free(lsockaddr); + zp_free(lsockaddr); } else { ret = _Z_ERR_GENERIC; } diff --git a/src/system/windows/system.c b/src/system/windows/system.c index 87e90bce2..217b815ec 100644 --- a/src/system/windows/system.c +++ b/src/system/windows/system.c @@ -23,40 +23,40 @@ #include "zenoh-pico/utils/result.h" /*------------------ Random ------------------*/ -uint8_t z_random_u8(void) { +uint8_t zp_random_u8(void) { uint8_t ret = 0; - z_random_fill(&ret, sizeof(ret)); + zp_random_fill(&ret, sizeof(ret)); return ret; } -uint16_t z_random_u16(void) { +uint16_t zp_random_u16(void) { uint16_t ret = 0; - z_random_fill(&ret, sizeof(ret)); + zp_random_fill(&ret, sizeof(ret)); return ret; } -uint32_t z_random_u32(void) { +uint32_t zp_random_u32(void) { uint32_t ret = 0; - z_random_fill(&ret, sizeof(ret)); + zp_random_fill(&ret, sizeof(ret)); return ret; } -uint64_t z_random_u64(void) { +uint64_t zp_random_u64(void) { uint64_t ret = 0; - z_random_fill(&ret, sizeof(ret)); + zp_random_fill(&ret, sizeof(ret)); return ret; } -void z_random_fill(void *buf, size_t len) { RtlGenRandom(buf, (unsigned long)len); } +void zp_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 *z_malloc(size_t size) { return malloc(size); } +void *zp_malloc(size_t size) { return malloc(size); } -void *z_realloc(void *ptr, size_t size) { return realloc(ptr, size); } +void *zp_realloc(void *ptr, size_t size) { return realloc(ptr, size); } -void z_free(void *ptr) { free(ptr); } +void zp_free(void *ptr) { free(ptr); } #if Z_FEATURE_MULTI_THREAD == 1 /*------------------ Task ------------------*/ @@ -85,24 +85,24 @@ int8_t zp_task_cancel(zp_task_t *task) { void zp_task_free(zp_task_t **task) { zp_task_t *ptr = *task; CloseHandle(*ptr); - z_free(ptr); + zp_free(ptr); *task = NULL; } /*------------------ Mutex ------------------*/ -int8_t z_mutex_init(zp_mutex_t *m) { +int8_t zp_mutex_init(zp_mutex_t *m) { int8_t ret = _Z_RES_OK; InitializeSRWLock(m); return ret; } -int8_t z_mutex_free(zp_mutex_t *m) { +int8_t zp_mutex_free(zp_mutex_t *m) { (void)(m); int8_t ret = _Z_RES_OK; return ret; } -int8_t z_mutex_lock(zp_mutex_t *m) { +int8_t zp_mutex_lock(zp_mutex_t *m) { int8_t ret = _Z_RES_OK; AcquireSRWLockExclusive(m); return ret; @@ -116,32 +116,32 @@ int8_t zp_mutex_trylock(zp_mutex_t *m) { return ret; } -int8_t z_mutex_unlock(zp_mutex_t *m) { +int8_t zp_mutex_unlock(zp_mutex_t *m) { int8_t ret = _Z_RES_OK; ReleaseSRWLockExclusive(m); return ret; } /*------------------ Condvar ------------------*/ -int8_t z_condvar_init(zp_condvar_t *cv) { +int8_t zp_condvar_init(zp_condvar_t *cv) { int8_t ret = _Z_RES_OK; InitializeConditionVariable(cv); return ret; } -int8_t z_condvar_free(zp_condvar_t *cv) { +int8_t zp_condvar_free(zp_condvar_t *cv) { (void)(cv); int8_t ret = _Z_RES_OK; return ret; } -int8_t z_condvar_signal(zp_condvar_t *cv) { +int8_t zp_condvar_signal(zp_condvar_t *cv) { int8_t ret = _Z_RES_OK; WakeConditionVariable(cv); return ret; } -int8_t z_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { +int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { int8_t ret = _Z_RES_OK; SleepConditionVariableSRW(cv, m, INFINITE, 0); return ret; @@ -149,9 +149,9 @@ int8_t z_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ -int z_sleep_us(size_t time) { return z_sleep_ms((time / 1000) + (time % 1000 == 0 ? 0 : 1)); } +int zp_sleep_us(size_t time) { return zp_sleep_ms((time / 1000) + (time % 1000 == 0 ? 0 : 1)); } -int z_sleep_ms(size_t time) { +int zp_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 z_sleep_ms(size_t time) { return 0; } -int z_sleep_s(size_t time) { - z_time_t start = z_time_now(); +int zp_sleep_s(size_t time) { + zp_time_t start = zp_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 (z_time_elapsed_s(&start) < time) { - z_sleep_ms(1000); + while (zp_time_elapsed_s(&start) < time) { + zp_sleep_ms(1000); } return 0; } /*------------------ Instant ------------------*/ -z_clock_t z_clock_now(void) { - z_clock_t now; +zp_clock_t zp_clock_now(void) { + zp_clock_t now; QueryPerformanceCounter(&now); return now; } -unsigned long z_clock_elapsed_us(z_clock_t *instant) { - z_clock_t now; +unsigned long zp_clock_elapsed_us(zp_clock_t *instant) { + zp_clock_t now; LARGE_INTEGER frequency; QueryPerformanceCounter(&now); QueryPerformanceFrequency(&frequency); // ticks per second @@ -196,8 +196,8 @@ unsigned long z_clock_elapsed_us(z_clock_t *instant) { return (unsigned long)elapsed; } -unsigned long z_clock_elapsed_ms(z_clock_t *instant) { - z_clock_t now; +unsigned long zp_clock_elapsed_ms(zp_clock_t *instant) { + zp_clock_t now; LARGE_INTEGER frequency; QueryPerformanceCounter(&now); QueryPerformanceFrequency(&frequency); // ticks per second @@ -211,8 +211,8 @@ unsigned long z_clock_elapsed_ms(z_clock_t *instant) { return (unsigned long)elapsed; } -unsigned long z_clock_elapsed_s(z_clock_t *instant) { - z_clock_t now; +unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { + zp_clock_t now; LARGE_INTEGER frequency; QueryPerformanceCounter(&now); QueryPerformanceFrequency(&frequency); // ticks per second @@ -226,32 +226,32 @@ unsigned long z_clock_elapsed_s(z_clock_t *instant) { } /*------------------ Time ------------------*/ -z_time_t z_time_now(void) { - z_time_t now; +zp_time_t zp_time_now(void) { + zp_time_t now; ftime(&now); return now; } -const char *z_time_now_as_str(char *const buf, unsigned long buflen) { - z_time_t tv = z_time_now(); +const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { + zp_time_t tv = zp_time_now(); struct tm ts; ts = *localtime(&tv.time); strftime(buf, buflen, "%Y-%m-%dT%H:%M:%SZ", &ts); return buf; } -unsigned long z_time_elapsed_us(z_time_t *time) { return z_time_elapsed_ms(time) * 1000; } +unsigned long zp_time_elapsed_us(zp_time_t *time) { return zp_time_elapsed_ms(time) * 1000; } -unsigned long z_time_elapsed_ms(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_ms(zp_time_t *time) { + zp_time_t now; ftime(&now); unsigned long elapsed = ((unsigned long)(now.time - time->time) * 1000) + (now.millitm - time->millitm); return elapsed; } -unsigned long z_time_elapsed_s(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_s(zp_time_t *time) { + zp_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 91a693e0a..21902deea 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) { - z_time_t tv; + zp_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) { - z_time_t tv; + zp_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 *)z_malloc(sizeof(struct sockaddr_in)); + lsockaddr = (struct sockaddr *)zp_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 *)z_malloc(sizeof(struct sockaddr_in6)); + lsockaddr = (struct sockaddr *)zp_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) { - z_time_t tv; + zp_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 *)z_malloc(sizeof(struct addrinfo)); + struct addrinfo *laddr = (struct addrinfo *)zp_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) { - z_free(lsockaddr); + zp_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 *)z_malloc(sizeof(struct sockaddr_in)); + lsockaddr = (struct sockaddr *)zp_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 *)z_malloc(sizeof(struct sockaddr_in6)); + lsockaddr = (struct sockaddr *)zp_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; } - z_time_t tv; + zp_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 } } - z_free(lsockaddr); + zp_free(lsockaddr); } else { ret = _Z_ERR_GENERIC; } @@ -618,7 +618,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 *)z_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); + uint8_t *before_cobs = (uint8_t *)zp_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; @@ -632,7 +632,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 *)z_malloc(_Z_SERIAL_MFS_SIZE); + uint8_t *after_cobs = (uint8_t *)zp_malloc(_Z_SERIAL_MFS_SIZE); size_t trb = _z_cobs_decode(before_cobs, rb, after_cobs); size_t i = 0; @@ -659,8 +659,8 @@ size_t _z_read_serial(const _z_sys_net_socket_t sock, uint8_t *ptr, size_t len) ret = _Z_ERR_GENERIC; } - z_free(before_cobs); - z_free(after_cobs); + zp_free(before_cobs); + zp_free(after_cobs); rb = payload_len; if (ret != _Z_RES_OK) { @@ -691,7 +691,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 *)z_malloc(_Z_SERIAL_MFS_SIZE); + uint8_t *before_cobs = (uint8_t *)zp_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; @@ -706,15 +706,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 *)z_malloc(_Z_SERIAL_MAX_COBS_BUF_SIZE); + uint8_t *after_cobs = (uint8_t *)zp_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]); } - z_free(before_cobs); - z_free(after_cobs); + zp_free(before_cobs); + zp_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 4b42103b7..3d1b0b9d5 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 z_random_u8(void) { return z_random_u32(); } +uint8_t zp_random_u8(void) { return zp_random_u32(); } -uint16_t z_random_u16(void) { return z_random_u32(); } +uint16_t zp_random_u16(void) { return zp_random_u32(); } -uint32_t z_random_u32(void) { return sys_rand32_get(); } +uint32_t zp_random_u32(void) { return sys_rand32_get(); } -uint64_t z_random_u64(void) { +uint64_t zp_random_u64(void) { uint64_t ret = 0; - ret |= z_random_u32(); + ret |= zp_random_u32(); ret = ret << 32; - ret |= z_random_u32(); + ret |= zp_random_u32(); return ret; } -void z_random_fill(void *buf, size_t len) { sys_rand_get(buf, len); } +void zp_random_fill(void *buf, size_t len) { sys_rand_get(buf, len); } /*------------------ Memory ------------------*/ -void *z_malloc(size_t size) { return k_malloc(size); } +void *zp_malloc(size_t size) { return k_malloc(size); } -void *z_realloc(void *ptr, size_t size) { +void *zp_realloc(void *ptr, size_t size) { // k_realloc not implemented in Zephyr return NULL; } -void z_free(void *ptr) { k_free(ptr); } +void zp_free(void *ptr) { k_free(ptr); } #if Z_FEATURE_MULTI_THREAD == 1 @@ -89,33 +89,33 @@ int8_t zp_task_cancel(zp_task_t *task) { return pthread_cancel(*task); } void zp_task_free(zp_task_t **task) { zp_task_t *ptr = *task; - z_free(ptr); + zp_free(ptr); *task = NULL; } /*------------------ Mutex ------------------*/ -int8_t z_mutex_init(zp_mutex_t *m) { return pthread_mutex_init(m, 0); } +int8_t zp_mutex_init(zp_mutex_t *m) { return pthread_mutex_init(m, 0); } -int8_t z_mutex_free(zp_mutex_t *m) { return pthread_mutex_destroy(m); } +int8_t zp_mutex_free(zp_mutex_t *m) { return pthread_mutex_destroy(m); } -int8_t z_mutex_lock(zp_mutex_t *m) { return pthread_mutex_lock(m); } +int8_t zp_mutex_lock(zp_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_unlock(zp_mutex_t *m) { return pthread_mutex_unlock(m); } +int8_t zp_mutex_unlock(zp_mutex_t *m) { return pthread_mutex_unlock(m); } /*------------------ Condvar ------------------*/ -int8_t z_condvar_init(zp_condvar_t *cv) { return pthread_cond_init(cv, 0); } +int8_t zp_condvar_init(zp_condvar_t *cv) { return pthread_cond_init(cv, 0); } -int8_t z_condvar_free(zp_condvar_t *cv) { return pthread_cond_destroy(cv); } +int8_t zp_condvar_free(zp_condvar_t *cv) { return pthread_cond_destroy(cv); } -int8_t z_condvar_signal(zp_condvar_t *cv) { return pthread_cond_signal(cv); } +int8_t zp_condvar_signal(zp_condvar_t *cv) { return pthread_cond_signal(cv); } -int8_t z_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return pthread_cond_wait(cv, m); } +int8_t zp_condvar_wait(zp_condvar_t *cv, zp_mutex_t *m) { return pthread_cond_wait(cv, m); } #endif // Z_FEATURE_MULTI_THREAD == 1 /*------------------ Sleep ------------------*/ -int z_sleep_us(size_t time) { +int zp_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 z_sleep_us(size_t time) { return 0; } -int z_sleep_ms(size_t time) { +int zp_sleep_ms(size_t time) { int32_t rem = time; while (rem > 0) { rem = k_msleep(rem); @@ -138,7 +138,7 @@ int z_sleep_ms(size_t time) { return 0; } -int z_sleep_s(size_t time) { +int zp_sleep_s(size_t time) { int32_t rem = time; while (rem > 0) { rem = k_sleep(K_SECONDS(rem)); @@ -148,30 +148,30 @@ int z_sleep_s(size_t time) { } /*------------------ Instant ------------------*/ -z_clock_t z_clock_now(void) { - z_clock_t now; +zp_clock_t zp_clock_now(void) { + zp_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); return now; } -unsigned long z_clock_elapsed_us(z_clock_t *instant) { - z_clock_t now; +unsigned long zp_clock_elapsed_us(zp_clock_t *instant) { + zp_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 z_clock_elapsed_ms(z_clock_t *instant) { - z_clock_t now; +unsigned long zp_clock_elapsed_ms(zp_clock_t *instant) { + zp_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 z_clock_elapsed_s(z_clock_t *instant) { - z_clock_t now; +unsigned long zp_clock_elapsed_s(zp_clock_t *instant) { + zp_clock_t now; clock_gettime(CLOCK_MONOTONIC, &now); unsigned long elapsed = now.tv_sec - instant->tv_sec; @@ -179,38 +179,38 @@ unsigned long z_clock_elapsed_s(z_clock_t *instant) { } /*------------------ Time ------------------*/ -z_time_t z_time_now(void) { - z_time_t now; +zp_time_t zp_time_now(void) { + zp_time_t now; gettimeofday(&now, NULL); return now; } -const char *z_time_now_as_str(char *const buf, unsigned long buflen) { - z_time_t tv = z_time_now(); +const char *zp_time_now_as_str(char *const buf, unsigned long buflen) { + zp_time_t tv = zp_time_now(); struct tm ts; ts = *localtime(&tv.tv_sec); strftime(buf, buflen, "%Y-%m-%dT%H:%M:%SZ", &ts); return buf; } -unsigned long z_time_elapsed_us(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_us(zp_time_t *time) { + zp_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 z_time_elapsed_ms(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_ms(zp_time_t *time) { + zp_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 z_time_elapsed_s(z_time_t *time) { - z_time_t now; +unsigned long zp_time_elapsed_s(zp_time_t *time) { + zp_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 207ca0875..5c7ef21d6 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) { - z_mutex_lock(&ztm->_mutex_peer); + zp_mutex_lock(&ztm->_mutex_peer); if (next_lease <= 0) { it = ztm->_peers; @@ -158,13 +158,13 @@ void *_zp_multicast_lease_task(void *ztm_arg) { } } - z_mutex_unlock(&ztm->_mutex_peer); + zp_mutex_unlock(&ztm->_mutex_peer); // The keep alive and lease intervals are expressed in milliseconds - z_sleep_ms(interval); + zp_sleep_ms(interval); // Decrement all intervals - z_mutex_lock(&ztm->_mutex_peer); + zp_mutex_lock(&ztm->_mutex_peer); it = ztm->_peers; while (it != NULL) { @@ -176,7 +176,7 @@ void *_zp_multicast_lease_task(void *ztm_arg) { next_keep_alive = next_keep_alive - interval; next_join = next_join - interval; - z_mutex_unlock(&ztm->_mutex_peer); + zp_mutex_unlock(&ztm->_mutex_peer); } return 0; } diff --git a/src/transport/multicast/read.c b/src/transport/multicast/read.c index b09d3d886..830ae11c1 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 - z_mutex_lock(&ztm->_mutex_rx); + zp_mutex_lock(&ztm->_mutex_rx); // Prepare the buffer _z_zbuf_reset(&ztm->_zbuf); @@ -124,7 +124,7 @@ 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); } - z_mutex_unlock(&ztm->_mutex_rx); + zp_mutex_unlock(&ztm->_mutex_rx); return NULL; } diff --git a/src/transport/multicast/rx.c b/src/transport/multicast/rx.c index f8c8c9f77..1d0fc2a75 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 - z_mutex_lock(&ztm->_mutex_rx); + zp_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 - z_mutex_unlock(&ztm->_mutex_rx); + zp_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 - z_mutex_lock(&ztm->_mutex_peer); + zp_mutex_lock(&ztm->_mutex_peer); #endif // Z_FEATURE_MULTI_THREAD == 1 // Mark the session that we have received data from this peer @@ -249,7 +249,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 *)z_malloc(sizeof(_z_transport_peer_entry_t)); + entry = (_z_transport_peer_entry_t *)zp_malloc(sizeof(_z_transport_peer_entry_t)); if (entry != NULL) { entry->_sn_res = _z_sn_max(t_msg->_body._join._seq_num_res); @@ -282,7 +282,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 { - z_free(entry); + zp_free(entry); } } else { ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; @@ -327,7 +327,7 @@ int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_t } #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_unlock(&ztm->_mutex_peer); + zp_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 026d4da10..0ffaa0bb6 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 = z_mutex_init(&ztm->_mutex_tx); + ret = zp_mutex_init(&ztm->_mutex_tx); if (ret == _Z_RES_OK) { - ret = z_mutex_init(&ztm->_mutex_rx); + ret = zp_mutex_init(&ztm->_mutex_rx); if (ret == _Z_RES_OK) { - ret = z_mutex_init(&ztm->_mutex_peer); + ret = zp_mutex_init(&ztm->_mutex_peer); if (ret != _Z_RES_OK) { - z_mutex_free(&ztm->_mutex_tx); - z_mutex_free(&ztm->_mutex_rx); + zp_mutex_free(&ztm->_mutex_tx); + zp_mutex_free(&ztm->_mutex_rx); } } else { - z_mutex_free(&ztm->_mutex_tx); + zp_mutex_free(&ztm->_mutex_tx); } } #endif // Z_FEATURE_MULTI_THREAD == 1 @@ -78,9 +78,9 @@ int8_t _z_multicast_transport_create(_z_transport_t *zt, _z_link_t *zl, ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_free(&ztm->_mutex_tx); - z_mutex_free(&ztm->_mutex_rx); - z_mutex_free(&ztm->_mutex_peer); + zp_mutex_free(&ztm->_mutex_tx); + zp_mutex_free(&ztm->_mutex_rx); + zp_mutex_free(&ztm->_mutex_peer); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_wbuf_clear(&ztm->_wbuf); @@ -123,7 +123,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; - z_random_fill(&initial_sn_tx, sizeof(initial_sn_tx)); + zp_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; @@ -191,9 +191,9 @@ void _z_multicast_transport_clear(_z_transport_t *zt) { zp_task_free(&ztm->_lease_task); } // Clean up the mutexes - z_mutex_free(&ztm->_mutex_tx); - z_mutex_free(&ztm->_mutex_rx); - z_mutex_free(&ztm->_mutex_peer); + zp_mutex_free(&ztm->_mutex_tx); + zp_mutex_free(&ztm->_mutex_rx); + zp_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 116a53aed..637a206f7 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 - z_mutex_lock(&ztm->_mutex_tx); + zp_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 - z_mutex_unlock(&ztm->_mutex_tx); + zp_mutex_unlock(&ztm->_mutex_tx); #endif // Z_FEATURE_MULTI_THREAD == 1 return ret; @@ -82,7 +82,7 @@ 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 - z_mutex_lock(&ztm->_mutex_tx); + zp_mutex_lock(&ztm->_mutex_tx); #endif // Z_FEATURE_MULTI_THREAD == 1 } else { #if Z_FEATURE_MULTI_THREAD == 1 @@ -150,7 +150,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 - z_mutex_unlock(&ztm->_mutex_tx); + zp_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 b38f77154..a2df3da6d 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 *)z_malloc(_ZP_MAC_ADDR_LENGTH); + uint8_t *ret = (uint8_t *)zp_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); - z_free(addr); + zp_free(addr); } else { memcpy(&self->_socket._raweth._smac, _ZP_RAWETH_CFG_SMAC, _ZP_MAC_ADDR_LENGTH); } diff --git a/src/transport/raweth/rx.c b/src/transport/raweth/rx.c index 93dd68b11..162c66c28 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 - z_mutex_lock(&ztm->_mutex_rx); + zp_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 - z_mutex_unlock(&ztm->_mutex_rx); + zp_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 97f827669..4ed64452c 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) { z_mutex_unlock(&ztm->_mutex_tx); } +static void _zp_raweth_unlock_tx_mutex(_z_transport_multicast_t *ztm) { zp_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 - z_mutex_lock(&ztm->_mutex_tx); + zp_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 - z_mutex_unlock(&ztm->_mutex_tx); + zp_mutex_unlock(&ztm->_mutex_tx); #endif return ret; @@ -228,7 +228,7 @@ 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) { - z_mutex_lock(&ztm->_mutex_tx); + zp_mutex_lock(&ztm->_mutex_tx); } else { if (zp_mutex_trylock(&ztm->_mutex_tx) != (int8_t)0) { _Z_INFO("Dropping zenoh message because of congestion control"); @@ -309,7 +309,7 @@ int8_t _z_raweth_send_n_msg(_z_session_t *zn, const _z_network_message_t *n_msg, _z_wbuf_clear(&fbf); } #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_unlock(&ztm->_mutex_tx); + zp_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 a53b7e364..3ced940ca 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); - z_free(ptr); + zp_free(ptr); *zt = NULL; } diff --git a/src/transport/unicast/lease.c b/src/transport/unicast/lease.c index df2d20635..a8d929f63 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 - z_sleep_ms(interval); + zp_sleep_ms(interval); next_lease = next_lease - interval; next_keep_alive = next_keep_alive - interval; diff --git a/src/transport/unicast/read.c b/src/transport/unicast/read.c index fb6c4210d..3b02ff597 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 - z_mutex_lock(&ztu->_mutex_rx); + zp_mutex_lock(&ztu->_mutex_rx); // Prepare the buffer _z_zbuf_reset(&ztu->_zbuf); @@ -117,7 +117,7 @@ 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); } - z_mutex_unlock(&ztu->_mutex_rx); + zp_mutex_unlock(&ztu->_mutex_rx); return NULL; } diff --git a/src/transport/unicast/rx.c b/src/transport/unicast/rx.c index f45c61ca2..1ae4c3f74 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 - z_mutex_lock(&ztu->_mutex_rx); + zp_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 - z_mutex_unlock(&ztu->_mutex_rx); + zp_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 6feb12c3c..b6375a4d7 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 = z_mutex_init(&zt->_transport._unicast._mutex_tx); + ret = zp_mutex_init(&zt->_transport._unicast._mutex_tx); if (ret == _Z_RES_OK) { - ret = z_mutex_init(&zt->_transport._unicast._mutex_rx); + ret = zp_mutex_init(&zt->_transport._unicast._mutex_rx); if (ret != _Z_RES_OK) { - z_mutex_free(&zt->_transport._unicast._mutex_tx); + zp_mutex_free(&zt->_transport._unicast._mutex_tx); } } #endif // Z_FEATURE_MULTI_THREAD == 1 @@ -95,8 +95,8 @@ int8_t _z_unicast_transport_create(_z_transport_t *zt, _z_link_t *zl, _z_transpo ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY; #if Z_FEATURE_MULTI_THREAD == 1 - z_mutex_free(&zt->_transport._unicast._mutex_tx); - z_mutex_free(&zt->_transport._unicast._mutex_rx); + zp_mutex_free(&zt->_transport._unicast._mutex_tx); + zp_mutex_free(&zt->_transport._unicast._mutex_rx); #endif // Z_FEATURE_MULTI_THREAD == 1 _z_wbuf_clear(&zt->_transport._unicast._wbuf); @@ -193,7 +193,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 - z_random_fill(¶m->_initial_sn_tx, sizeof(param->_initial_sn_tx)); + zp_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 @@ -277,8 +277,8 @@ void _z_unicast_transport_clear(_z_transport_t *zt) { } // Clean up the mutexes - z_mutex_free(&ztu->_mutex_tx); - z_mutex_free(&ztu->_mutex_rx); + zp_mutex_free(&ztu->_mutex_tx); + zp_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 7b23557cf..52d52b640 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 - z_mutex_lock(&ztu->_mutex_tx); + zp_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 - z_mutex_unlock(&ztu->_mutex_tx); + zp_mutex_unlock(&ztu->_mutex_tx); #endif // Z_FEATURE_MULTI_THREAD == 1 return ret; @@ -85,7 +85,7 @@ 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 - z_mutex_lock(&ztu->_mutex_tx); + zp_mutex_lock(&ztu->_mutex_tx); #endif // Z_FEATURE_MULTI_THREAD == 1 } else { #if Z_FEATURE_MULTI_THREAD == 1 @@ -159,7 +159,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 - z_mutex_unlock(&ztu->_mutex_tx); + zp_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 dd0be80da..f95fb38e3 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); - z_sleep_ms(_scouting_timeout); + zp_sleep_ms(_scouting_timeout); printf("Ok\n"); - z_sleep_s(SLEEP); + zp_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 1058e5b31..b2975f960 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); - z_sleep_s(SLEEP); + zp_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); - z_sleep_s(SLEEP); + zp_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; } - z_sleep_s(SLEEP); + zp_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; } - z_sleep_s(SLEEP); + zp_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 *)z_malloc(sizeof(z_owned_subscriber_t)); + z_owned_subscriber_t *sub = (z_owned_subscriber_t *)zp_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); } - z_sleep_s(SLEEP); + zp_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 *)z_malloc(sizeof(z_owned_queryable_t)); + z_owned_queryable_t *qle = (z_owned_queryable_t *)zp_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); } - z_sleep_s(SLEEP); + zp_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 *)z_malloc(sizeof(z_owned_publisher_t)); + z_owned_publisher_t *pub = (z_owned_publisher_t *)zp_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); } - z_sleep_s(SLEEP); + zp_sleep_s(SLEEP); // Write data from first session size_t len = MSG_LEN; - uint8_t *payload = (uint8_t *)z_malloc(len); + uint8_t *payload = (uint8_t *)zp_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 - z_clock_t now = z_clock_now(); + zp_clock_t now = zp_clock_now(); unsigned int expected = is_reliable ? total : 1; while (datas < expected) { - assert(z_clock_elapsed_s(&now) < TIMEOUT); + assert(zp_clock_elapsed_s(&now) < TIMEOUT); printf("Waiting for datas... %u/%u\n", datas, expected); - z_sleep_s(SLEEP); + zp_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; - z_sleep_s(SLEEP); + zp_sleep_s(SLEEP); // Write fragment data from first session if (is_reliable) { - z_free((uint8_t *)payload); + zp_free((uint8_t *)payload); len = FRAGMENT_MSG_LEN; - payload = (uint8_t *)z_malloc(len); + payload = (uint8_t *)zp_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 = z_clock_now(); + now = zp_clock_now(); while (datas < total) { - assert(z_clock_elapsed_s(&now) < TIMEOUT); + assert(zp_clock_elapsed_s(&now) < TIMEOUT); printf("Waiting for fragment datas... %u/%u\n", datas, total); - z_sleep_s(SLEEP); + zp_sleep_s(SLEEP); } if (is_reliable == true) { assert(datas == total); } datas = 0; - z_sleep_s(SLEEP); + zp_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 = z_clock_now(); + now = zp_clock_now(); expected = is_reliable ? total : 1; while (queries < expected) { - assert(z_clock_elapsed_s(&now) < TIMEOUT); + assert(zp_clock_elapsed_s(&now) < TIMEOUT); printf("Waiting for queries... %u/%u\n", queries, expected); - z_sleep_s(SLEEP); + zp_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 = z_clock_now(); + now = zp_clock_now(); while (replies < expected) { - assert(z_clock_elapsed_s(&now) < TIMEOUT); + assert(zp_clock_elapsed_s(&now) < TIMEOUT); printf("Waiting for replies... %u/%u\n", replies, expected); - z_sleep_s(SLEEP); + zp_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; - z_sleep_s(SLEEP); + zp_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); } - z_sleep_s(SLEEP); + zp_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); } - z_sleep_s(SLEEP); + zp_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); } - z_sleep_s(SLEEP); + zp_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])); } - z_sleep_s(SLEEP); + zp_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])); } - z_sleep_s(SLEEP); + zp_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)); - z_sleep_s(SLEEP); + zp_sleep_s(SLEEP); printf("Closing session 2\n"); z_close(z_move(s2)); - z_free((uint8_t *)payload); + zp_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 461ee92ca..b877d08ae 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 *)z_malloc(sizeof(_z_transport_peer_entry_t)); + _z_transport_peer_entry_t *entry = (_z_transport_peer_entry_t *)zp_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 *)z_malloc(sizeof(_z_transport_peer_entry_t)); + _z_transport_peer_entry_t *entry = (_z_transport_peer_entry_t *)zp_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 0b490d515..1a49129dc 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 z_random_u8() % 2; } +int gen_bool(void) { return zp_random_u8() % 2; } -uint8_t gen_uint8(void) { return z_random_u8() % 255; } +uint8_t gen_uint8(void) { return zp_random_u8() % 255; } size_t gen_size_t(void) { size_t ret = 0; - z_random_fill(&ret, sizeof(ret)); + zp_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 *)z_malloc(len); + uint8_t *payload = (uint8_t *)zp_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 *)z_malloc(len); + uint8_t *buffer = (uint8_t *)zp_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); - z_free(pios); + zp_free(pios); _z_iosli_clear(cios); - z_free(cios); + zp_free(cios); - z_free(buffer); - z_free(payload); + zp_free(buffer); + zp_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 *)z_malloc(len); + uint8_t *buf01 = (uint8_t *)zp_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"); - z_free(buf01); + zp_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 = z_random_u8() % 128; + size_t len = zp_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 5d20469df..1bc1bdc3a 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 z_random_u8() % 2; } +_Bool gen_bool(void) { return zp_random_u8() % 2; } -uint8_t gen_uint8(void) { return z_random_u8(); } +uint8_t gen_uint8(void) { return zp_random_u8(); } -uint8_t gen_uint16(void) { return z_random_u16(); } +uint8_t gen_uint16(void) { return zp_random_u16(); } uint64_t gen_uint64(void) { uint64_t ret = 0; - z_random_fill(&ret, sizeof(ret)); + zp_random_fill(&ret, sizeof(ret)); return ret; } unsigned int gen_uint(void) { unsigned int ret = 0; - z_random_fill(&ret, sizeof(ret)); + zp_random_fill(&ret, sizeof(ret)); return ret; } _z_zint_t gen_zint(void) { _z_zint_t ret = 0; - z_random_fill(&ret, sizeof(ret)); + zp_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 *)z_malloc(len); - z_random_fill((uint8_t *)pld.start, pld.len); + pld.start = (uint8_t *)zp_malloc(len); + zp_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 *)z_malloc(sizeof(uint8_t) * len); + arr.start = (uint8_t *)zp_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 *)z_malloc(size + 1); + char *str = (char *)zp_malloc(size + 1); for (_z_zint_t i = 0; i < size; i++) { - uint32_t key = z_random_u32() % (sizeof(charset) - 1); + uint32_t key = zp_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(" "); - z_free(ls); - z_free(rs); + zp_free(ls); + zp_free(rs); assert(_z_locator_eq(l, r) == true); } @@ -1659,7 +1659,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 *)z_malloc(sizeof(_z_network_message_t)); + _z_network_message_t *msg = (_z_network_message_t *)zp_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 d29551a0f..17bdb27e2 100644 --- a/tests/z_peer_multicast_test.c +++ b/tests/z_peer_multicast_test.c @@ -82,7 +82,7 @@ int main(int argc, char **argv) { zp_start_read_task(z_loan(s1), NULL); zp_start_lease_task(z_loan(s1), NULL); - z_sleep_s(SLEEP); + zp_sleep_s(SLEEP); config = z_config_default(); zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make("peer")); @@ -99,7 +99,7 @@ int main(int argc, char **argv) { zp_start_read_task(z_loan(s2), NULL); zp_start_lease_task(z_loan(s2), NULL); - z_sleep_s(SLEEP * 5); + zp_sleep_s(SLEEP * 5); // Declare subscribers on second session char *s1_res = (char *)malloc(64); @@ -107,7 +107,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 *)z_malloc(sizeof(z_owned_subscriber_t)); + z_owned_subscriber_t *sub = (z_owned_subscriber_t *)zp_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, @@ -117,7 +117,7 @@ int main(int argc, char **argv) { // Write data from first session size_t len = MSG_LEN; - uint8_t *payload = (uint8_t *)z_malloc(len); + uint8_t *payload = (uint8_t *)zp_malloc(len); memset(payload, 1, MSG_LEN); total = MSG * SET; @@ -133,13 +133,13 @@ int main(int argc, char **argv) { } // Wait to receive all the data - z_time_t now = z_time_now(); + zp_time_t now = zp_time_now(); unsigned int expected = is_reliable ? total : 1; while (datas < expected) { - assert(z_time_elapsed_s(&now) < TIMEOUT); + assert(zp_time_elapsed_s(&now) < TIMEOUT); (void)(now); printf("Waiting for datas... %u/%u\n", datas, expected); - z_sleep_s(SLEEP); + zp_sleep_s(SLEEP); } if (is_reliable == true) assert(datas == expected); @@ -147,7 +147,7 @@ int main(int argc, char **argv) { assert(datas >= expected); datas = 0; - z_sleep_s(SLEEP); + zp_sleep_s(SLEEP); // Undeclare subscribers and queryables on second session while (subs2) { @@ -157,7 +157,7 @@ int main(int argc, char **argv) { subs2 = _z_list_pop(subs2, _z_noop_elem_free, NULL); } - z_sleep_s(SLEEP); + zp_sleep_s(SLEEP); // Stop both sessions printf("Stopping threads on session 1\n"); @@ -172,12 +172,12 @@ int main(int argc, char **argv) { printf("Closing session 1\n"); z_close(z_move(s1)); - z_sleep_s(SLEEP); + zp_sleep_s(SLEEP); printf("Closing session 2\n"); z_close(z_move(s2)); - z_free((uint8_t *)payload); + zp_free((uint8_t *)payload); payload = NULL; free(s1_res); diff --git a/tests/z_perf_rx.c b/tests/z_perf_rx.c index 391bcd231..47ebb5cb0 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; - z_clock_t start; + zp_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 = z_clock_elapsed_ms(&stats->start); + unsigned long elapsed_ms = zp_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 = z_clock_now(); + stats->start = zp_clock_now(); } stats->count++; } @@ -108,7 +108,7 @@ int main(int argc, char **argv) { } // Wait for everything to settle printf("End of test\n"); - z_sleep_s(1); + zp_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 eac90d159..d9e5e7777 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) { - z_clock_t test_start = z_clock_now(); + zp_clock_t test_start = zp_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 = z_clock_elapsed_us(&test_start); + elapsed_us = zp_clock_elapsed_us(&test_start); } return 0; } @@ -82,7 +82,7 @@ int main(int argc, char **argv) { // Wait for joins if (strcmp(mode, "peer") == 0) { printf("Waiting for JOIN messages\n"); - z_sleep_s(3); + zp_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 c24cab42c..c7afabec1 100644 --- a/tests/z_session_test.c +++ b/tests/z_session_test.c @@ -39,7 +39,7 @@ int main(void) { } // Commented out wait for 1 second. Stopping should work without it. - // z_sleep_ms(1000); + // zp_sleep_ms(1000); // Stop read and lease tasks for zenoh-pico zp_stop_read_task(z_loan(s));