Skip to content

Commit

Permalink
Merge pull request #308 from jean-roland/fix_single_thread
Browse files Browse the repository at this point in the history
Restore single thread compilation
  • Loading branch information
p-avital authored Jan 4, 2024
2 parents abd4606 + 65b002c commit 203bae5
Show file tree
Hide file tree
Showing 22 changed files with 375 additions and 190 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,31 @@ jobs:
env:
Z_FEATURE_RAWETH_TRANSPORT: ${{ matrix.feature_reth }}

st_build:
name: Build and test in single thread on ubuntu-latest
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Run docker image
run: docker run --name zenoh_router --init --net host -d eclipse/zenoh:latest

- name: Build project and run test
run: |
sudo apt install -y ninja-build
CMAKE_GENERATOR=Ninja make
python3 ./build/tests/single_thread.py
timeout-minutes: 5
env:
Z_FEATURE_MULTI_THREAD: 0

- name: Stop docker image
if: always()
run: |
docker stop zenoh_router
docker rm zenoh_router
fragment_test:
name: Test multicast and unicast fragmentation
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,20 @@ if (BATCH_UNICAST_SIZE)
endif()

# Zenoh pico feature configuration options
set(Z_FEATURE_MULTI_THREAD 1 CACHE STRING "Toggle multithread feature")
set(Z_FEATURE_PUBLICATION 1 CACHE STRING "Toggle publication feature")
set(Z_FEATURE_SUBSCRIPTION 1 CACHE STRING "Toggle subscription feature")
set(Z_FEATURE_QUERY 1 CACHE STRING "Toggle query feature")
set(Z_FEATURE_QUERYABLE 1 CACHE STRING "Toggle queryable feature")
set(Z_FEATURE_RAWETH_TRANSPORT 0 CACHE STRING "Toggle raw ethernet transport feature")
add_definition(Z_FEATURE_MULTI_THREAD=${Z_FEATURE_MULTI_THREAD})
add_definition(Z_FEATURE_PUBLICATION=${Z_FEATURE_PUBLICATION})
add_definition(Z_FEATURE_SUBSCRIPTION=${Z_FEATURE_SUBSCRIPTION})
add_definition(Z_FEATURE_QUERY=${Z_FEATURE_QUERY})
add_definition(Z_FEATURE_QUERYABLE=${Z_FEATURE_QUERYABLE})
add_definition(Z_FEATURE_RAWETH_TRANSPORT=${Z_FEATURE_RAWETH_TRANSPORT})
message(STATUS "Building with feature confing:\n\
* MULTI-THREAD: ${Z_FEATURE_MULTI_THREAD}\n\
* PUBLICATION: ${Z_FEATURE_PUBLICATION}\n\
* SUBSCRIPTION: ${Z_FEATURE_SUBSCRIPTION}\n\
* QUERY: ${Z_FEATURE_QUERY}\n\
Expand Down Expand Up @@ -328,6 +331,7 @@ if(UNIX OR MSVC)
configure_file(${PROJECT_SOURCE_DIR}/tests/modularity.py ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/modularity.py COPYONLY)
configure_file(${PROJECT_SOURCE_DIR}/tests/raweth.py ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/raweth.py COPYONLY)
configure_file(${PROJECT_SOURCE_DIR}/tests/fragment.py ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/fragment.py COPYONLY)
configure_file(${PROJECT_SOURCE_DIR}/tests/single_thread.py ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/single_thread.py COPYONLY)

enable_testing()
add_test(z_data_struct_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_data_struct_test)
Expand Down
2 changes: 2 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ ZENOH_DEBUG?=0

# Feature config toggle
# Accepted values: 0, 1
Z_FEATURE_MULTI_THREAD?=1
Z_FEATURE_PUBLICATION?=1
Z_FEATURE_SUBSCRIPTION?=1
Z_FEATURE_QUERY?=1
Expand All @@ -67,6 +68,7 @@ CROSSIMG_PREFIX=zenoh-pico_
# - ARM: old versions of dockcross/dockcross were creating some issues since they used an old GCC (4.8.3) which lacks <stdatomic.h> (even using -std=gnu11)

CMAKE_OPT=-DZENOH_DEBUG=$(ZENOH_DEBUG) -DBUILD_EXAMPLES=$(BUILD_EXAMPLES) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_TESTING=$(BUILD_TESTING) -DBUILD_MULTICAST=$(BUILD_MULTICAST)\
-DZ_FEATURE_MULTI_THREAD=$(Z_FEATURE_MULTI_THREAD) \
-DZ_FEATURE_PUBLICATION=$(Z_FEATURE_PUBLICATION) -DZ_FEATURE_SUBSCRIPTION=$(Z_FEATURE_SUBSCRIPTION) -DZ_FEATURE_QUERY=$(Z_FEATURE_QUERY) -DZ_FEATURE_QUERYABLE=$(Z_FEATURE_QUERYABLE)\
-DZ_FEATURE_RAWETH_TRANSPORT=$(Z_FEATURE_RAWETH_TRANSPORT) -DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H.

Expand Down
6 changes: 3 additions & 3 deletions examples/unix/c11/z_ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "zenoh-pico.h"
#include "zenoh-pico/system/platform.h"

#if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1
#if Z_FEATURE_SUBSCRIPTION == 1 && Z_FEATURE_PUBLICATION == 1 && Z_FEATURE_MULTI_THREAD == 1

#define DEFAULT_PKT_SIZE 8
#define DEFAULT_PING_NB 100
Expand Down Expand Up @@ -175,8 +175,8 @@ struct args_t parse_args(int argc, char** argv) {
#else
int main(void) {
printf(
"ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION but this example "
"requires them.\n");
"ERROR: Zenoh pico was compiled without Z_FEATURE_SUBSCRIPTION or Z_FEATURE_PUBLICATION or "
"Z_FEATURE_MULTI_THREAD but this example requires them.\n");
return -2;
}
#endif
4 changes: 2 additions & 2 deletions examples/unix/c11/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ int main(int argc, char **argv) {
n = atoi(optarg);
break;
case '?':
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l' ||
optopt == 'n') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down Expand Up @@ -97,7 +98,6 @@ int main(int argc, char **argv) {
for (int idx = 0; idx < n; ++idx) {
sleep(1);
(void)idx;
// snprintf(buf, 256, "[%4d] %s", idx, value);
printf("Putting Data ('%s': '%s')...\n", keyexpr, value);

z_publisher_put_options_t options = z_publisher_put_options_default();
Expand Down
34 changes: 15 additions & 19 deletions examples/unix/c11/z_pub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
#if Z_FEATURE_PUBLICATION == 1
int main(int argc, char **argv) {
const char *keyexpr = "demo/example/zenoh-pico-pub";
const char *value = "Pub from Pico!";
char *const default_value = "Pub from Pico!";
const char *value = default_value;
const char *mode = "client";
char *clocator = NULL;
char *llocator = NULL;
int n = 10;

int opt;
while ((opt = getopt(argc, argv, "k:v:e:m:l:")) != -1) {
while ((opt = getopt(argc, argv, "k:v:e:m:l:n:")) != -1) {
switch (opt) {
case 'k':
keyexpr = optarg;
Expand All @@ -45,8 +47,12 @@ int main(int argc, char **argv) {
case 'l':
llocator = optarg;
break;
case 'n':
n = atoi(optarg);
break;
case '?':
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm' || optopt == 'l' ||
optopt == 'n') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down Expand Up @@ -79,29 +85,19 @@ int main(int argc, char **argv) {
printf("Unable to declare publisher for key expression!\n");
return -1;
}

char *buf = (char *)malloc(256);
z_clock_t now = z_clock_now();
for (int idx = 0; 1;) {
if (z_clock_elapsed_ms(&now) > 1000) {
snprintf(buf, 256, "[%4d] %s", idx, value);
printf("Putting Data ('%s': '%s')...\n", keyexpr, buf);
z_publisher_put(z_loan(pub), (const uint8_t *)buf, strlen(buf), NULL);
++idx;

now = z_clock_now();
}
// Main loop
for (int idx = 0; idx < n; idx++) {
sleep(1);
(void)idx;
printf("Putting Data ('%s': '%s')...\n", keyexpr, value);
z_publisher_put(z_loan(pub), (const uint8_t *)value, strlen(value), NULL);

zp_read(z_loan(s), NULL);
zp_send_keep_alive(z_loan(s), NULL);
zp_send_join(z_loan(s), NULL);
}

z_undeclare_publisher(z_move(pub));

z_close(z_move(s));

free(buf);
return 0;
}
#else
Expand Down
17 changes: 11 additions & 6 deletions examples/unix/c11/z_sub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,27 @@
#include <zenoh-pico.h>

#if Z_FEATURE_SUBSCRIPTION == 1

static int msg_nb = 0;

void data_handler(const z_sample_t *sample, void *ctx) {
(void)(ctx);
z_owned_str_t keystr = z_keyexpr_to_string(sample->keyexpr);
printf(">> [Subscriber] Received ('%s': '%.*s')\n", z_loan(keystr), (int)sample->payload.len,
sample->payload.start);
z_drop(z_move(keystr));
msg_nb++;
}

int main(int argc, char **argv) {
const char *keyexpr = "demo/example/**";
const char *mode = "client";
char *clocator = NULL;
char *llocator = NULL;
int n = -1;

int opt;
while ((opt = getopt(argc, argv, "k:e:m:l:")) != -1) {
while ((opt = getopt(argc, argv, "k:e:m:l:n:")) != -1) {
switch (opt) {
case 'k':
keyexpr = optarg;
Expand All @@ -49,8 +54,11 @@ int main(int argc, char **argv) {
case 'l':
llocator = optarg;
break;
case 'n':
n = atoi(optarg);
break;
case '?':
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'l') {
if (optopt == 'k' || optopt == 'e' || optopt == 'm' || optopt == 'l' || optopt == 'n') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
} else {
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
Expand Down Expand Up @@ -85,16 +93,13 @@ int main(int argc, char **argv) {
return -1;
}

while (1) {
while (msg_nb != n) {
zp_read(z_loan(s), NULL);
zp_send_keep_alive(z_loan(s), NULL);
zp_send_join(z_loan(s), NULL);
}

z_undeclare_subscriber(z_move(sub));

z_close(z_move(s));

return 0;
}
#else
Expand Down
3 changes: 2 additions & 1 deletion include/zenoh-pico/system/platform/emscripten.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
#ifndef ZENOH_PICO_SYSTEM_WASM_TYPES_H
#define ZENOH_PICO_SYSTEM_WASM_TYPES_H

#include <pthread.h>
#include <stdint.h>

#include "zenoh-pico/config.h"

#if Z_FEATURE_MULTI_THREAD == 1
#include <pthread.h>

typedef pthread_t _z_task_t;
typedef pthread_attr_t _z_task_attr_t;
typedef pthread_mutex_t _z_mutex_t;
Expand Down
3 changes: 2 additions & 1 deletion include/zenoh-pico/system/platform/espidf.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
#include <driver/uart.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <pthread.h>

#include "zenoh-pico/config.h"

#if Z_FEATURE_MULTI_THREAD == 1
#include <pthread.h>

typedef TaskHandle_t _z_task_t;
typedef void *_z_task_attr_t; // Not used in ESP32
typedef pthread_mutex_t _z_mutex_t;
Expand Down
3 changes: 2 additions & 1 deletion include/zenoh-pico/system/platform/unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#ifndef ZENOH_PICO_SYSTEM_UNIX_TYPES_H
#define ZENOH_PICO_SYSTEM_UNIX_TYPES_H

#include <pthread.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
Expand All @@ -24,6 +23,8 @@
#include "zenoh-pico/config.h"

#if Z_FEATURE_MULTI_THREAD == 1
#include <pthread.h>

typedef pthread_t _z_task_t;
typedef pthread_attr_t _z_task_attr_t;
typedef pthread_mutex_t _z_mutex_t;
Expand Down
7 changes: 6 additions & 1 deletion include/zenoh-pico/transport/multicast/lease.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@

int8_t _zp_multicast_send_join(_z_transport_multicast_t *ztm);
int8_t _zp_multicast_send_keep_alive(_z_transport_multicast_t *ztm);
int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, _z_task_attr_t *attr, _z_task_t *task);
int8_t _zp_multicast_stop_lease_task(_z_transport_multicast_t *ztm);
void *_zp_multicast_lease_task(void *ztm_arg); // The argument is void* to avoid incompatible pointer types in tasks

#if Z_FEATURE_MULTI_THREAD == 1 && (Z_FEATURE_MULTICAST_TRANSPORT == 1 || Z_FEATURE_RAWETH_TRANSPORT == 1)
int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, _z_task_attr_t *attr, _z_task_t *task);
#else
int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, void *attr, void *task);
#endif /* Z_FEATURE_MULTI_THREAD == 1 && (Z_FEATURE_MULTICAST_TRANSPORT == 1 || Z_FEATURE_RAWETH_TRANSPORT == 1) */

#endif /* ZENOH_PICO_MULTICAST_LEASE_H */
7 changes: 6 additions & 1 deletion include/zenoh-pico/transport/multicast/read.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
#include "zenoh-pico/transport/transport.h"

int8_t _zp_multicast_read(_z_transport_multicast_t *ztm);
int8_t _zp_multicast_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task);
int8_t _zp_multicast_stop_read_task(_z_transport_t *zt);
void *_zp_multicast_read_task(void *ztm_arg); // The argument is void* to avoid incompatible pointer types in tasks

#if Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_MULTICAST_TRANSPORT == 1
int8_t _zp_multicast_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task);
#else
int8_t _zp_multicast_start_read_task(_z_transport_t *zt, void *attr, void *task);
#endif /* #if Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_MULTICAST_TRANSPORT == 1 */

#endif /* ZENOH_PICO_MULTICAST_READ_H */
7 changes: 6 additions & 1 deletion include/zenoh-pico/transport/raweth/read.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
#include "zenoh-pico/transport/transport.h"

int8_t _zp_raweth_read(_z_transport_multicast_t *ztm);
int8_t _zp_raweth_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task);
int8_t _zp_raweth_stop_read_task(_z_transport_t *zt);
void *_zp_raweth_read_task(void *ztm_arg); // The argument is void* to avoid incompatible pointer types in tasks

#if Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_RAWETH_TRANSPORT == 1
int8_t _zp_raweth_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task);
#else
int8_t _zp_raweth_start_read_task(_z_transport_t *zt, void *attr, void *task);
#endif /* Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_RAWETH_TRANSPORT == 1 */

#endif /* ZENOH_PICO_RAWETH_READ_H */
7 changes: 6 additions & 1 deletion include/zenoh-pico/transport/unicast/lease.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
#include "zenoh-pico/transport/transport.h"

int8_t _zp_unicast_send_keep_alive(_z_transport_unicast_t *ztu);
int8_t _zp_unicast_start_lease_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task);
int8_t _zp_unicast_stop_lease_task(_z_transport_t *zt);
void *_zp_unicast_lease_task(void *ztu_arg); // The argument is void* to avoid incompatible pointer types in tasks

#if Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_UNICAST_TRANSPORT == 1
int8_t _zp_unicast_start_lease_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task);
#else
int8_t _zp_unicast_start_lease_task(_z_transport_t *zt, void *attr, void *task);
#endif /* Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_UNICAST_TRANSPORT == 1 */

#endif /* ZENOH_PICO_TRANSPORT_LINK_TASK_LEASE_H */
7 changes: 6 additions & 1 deletion include/zenoh-pico/transport/unicast/read.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
#include "zenoh-pico/transport/transport.h"

int8_t _zp_unicast_read(_z_transport_unicast_t *ztu);
int8_t _zp_unicast_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task);
int8_t _zp_unicast_stop_read_task(_z_transport_t *zt);
void *_zp_unicast_read_task(void *ztu_arg); // The argument is void* to avoid incompatible pointer types in tasks

#if Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_UNICAST_TRANSPORT == 1
int8_t _zp_unicast_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_task_t *task);
#else
int8_t _zp_unicast_start_read_task(_z_transport_t *zt, void *attr, void *task);
#endif /* Z_FEATURE_MULTI_THREAD == 1 && Z_FEATURE_UNICAST_TRANSPORT == 1 */

#endif /* ZENOH_PICO_UNICAST_READ_H */
1 change: 1 addition & 0 deletions src/system/unix/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#if defined(ZENOH_LINUX)
#include <sys/random.h>
Expand Down
Loading

0 comments on commit 203bae5

Please sign in to comment.