Skip to content

Commit

Permalink
Make all sync mechanisms public (#309)
Browse files Browse the repository at this point in the history
* feat: make all sync mechanisms public

* feat: switch tasks to zp namespace

* feat: switch types to zp namespace

* feat: switch the rest to zp namespace

* feat: add missing end of file new line
  • Loading branch information
jean-roland authored Jan 11, 2024
1 parent c760cca commit d3a631f
Show file tree
Hide file tree
Showing 125 changed files with 1,111 additions and 1,113 deletions.
2 changes: 1 addition & 1 deletion examples/freertos_plus_tcp/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions examples/freertos_plus_tcp/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void app_main(void) {
static StackType_t read_task_stack[1000];
static StaticTask_t read_task_buffer;

_z_task_attr_t read_task_attr = {
zp_task_attr_t read_task_attr = {
.name = "ZenohReadTask",
.priority = 10,
.stack_depth = 1000,
Expand All @@ -62,7 +62,7 @@ void app_main(void) {
static StackType_t lease_task_stack[1000];
static StaticTask_t lease_task_buffer;

_z_task_attr_t lease_task_attr = {
zp_task_attr_t lease_task_attr = {
.name = "ZenohLeaseTask",
.priority = 10,
.stack_depth = 1000,
Expand All @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions examples/freertos_plus_tcp/z_pub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion examples/freertos_plus_tcp/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion examples/freertos_plus_tcp/z_put.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion examples/freertos_plus_tcp/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void app_main(void) {
}

while (1) {
z_sleep_s(5);
zp_sleep_s(5);
}

z_undeclare_queryable(z_move(qable));
Expand Down
2 changes: 1 addition & 1 deletion examples/freertos_plus_tcp/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void app_main(void) {
}

while (1) {
z_sleep_s(5);
zp_sleep_s(5);
}

z_undeclare_subscriber(z_move(sub));
Expand Down
2 changes: 1 addition & 1 deletion examples/mbed/z_get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion examples/mbed/z_pub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion examples/mbed/z_pull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion examples/mbed/z_queryable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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...");
Expand Down
2 changes: 1 addition & 1 deletion examples/mbed/z_sub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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...");
Expand Down
38 changes: 18 additions & 20 deletions examples/unix/c11/z_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,17 @@
#define DEFAULT_PING_NB 100
#define DEFAULT_WARMUP_MS 1000

// WARNING: for the sake of this example we are using "internal" structs and functions (starting with "_").
// Synchronisation primitives are planned to be added to the API in the future.
_z_condvar_t cond;
_z_mutex_t mutex;
static zp_condvar_t cond;
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 {
Expand All @@ -63,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)) {
Expand Down Expand Up @@ -93,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));

Expand Down
12 changes: 6 additions & 6 deletions examples/unix/c11/z_sub_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
36 changes: 18 additions & 18 deletions examples/unix/c99/z_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@
#define DEFAULT_PING_NB 100
#define DEFAULT_WARMUP_MS 1000

_z_condvar_t cond;
_z_mutex_t mutex;
static zp_condvar_t cond;
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 {
Expand All @@ -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)) {
Expand Down Expand Up @@ -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));

Expand Down
6 changes: 3 additions & 3 deletions examples/unix/c99/z_pub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit d3a631f

Please sign in to comment.