From ecea57e39b46b91b1960546f68157ac0b9fe6de5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20Guimar=C3=A3es?= <carlos.em.guimaraes@gmail.com>
Date: Wed, 22 Feb 2023 17:46:00 +0100
Subject: [PATCH 1/7] Surpress compilation of allocation functions if custom
 allocation is configured

---
 include/zenoh-pico/config.h | 4 ++++
 src/system/unix/system.c    | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/include/zenoh-pico/config.h b/include/zenoh-pico/config.h
index 234e66fb3..c45c6c3a7 100644
--- a/include/zenoh-pico/config.h
+++ b/include/zenoh-pico/config.h
@@ -271,4 +271,8 @@
 #endif
 #endif
 
+#ifndef Z_CUSTOM_ALLOCATOR
+#define Z_CUSTOM_ALLOCATOR 0
+#endif
+
 #endif /* ZENOH_PICO_CONFIG_H */
diff --git a/src/system/unix/system.c b/src/system/unix/system.c
index e5dca90e9..cc26734e1 100644
--- a/src/system/unix/system.c
+++ b/src/system/unix/system.c
@@ -92,11 +92,13 @@ void z_random_fill(void *buf, size_t len) {
 }
 
 /*------------------ Memory ------------------*/
+#if Z_CUSTOM_ALLOCATOR == 0
 void *z_malloc(size_t size) { return malloc(size); }
 
 void *z_realloc(void *ptr, size_t size) { return realloc(ptr, size); }
 
 void z_free(void *ptr) { free(ptr); }
+#endif  // Z_CUSTOM_ALLOCATOR
 
 #if Z_MULTI_THREAD == 1
 /*------------------ Task ------------------*/

From 38a4cc9fdab9433958eecbbdb6c9eb02f3a1c1b0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20Guimar=C3=A3es?= <carlos.em.guimaraes@gmail.com>
Date: Wed, 22 Feb 2023 18:49:55 +0100
Subject: [PATCH 2/7] Update build to consider custom allocator builds

---
 .github/workflows/emscripten.yaml |   2 +-
 BSDmakefile                       |   6 +-
 CMakeLists.txt                    | 200 ++++++++++++++++--------------
 GNUmakefile                       |   6 +-
 4 files changed, 120 insertions(+), 94 deletions(-)

diff --git a/.github/workflows/emscripten.yaml b/.github/workflows/emscripten.yaml
index b995749d9..fd545d6dc 100644
--- a/.github/workflows/emscripten.yaml
+++ b/.github/workflows/emscripten.yaml
@@ -34,7 +34,7 @@ jobs:
     - name: Compile debug
       run: |
        mkdir build
-       emcmake cmake -E env CFLAGS="-DZ_LINK_WS=1 -DZ_LINK_TCP=0 -DZ_LINK_UDP_MULTICAST=0 -DZ_LINK_UDP_UNICAST=0 -DZ_SCOUTING_UDP=0" cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_STANDARD=11 -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=OFF -DBUILD_MULTICAST=OFF -DBUILD_INTEGRATION=OFF -DBUILD_TOOLS=OFF -DZENOH_DEBUG=3 -H. -Bbuild
+       emcmake cmake -E env CFLAGS="-DZ_LINK_WS=1 -DZ_LINK_TCP=0 -DZ_LINK_UDP_MULTICAST=0 -DZ_LINK_UDP_UNICAST=0 -DZ_SCOUTING_UDP=0" cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_STANDARD=11 -DBUILD_WITH_CUSTOM_ALLOCATOR=OFF -DBUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=OFF -DBUILD_MULTICAST=OFF -DBUILD_INTEGRATION=OFF -DBUILD_TOOLS=OFF -DZENOH_DEBUG=3 -H. -Bbuild
        make -C build
 
 
diff --git a/BSDmakefile b/BSDmakefile
index 505dabb90..67de9048d 100644
--- a/BSDmakefile
+++ b/BSDmakefile
@@ -21,6 +21,10 @@ BUILD_TYPE?=Release
 # Accepted values: ON, OFF
 BUILD_EXAMPLES?=ON
 
+# Build with custom / user allocators. This sets the BUILD_WITH_CUSTOM_ALLOCATOR variable.
+# Accepted values: ON, OFF
+BUILD_WITH_CUSTOM_ALLOCATOR?=OFF
+
 # Build testing. This sets the BUILD_TESTING variable.
 # Accepted values: ON, OFF
 BUILD_TESTING?=ON
@@ -58,7 +62,7 @@ CROSSIMG_PREFIX=zenoh-pico_
 # NOTES:
 # - 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) -DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H.
+CMAKE_OPT=-DZENOH_DEBUG=$(ZENOH_DEBUG) -DBUILD_EXAMPLES=$(BUILD_EXAMPLES) -DBUILD_WITH_CUSTOM_ALLOCATOR=$(BUILD_WITH_CUSTOM_ALLOCATOR) -D -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_TESTING=$(BUILD_TESTING) -DBUILD_MULTICAST=$(BUILD_MULTICAST) -DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H.
 
 all: make
 
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d22098853..927aae911 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -48,6 +48,9 @@ message(STATUS "Produce Debian and RPM packages: ${PACKAGING}")
 option(BUILD_EXAMPLES "Use this to also build the examples." ON)
 message(STATUS "Build examples: ${BUILD_EXAMPLES}")
 
+option(BUILD_WITH_CUSTOM_ALLOCATOR "Use this build with custom / user allocators." OFF)
+message(STATUS "Build examples with user allocators: ${BUILD_WITH_CUSTOM_ALLOCATOR}")
+
 option(BUILD_TOOLS "Use this to also build the tools." OFF)
 message(STATUS "Build examples: ${BUILD_TOOLS}")
 
@@ -57,6 +60,9 @@ message(STATUS "Build tests: ${BUILD_TESTING}")
 option(BUILD_INTEGRATION "Use this to also build integration tests." OFF)
 message(STATUS "Build integration: ${BUILD_INTEGRATION}")
 
+option(BUILD_MULTICAST "Use this to also build multicast tests." OFF)
+message(STATUS "Build tests: ${BUILD_MULTICAST}")
+
 option(ZENOH_DEBUG "Use this to set the ZENOH_DEBUG variable." 0)
 message(STATUS "Zenoh Level Log: ${ZENOH_DEBUG}")
 
@@ -193,116 +199,128 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/zenoh-pico
   COMPONENT Headers
 )
 
-if(BUILD_EXAMPLES)
+if(BUILD_WITH_CUSTOM_ALLOCATOR)
+  add_definitions(-DZ_CUSTOM_ALLOCATOR=1)
   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples)
 
   if(UNIX)
     if(CMAKE_C_STANDARD MATCHES "99")
-      add_executable(z_put ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_put.c)
-      add_executable(z_pub ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_pub.c)
-      add_executable(z_pub_st ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_pub_st.c)
-      add_executable(z_sub ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_sub.c)
-      add_executable(z_sub_st ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_sub_st.c)
-      add_executable(z_pull ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_pull.c)
-      add_executable(z_get ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_get.c)
-      add_executable(z_queryable ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_queryable.c)
-      add_executable(z_info ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_info.c)
-      add_executable(z_scout ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_scout.c)
     else()
-      add_executable(z_put ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_put.c)
-      add_executable(z_pub ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_pub.c)
-      add_executable(z_pub_st ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_pub_st.c)
-      add_executable(z_sub ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_sub.c)
-      add_executable(z_sub_st ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_sub_st.c)
-      add_executable(z_pull ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_pull.c)
-      add_executable(z_get ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_get.c)
-      add_executable(z_queryable ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_queryable.c)
-      add_executable(z_info ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_info.c)
-      add_executable(z_scout ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_scout.c)
     endif()
-  elseif (MSVC)
-      add_executable(z_put ${PROJECT_SOURCE_DIR}/examples/windows/z_put.c)
-      add_executable(z_pub ${PROJECT_SOURCE_DIR}/examples/windows/z_pub.c)
-      add_executable(z_pub_st ${PROJECT_SOURCE_DIR}/examples/windows/z_pub_st.c)
-      add_executable(z_sub ${PROJECT_SOURCE_DIR}/examples/windows/z_sub.c)
-      add_executable(z_sub_st ${PROJECT_SOURCE_DIR}/examples/windows/z_sub_st.c)
-      add_executable(z_pull ${PROJECT_SOURCE_DIR}/examples/windows/z_pull.c)
-      add_executable(z_get ${PROJECT_SOURCE_DIR}/examples/windows/z_get.c)
-      add_executable(z_queryable ${PROJECT_SOURCE_DIR}/examples/windows/z_queryable.c)
-      add_executable(z_info ${PROJECT_SOURCE_DIR}/examples/windows/z_info.c)
-      add_executable(z_scout ${PROJECT_SOURCE_DIR}/examples/windows/z_scout.c)
+  
   endif()
+else()
+  if(BUILD_EXAMPLES)
+    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples)
+
+    if(UNIX)
+      if(CMAKE_C_STANDARD MATCHES "99")
+        add_executable(z_put ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_put.c)
+        add_executable(z_pub ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_pub.c)
+        add_executable(z_pub_st ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_pub_st.c)
+        add_executable(z_sub ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_sub.c)
+        add_executable(z_sub_st ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_sub_st.c)
+        add_executable(z_pull ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_pull.c)
+        add_executable(z_get ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_get.c)
+        add_executable(z_queryable ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_queryable.c)
+        add_executable(z_info ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_info.c)
+        add_executable(z_scout ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_scout.c)
+      else()
+        add_executable(z_put ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_put.c)
+        add_executable(z_pub ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_pub.c)
+        add_executable(z_pub_st ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_pub_st.c)
+        add_executable(z_sub ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_sub.c)
+        add_executable(z_sub_st ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_sub_st.c)
+        add_executable(z_pull ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_pull.c)
+        add_executable(z_get ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_get.c)
+        add_executable(z_queryable ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_queryable.c)
+        add_executable(z_info ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_info.c)
+        add_executable(z_scout ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_scout.c)
+      endif()
+    elseif (MSVC)
+        add_executable(z_put ${PROJECT_SOURCE_DIR}/examples/windows/z_put.c)
+        add_executable(z_pub ${PROJECT_SOURCE_DIR}/examples/windows/z_pub.c)
+        add_executable(z_pub_st ${PROJECT_SOURCE_DIR}/examples/windows/z_pub_st.c)
+        add_executable(z_sub ${PROJECT_SOURCE_DIR}/examples/windows/z_sub.c)
+        add_executable(z_sub_st ${PROJECT_SOURCE_DIR}/examples/windows/z_sub_st.c)
+        add_executable(z_pull ${PROJECT_SOURCE_DIR}/examples/windows/z_pull.c)
+        add_executable(z_get ${PROJECT_SOURCE_DIR}/examples/windows/z_get.c)
+        add_executable(z_queryable ${PROJECT_SOURCE_DIR}/examples/windows/z_queryable.c)
+        add_executable(z_info ${PROJECT_SOURCE_DIR}/examples/windows/z_info.c)
+        add_executable(z_scout ${PROJECT_SOURCE_DIR}/examples/windows/z_scout.c)
+    endif()
 
-  target_link_libraries(z_put ${Libname})
-  target_link_libraries(z_pub ${Libname})
-  target_link_libraries(z_pub_st ${Libname})
-  target_link_libraries(z_sub ${Libname})
-  target_link_libraries(z_sub_st ${Libname})
-  target_link_libraries(z_pull ${Libname})
-  target_link_libraries(z_get ${Libname})
-  target_link_libraries(z_queryable ${Libname})
-  target_link_libraries(z_info ${Libname})
-  target_link_libraries(z_scout ${Libname})
-endif()
-
-if(BUILD_TOOLS)
-  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tools)
-  add_executable(z_keyexpr_canonizer ${PROJECT_SOURCE_DIR}/tools/z_keyexpr_canonizer.c)
-  target_link_libraries(z_keyexpr_canonizer ${Libname})
-endif()
+    target_link_libraries(z_put ${Libname})
+    target_link_libraries(z_pub ${Libname})
+    target_link_libraries(z_pub_st ${Libname})
+    target_link_libraries(z_sub ${Libname})
+    target_link_libraries(z_sub_st ${Libname})
+    target_link_libraries(z_pull ${Libname})
+    target_link_libraries(z_get ${Libname})
+    target_link_libraries(z_queryable ${Libname})
+    target_link_libraries(z_info ${Libname})
+    target_link_libraries(z_scout ${Libname})
+  endif()
 
-if(BUILD_TESTING)
-  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
-
-  add_executable(z_data_struct_test ${PROJECT_SOURCE_DIR}/tests/z_data_struct_test.c)
-  add_executable(z_endpoint_test ${PROJECT_SOURCE_DIR}/tests/z_endpoint_test.c)
-  add_executable(z_iobuf_test ${PROJECT_SOURCE_DIR}/tests/z_iobuf_test.c)
-  add_executable(z_msgcodec_test ${PROJECT_SOURCE_DIR}/tests/z_msgcodec_test.c)
-  add_executable(z_keyexpr_test ${PROJECT_SOURCE_DIR}/tests/z_keyexpr_test.c)
-
-  target_link_libraries(z_data_struct_test ${Libname})
-  target_link_libraries(z_endpoint_test ${Libname})
-  target_link_libraries(z_iobuf_test ${Libname})
-  target_link_libraries(z_msgcodec_test ${Libname})
-  target_link_libraries(z_keyexpr_test ${Libname})
-
-  enable_testing()
-  add_test(z_data_struct_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_data_struct_test)
-  add_test(z_endpoint_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_endpoint_test)
-  add_test(z_iobuf_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_iobuf_test)
-  add_test(z_msgcodec_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_msgcodec_test)
-  add_test(z_keyexpr_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_keyexpr_test)
-endif()
+  if(BUILD_TOOLS)
+    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tools)
+    add_executable(z_keyexpr_canonizer ${PROJECT_SOURCE_DIR}/tools/z_keyexpr_canonizer.c)
+    target_link_libraries(z_keyexpr_canonizer ${Libname})
+  endif()
 
-if(BUILD_MULTICAST)
-  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
+  if(BUILD_TESTING)
+    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
 
-  if(CMAKE_C_STANDARD MATCHES "11")
-    add_executable(z_peer_multicast_test ${PROJECT_SOURCE_DIR}/tests/z_peer_multicast_test.c)
-    target_link_libraries(z_peer_multicast_test ${Libname})
+    add_executable(z_data_struct_test ${PROJECT_SOURCE_DIR}/tests/z_data_struct_test.c)
+    add_executable(z_endpoint_test ${PROJECT_SOURCE_DIR}/tests/z_endpoint_test.c)
+    add_executable(z_iobuf_test ${PROJECT_SOURCE_DIR}/tests/z_iobuf_test.c)
+    add_executable(z_msgcodec_test ${PROJECT_SOURCE_DIR}/tests/z_msgcodec_test.c)
+    add_executable(z_keyexpr_test ${PROJECT_SOURCE_DIR}/tests/z_keyexpr_test.c)
 
-    configure_file(${PROJECT_SOURCE_DIR}/tests/multicast.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/multicast.sh COPYONLY)
+    target_link_libraries(z_data_struct_test ${Libname})
+    target_link_libraries(z_endpoint_test ${Libname})
+    target_link_libraries(z_iobuf_test ${Libname})
+    target_link_libraries(z_msgcodec_test ${Libname})
+    target_link_libraries(z_keyexpr_test ${Libname})
 
     enable_testing()
-    add_test(z_peer_multicast_test bash ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/multicast.sh z_peer_multicast_test)
+    add_test(z_data_struct_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_data_struct_test)
+    add_test(z_endpoint_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_endpoint_test)
+    add_test(z_iobuf_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_iobuf_test)
+    add_test(z_msgcodec_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_msgcodec_test)
+    add_test(z_keyexpr_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_keyexpr_test)
   endif()
-endif()
 
-if(BUILD_INTEGRATION)
-  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
+  if(BUILD_MULTICAST)
+    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
 
-  if(CMAKE_C_STANDARD MATCHES "11")
-    add_executable(z_client_test ${PROJECT_SOURCE_DIR}/tests/z_client_test.c)
-    add_executable(z_api_alignment_test ${PROJECT_SOURCE_DIR}/tests/z_api_alignment_test.c)
-    target_link_libraries(z_client_test ${Libname})
-    target_link_libraries(z_api_alignment_test ${Libname})
+    if(CMAKE_C_STANDARD MATCHES "11")
+      add_executable(z_peer_multicast_test ${PROJECT_SOURCE_DIR}/tests/z_peer_multicast_test.c)
+      target_link_libraries(z_peer_multicast_test ${Libname})
 
-    configure_file(${PROJECT_SOURCE_DIR}/tests/routed.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/routed.sh COPYONLY)
-    configure_file(${PROJECT_SOURCE_DIR}/tests/api.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/api.sh COPYONLY)
+      configure_file(${PROJECT_SOURCE_DIR}/tests/multicast.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/multicast.sh COPYONLY)
 
-    enable_testing()
-    add_test(z_client_test bash ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/routed.sh z_client_test)
-    add_test(z_api_alignment_test bash ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/api.sh z_api_alignment_test)
+      enable_testing()
+      add_test(z_peer_multicast_test bash ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/multicast.sh z_peer_multicast_test)
+    endif()
+  endif()
+
+  if(BUILD_INTEGRATION)
+    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
+
+    if(CMAKE_C_STANDARD MATCHES "11")
+      add_executable(z_client_test ${PROJECT_SOURCE_DIR}/tests/z_client_test.c)
+      add_executable(z_api_alignment_test ${PROJECT_SOURCE_DIR}/tests/z_api_alignment_test.c)
+      target_link_libraries(z_client_test ${Libname})
+      target_link_libraries(z_api_alignment_test ${Libname})
+
+      configure_file(${PROJECT_SOURCE_DIR}/tests/routed.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/routed.sh COPYONLY)
+      configure_file(${PROJECT_SOURCE_DIR}/tests/api.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/api.sh COPYONLY)
+
+      enable_testing()
+      add_test(z_client_test bash ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/routed.sh z_client_test)
+      add_test(z_api_alignment_test bash ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/api.sh z_api_alignment_test)
+    endif()
   endif()
 endif()
 
diff --git a/GNUmakefile b/GNUmakefile
index 367b18ac3..6f0f0534f 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -21,6 +21,10 @@ BUILD_TYPE?=Release
 # Accepted values: ON, OFF
 BUILD_EXAMPLES?=ON
 
+# Build with custom / user allocators. This sets the BUILD_WITH_CUSTOM_ALLOCATOR variable.
+# Accepted values: ON, OFF
+BUILD_WITH_CUSTOM_ALLOCATOR?=OFF
+
 # Build testing. This sets the BUILD_TESTING variable.
 # Accepted values: ON, OFF
 BUILD_TESTING?=ON
@@ -58,7 +62,7 @@ CROSSIMG_PREFIX=zenoh-pico_
 # NOTES:
 # - 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) -DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H.
+CMAKE_OPT=-DZENOH_DEBUG=$(ZENOH_DEBUG) -DBUILD_EXAMPLES=$(BUILD_EXAMPLES) -DBUILD_WITH_CUSTOM_ALLOCATOR=$(BUILD_WITH_CUSTOM_ALLOCATOR) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DBUILD_TESTING=$(BUILD_TESTING) -DBUILD_MULTICAST=$(BUILD_MULTICAST) -DBUILD_INTEGRATION=$(BUILD_INTEGRATION) -DBUILD_TOOLS=$(BUILD_TOOLS) -DBUILD_SHARED_LIBS=$(BUILD_SHARED_LIBS) -H.
 
 all: make
 

From 423b4817c855e5c734210b60917e02b4e4d42a2d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20Guimar=C3=A3es?= <carlos.em.guimaraes@gmail.com>
Date: Wed, 22 Feb 2023 18:58:08 +0100
Subject: [PATCH 3/7] Add ualloc examples with a first fit strategy

---
 CMakeLists.txt                   |   3 +
 examples/unix/c11/z_pub_ualloc.c | 200 +++++++++++++++++++++++++++++++
 examples/unix/c99/z_pub_ualloc.c | 199 ++++++++++++++++++++++++++++++
 3 files changed, 402 insertions(+)
 create mode 100644 examples/unix/c11/z_pub_ualloc.c
 create mode 100644 examples/unix/c99/z_pub_ualloc.c

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 927aae911..905d656a9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -205,9 +205,12 @@ if(BUILD_WITH_CUSTOM_ALLOCATOR)
 
   if(UNIX)
     if(CMAKE_C_STANDARD MATCHES "99")
+      add_executable(z_pub_ualloc ${PROJECT_SOURCE_DIR}/examples/unix/c99/z_pub_ualloc.c)
     else()
+      add_executable(z_pub_ualloc ${PROJECT_SOURCE_DIR}/examples/unix/c11/z_pub_ualloc.c)
     endif()
   
+    target_link_libraries(z_pub_ualloc ${Libname})
   endif()
 else()
   if(BUILD_EXAMPLES)
diff --git a/examples/unix/c11/z_pub_ualloc.c b/examples/unix/c11/z_pub_ualloc.c
new file mode 100644
index 000000000..1131afeb8
--- /dev/null
+++ b/examples/unix/c11/z_pub_ualloc.c
@@ -0,0 +1,200 @@
+//
+// Copyright (c) 2022 ZettaScale Technology
+//
+// This program and the accompanying materials are made available under the
+// terms of the Eclipse Public License 2.0 which is available at
+// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
+// which is available at https://www.apache.org/licenses/LICENSE-2.0.
+//
+// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
+//
+// Contributors:
+//   ZettaScale Zenoh Team, <zenoh@zettascale.tech>
+//
+
+#include <ctype.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <zenoh-pico.h>
+#include <zenoh-pico/system/platform.h>
+
+// First Fit custom / user defined allocators
+#define WORD uint64_t             // FIXME: not true for other architectues like 32-bits architectures
+#define VAS_SIZE 1 * 1024 * 1024  // Virtual address space in bytes
+
+typedef struct z_m_block_hdr_t {
+    size_t size;               // Block size
+    struct z_m_block_t *next;  // The next block in the list
+    _Bool is_used;             // Whether this block is currently being used
+} z_m_block_hdr_t;
+
+typedef struct z_m_block_t {
+    z_m_block_hdr_t hdr;
+    WORD data[1];  // Payload pointer. Note: this MUST always be the last member in the struct.
+} z_m_block_t;
+
+_z_mutex_t mut;
+void *z_heap_start = NULL;  // Heap start. It must be explicitly initialized
+void *z_heap_end = NULL;    // Heap end. Defined for convenience to avoid computing
+                            // it multiple times
+z_m_block_t *p_brk = NULL;  // Program break identifying the top of our local heap
+
+void *z_minit(size_t size) {
+    z_heap_start = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+    if (z_heap_start == MAP_FAILED) {
+        z_heap_start = NULL;
+        z_heap_end = NULL;
+    } else {
+        z_heap_end = z_heap_start + (size * sizeof(uint8_t));
+    }
+
+    z_m_block_t *new_block = z_heap_start;
+    if (((uint8_t *)new_block + (sizeof(z_m_block_hdr_t) + 0)) <= (uint8_t *)z_heap_end) {
+        *new_block = (z_m_block_t){.hdr = {.next = NULL, .is_used = true, .size = 0}};
+        p_brk = (z_m_block_t *)((uint8_t *)new_block->data + new_block->hdr.size);
+    }
+
+    return z_heap_start;
+}
+
+void z_muninit(void *start, size_t size) { munmap(start, size); }
+
+// Align the size to the word size.
+size_t z_malign(size_t size) {
+    size_t aligned_size = (size + sizeof(WORD) - 1) & ~(sizeof(WORD) - 1);
+    return aligned_size;
+}
+
+// Allocates a block of memory of size bytes, following a first fit strategy.
+// Due to allignment extra bytes might be allocated.
+void *z_malloc(size_t size) {
+    _z_mutex_lock(&mut);
+    WORD *ret = NULL;
+    size_t aligned_size = z_malign(size);
+
+    z_m_block_t *block = z_heap_start;
+    _Bool found = false;
+    while (block->hdr.next != NULL) {
+        block = block->hdr.next;
+        if (block->hdr.is_used == false && block->hdr.size >= aligned_size) {
+            found = true;
+            break;
+        }
+    }
+
+    if (found == true) {
+        ret = block->data;
+        block->hdr.is_used = true;
+    } else {
+        z_m_block_t *new_block = p_brk;
+        if (((uint8_t *)new_block + (sizeof(z_m_block_hdr_t) + aligned_size)) <= (uint8_t *)z_heap_end) {
+            *new_block = (z_m_block_t){.hdr = {.next = NULL, .is_used = true, .size = aligned_size}};
+            ret = new_block->data;
+            block->hdr.next = new_block;
+            p_brk = (z_m_block_t *)((uint8_t *)new_block->data + new_block->hdr.size);
+        }
+    }
+    _z_mutex_unlock(&mut);
+
+    return ret;
+}
+
+void z_free(void *ptr) {
+    _z_mutex_lock(&mut);
+    z_m_block_t *block = ptr - sizeof(z_m_block_hdr_t);
+    block->hdr.is_used = false;
+    _z_mutex_unlock(&mut);
+}
+//
+
+int main(int argc, char **argv) {
+    if (z_minit(VAS_SIZE) == NULL) {
+        printf("Failed to reserve memory\n");
+    }
+
+    const char *keyexpr = "demo/example/zenoh-pico-pub";
+    const char *value = "Pub from Pico!";
+    const char *mode = "client";
+    char *locator = NULL;
+
+    int opt;
+    while ((opt = getopt(argc, argv, "k:v:e:m:")) != -1) {
+        switch (opt) {
+            case 'k':
+                keyexpr = optarg;
+                break;
+            case 'v':
+                value = optarg;
+                break;
+            case 'e':
+                locator = optarg;
+                break;
+            case 'm':
+                mode = optarg;
+                break;
+            case '?':
+                if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') {
+                    fprintf(stderr, "Option -%c requires an argument.\n", optopt);
+                } else {
+                    fprintf(stderr, "Unknown option `-%c'.\n", optopt);
+                }
+                return 1;
+            default:
+                return -1;
+        }
+    }
+
+    z_owned_config_t config = z_config_default();
+    zp_config_insert(z_loan(config), Z_CONFIG_MODE_KEY, z_string_make(mode));
+    if (locator != NULL) {
+        zp_config_insert(z_loan(config), Z_CONFIG_PEER_KEY, z_string_make(locator));
+    }
+
+    printf("Opening session...\n");
+    z_owned_session_t s = z_open(z_move(config));
+    if (!z_check(s)) {
+        printf("Unable to open session!\n");
+        return -1;
+    }
+
+    // Start read and lease tasks for zenoh-pico
+    if (zp_start_read_task(z_loan(s), NULL) < 0 || zp_start_lease_task(z_loan(s), NULL) < 0) {
+        printf("Unable to start read and lease tasks");
+        return -1;
+    }
+
+    printf("Declaring publisher for '%s'...\n", keyexpr);
+    z_owned_publisher_t pub = z_declare_publisher(z_loan(s), z_keyexpr(keyexpr), NULL);
+    if (!z_check(pub)) {
+        printf("Unable to declare publisher for key expression!\n");
+        return -1;
+    }
+
+    char *buf = (char *)malloc(256);
+    for (int idx = 0; 1; ++idx) {
+        sleep(1);
+        snprintf(buf, 256, "[%4d] %s", idx, value);
+        printf("Putting Data ('%s': '%s')...\n", keyexpr, buf);
+
+        z_publisher_put_options_t options = z_publisher_put_options_default();
+        options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL);
+        z_publisher_put(z_loan(pub), (const uint8_t *)buf, strlen(buf), &options);
+    }
+
+    z_undeclare_publisher(z_move(pub));
+
+    // Stop read and lease tasks for zenoh-pico
+    zp_stop_read_task(z_loan(s));
+    zp_stop_lease_task(z_loan(s));
+
+    z_close(z_move(s));
+
+    free(buf);
+
+    z_muninit(z_heap_start, VAS_SIZE);
+
+    return 0;
+}
diff --git a/examples/unix/c99/z_pub_ualloc.c b/examples/unix/c99/z_pub_ualloc.c
new file mode 100644
index 000000000..2289ece1d
--- /dev/null
+++ b/examples/unix/c99/z_pub_ualloc.c
@@ -0,0 +1,199 @@
+//
+// Copyright (c) 2022 ZettaScale Technology
+//
+// This program and the accompanying materials are made available under the
+// terms of the Eclipse Public License 2.0 which is available at
+// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
+// which is available at https://www.apache.org/licenses/LICENSE-2.0.
+//
+// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
+//
+// Contributors:
+//   ZettaScale Zenoh Team, <zenoh@zettascale.tech>
+//
+
+#include <ctype.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <zenoh-pico.h>
+#include <zenoh-pico/system/platform.h>
+
+// First Fit custom / user defined allocators
+#define WORD uint64_t             // FIXME: not true for other architectues like 32-bits architectures
+#define VAS_SIZE 1 * 1024 * 1024  // Virtual address space in bytes
+
+typedef struct z_m_block_hdr_t {
+    size_t size;               // Block size
+    struct z_m_block_t *next;  // The next block in the list
+    _Bool is_used;             // Whether this block is currently being used
+} z_m_block_hdr_t;
+
+typedef struct z_m_block_t {
+    z_m_block_hdr_t hdr;
+    WORD data[1];  // Payload pointer. Note: this MUST always be the last member in the struct.
+} z_m_block_t;
+
+_z_mutex_t mut;
+void *z_heap_start = NULL;  // Heap start. It must be explicitly initialized
+void *z_heap_end = NULL;    // Heap end. Defined for convenience to avoid computing
+                            // it multiple times
+z_m_block_t *p_brk = NULL;  // Program break identifying the top of our local heap
+
+void *z_minit(size_t size) {
+    z_heap_start = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+    if (z_heap_start == MAP_FAILED) {
+        z_heap_start = NULL;
+        z_heap_end = NULL;
+    } else {
+        z_heap_end = z_heap_start + (size * sizeof(uint8_t));
+    }
+
+    z_m_block_t *new_block = z_heap_start;
+    if (((uint8_t *)new_block + (sizeof(z_m_block_hdr_t) + 0)) <= (uint8_t *)z_heap_end) {
+        *new_block = (z_m_block_t){.hdr = {.next = NULL, .is_used = true, .size = 0}};
+        p_brk = (z_m_block_t *)((uint8_t *)new_block->data + new_block->hdr.size);
+    }
+
+    return z_heap_start;
+}
+
+void z_muninit(void *start, size_t size) { munmap(start, size); }
+
+// Align the size to the word size.
+size_t z_malign(size_t size) {
+    size_t aligned_size = (size + sizeof(WORD) - 1) & ~(sizeof(WORD) - 1);
+    return aligned_size;
+}
+
+// Allocates a block of memory of size bytes, following a first fit strategy.
+// Due to allignment extra bytes might be allocated.
+void *z_malloc(size_t size) {
+    _z_mutex_lock(&mut);
+    WORD *ret = NULL;
+    size_t aligned_size = z_malign(size);
+
+    z_m_block_t *block = z_heap_start;
+    _Bool found = false;
+    while (block->hdr.next != NULL) {
+        block = block->hdr.next;
+        if (block->hdr.is_used == false && block->hdr.size >= aligned_size) {
+            found = true;
+            break;
+        }
+    }
+
+    if (found == true) {
+        ret = block->data;
+        block->hdr.is_used = true;
+    } else {
+        z_m_block_t *new_block = p_brk;
+        if (((uint8_t *)new_block + (sizeof(z_m_block_hdr_t) + aligned_size)) <= (uint8_t *)z_heap_end) {
+            *new_block = (z_m_block_t){.hdr = {.next = NULL, .is_used = true, .size = aligned_size}};
+            ret = new_block->data;
+            block->hdr.next = new_block;
+            p_brk = (z_m_block_t *)((uint8_t *)new_block->data + new_block->hdr.size);
+        }
+    }
+    _z_mutex_unlock(&mut);
+
+    return ret;
+}
+
+void z_free(void *ptr) {
+    _z_mutex_lock(&mut);
+    z_m_block_t *block = ptr - sizeof(z_m_block_hdr_t);
+    block->hdr.is_used = false;
+    _z_mutex_unlock(&mut);
+}
+//
+
+int main(int argc, char **argv) {
+    if (z_minit(VAS_SIZE) == NULL) {
+        printf("Failed to reserve memory\n");
+    }
+
+    const char *keyexpr = "demo/example/zenoh-pico-pub";
+    const char *value = "Pub from Pico!";
+    const char *mode = "client";
+    char *locator = NULL;
+
+    int opt;
+    while ((opt = getopt(argc, argv, "k:v:e:m:")) != -1) {
+        switch (opt) {
+            case 'k':
+                keyexpr = optarg;
+                break;
+            case 'v':
+                value = optarg;
+                break;
+            case 'e':
+                locator = optarg;
+                break;
+            case 'm':
+                mode = optarg;
+                break;
+            case '?':
+                if (optopt == 'k' || optopt == 'v' || optopt == 'e' || optopt == 'm') {
+                    fprintf(stderr, "Option -%c requires an argument.\n", optopt);
+                } else {
+                    fprintf(stderr, "Unknown option `-%c'.\n", optopt);
+                }
+                return 1;
+            default:
+                return -1;
+        }
+    }
+
+    z_owned_config_t config = z_config_default();
+    zp_config_insert(z_config_loan(&config), Z_CONFIG_MODE_KEY, z_string_make(mode));
+    if (locator != NULL) {
+        zp_config_insert(z_config_loan(&config), Z_CONFIG_PEER_KEY, z_string_make(locator));
+    }
+
+    printf("Opening session...\n");
+    z_owned_session_t s = z_open(z_config_move(&config));
+    if (!z_session_check(&s)) {
+        printf("Unable to open session!\n");
+        return -1;
+    }
+
+    // Start read and lease tasks for zenoh-pico
+    if (zp_start_read_task(z_session_loan(&s), NULL) < 0 || zp_start_lease_task(z_session_loan(&s), NULL) < 0) {
+        printf("Unable to start read and lease tasks");
+        return -1;
+    }
+
+    printf("Declaring publisher for '%s'...\n", keyexpr);
+    z_owned_publisher_t pub = z_declare_publisher(z_session_loan(&s), z_keyexpr(keyexpr), NULL);
+    if (!z_publisher_check(&pub)) {
+        printf("Unable to declare publisher for key expression!\n");
+        return -1;
+    }
+
+    char *buf = (char *)malloc(256);
+    for (int idx = 0; 1; ++idx) {
+        sleep(1);
+        snprintf(buf, 256, "[%4d] %s", idx, value);
+        printf("Putting Data ('%s': '%s')...\n", keyexpr, buf);
+        z_publisher_put_options_t options = z_publisher_put_options_default();
+        options.encoding = z_encoding(Z_ENCODING_PREFIX_TEXT_PLAIN, NULL);
+        z_publisher_put(z_publisher_loan(&pub), (const uint8_t *)buf, strlen(buf), &options);
+    }
+
+    z_undeclare_publisher(z_publisher_move(&pub));
+
+    // Stop read and lease tasks for zenoh-pico
+    zp_stop_read_task(z_session_loan(&s));
+    zp_stop_lease_task(z_session_loan(&s));
+
+    z_close(z_session_move(&s));
+
+    free(buf);
+
+    z_muninit(z_heap_start, VAS_SIZE);
+
+    return 0;
+}

From 8ae88cd6a88097a49a2dfcd629c6b041373a53b8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20Guimar=C3=A3es?= <carlos.em.guimaraes@gmail.com>
Date: Wed, 22 Feb 2023 18:59:52 +0100
Subject: [PATCH 4/7] Make mutexes part of the public api

---
 examples/unix/c11/z_pub_ualloc.c              | 11 +++---
 examples/unix/c99/z_pub_ualloc.c              | 11 +++---
 include/zenoh-pico/net/session.h              |  2 +-
 include/zenoh-pico/session/session.h          |  2 +-
 include/zenoh-pico/system/platform.h          | 12 +++---
 .../system/platform/arduino/esp32.h           |  2 +-
 .../system/platform/arduino/opencr.h          |  4 +-
 .../zenoh-pico/system/platform/emscripten.h   |  2 +-
 include/zenoh-pico/system/platform/espidf.h   |  2 +-
 include/zenoh-pico/system/platform/mbed.h     |  2 +-
 include/zenoh-pico/system/platform/unix.h     |  2 +-
 include/zenoh-pico/system/platform/void.h     |  2 +-
 include/zenoh-pico/system/platform/windows.h  |  2 +-
 include/zenoh-pico/system/platform/zephyr.h   |  4 +-
 include/zenoh-pico/transport/transport.h      | 10 ++---
 src/session/query.c                           | 24 ++++++------
 src/session/queryable.c                       | 26 ++++++-------
 src/session/resource.c                        | 24 ++++++------
 src/session/subscription.c                    | 26 ++++++-------
 src/session/utils.c                           |  4 +-
 src/system/arduino/esp32/system.c             | 12 +++---
 src/system/arduino/opencr/system.c            | 12 +++---
 src/system/emscripten/system.c                | 12 +++---
 src/system/espidf/system.c                    | 12 +++---
 src/system/mbed/system.cpp                    | 12 +++---
 src/system/unix/system.c                      | 12 +++---
 src/system/windows/system.c                   | 12 +++---
 src/system/zephyr/system.c                    | 12 +++---
 src/transport/multicast/link/rx.c             |  8 ++--
 src/transport/multicast/link/task/lease.c     |  8 ++--
 src/transport/multicast/link/task/read.c      |  4 +-
 src/transport/multicast/link/tx.c             | 10 ++---
 src/transport/transport.c                     | 38 +++++++++----------
 src/transport/unicast/link/rx.c               |  4 +-
 src/transport/unicast/link/task/read.c        |  4 +-
 src/transport/unicast/link/tx.c               | 10 ++---
 36 files changed, 177 insertions(+), 179 deletions(-)

diff --git a/examples/unix/c11/z_pub_ualloc.c b/examples/unix/c11/z_pub_ualloc.c
index 1131afeb8..d046fffc1 100644
--- a/examples/unix/c11/z_pub_ualloc.c
+++ b/examples/unix/c11/z_pub_ualloc.c
@@ -19,7 +19,6 @@
 #include <sys/mman.h>
 #include <unistd.h>
 #include <zenoh-pico.h>
-#include <zenoh-pico/system/platform.h>
 
 // First Fit custom / user defined allocators
 #define WORD uint64_t             // FIXME: not true for other architectues like 32-bits architectures
@@ -36,7 +35,7 @@ typedef struct z_m_block_t {
     WORD data[1];  // Payload pointer. Note: this MUST always be the last member in the struct.
 } z_m_block_t;
 
-_z_mutex_t mut;
+z_mutex_t mut;
 void *z_heap_start = NULL;  // Heap start. It must be explicitly initialized
 void *z_heap_end = NULL;    // Heap end. Defined for convenience to avoid computing
                             // it multiple times
@@ -71,7 +70,7 @@ size_t z_malign(size_t size) {
 // Allocates a block of memory of size bytes, following a first fit strategy.
 // Due to allignment extra bytes might be allocated.
 void *z_malloc(size_t size) {
-    _z_mutex_lock(&mut);
+    z_mutex_lock(&mut);
     WORD *ret = NULL;
     size_t aligned_size = z_malign(size);
 
@@ -97,16 +96,16 @@ void *z_malloc(size_t size) {
             p_brk = (z_m_block_t *)((uint8_t *)new_block->data + new_block->hdr.size);
         }
     }
-    _z_mutex_unlock(&mut);
+    z_mutex_unlock(&mut);
 
     return ret;
 }
 
 void z_free(void *ptr) {
-    _z_mutex_lock(&mut);
+    z_mutex_lock(&mut);
     z_m_block_t *block = ptr - sizeof(z_m_block_hdr_t);
     block->hdr.is_used = false;
-    _z_mutex_unlock(&mut);
+    z_mutex_unlock(&mut);
 }
 //
 
diff --git a/examples/unix/c99/z_pub_ualloc.c b/examples/unix/c99/z_pub_ualloc.c
index 2289ece1d..b09c81a8e 100644
--- a/examples/unix/c99/z_pub_ualloc.c
+++ b/examples/unix/c99/z_pub_ualloc.c
@@ -19,7 +19,6 @@
 #include <sys/mman.h>
 #include <unistd.h>
 #include <zenoh-pico.h>
-#include <zenoh-pico/system/platform.h>
 
 // First Fit custom / user defined allocators
 #define WORD uint64_t             // FIXME: not true for other architectues like 32-bits architectures
@@ -36,7 +35,7 @@ typedef struct z_m_block_t {
     WORD data[1];  // Payload pointer. Note: this MUST always be the last member in the struct.
 } z_m_block_t;
 
-_z_mutex_t mut;
+z_mutex_t mut;
 void *z_heap_start = NULL;  // Heap start. It must be explicitly initialized
 void *z_heap_end = NULL;    // Heap end. Defined for convenience to avoid computing
                             // it multiple times
@@ -71,7 +70,7 @@ size_t z_malign(size_t size) {
 // Allocates a block of memory of size bytes, following a first fit strategy.
 // Due to allignment extra bytes might be allocated.
 void *z_malloc(size_t size) {
-    _z_mutex_lock(&mut);
+    z_mutex_lock(&mut);
     WORD *ret = NULL;
     size_t aligned_size = z_malign(size);
 
@@ -97,16 +96,16 @@ void *z_malloc(size_t size) {
             p_brk = (z_m_block_t *)((uint8_t *)new_block->data + new_block->hdr.size);
         }
     }
-    _z_mutex_unlock(&mut);
+    z_mutex_unlock(&mut);
 
     return ret;
 }
 
 void z_free(void *ptr) {
-    _z_mutex_lock(&mut);
+    z_mutex_lock(&mut);
     z_m_block_t *block = ptr - sizeof(z_m_block_hdr_t);
     block->hdr.is_used = false;
-    _z_mutex_unlock(&mut);
+    z_mutex_unlock(&mut);
 }
 //
 
diff --git a/include/zenoh-pico/net/session.h b/include/zenoh-pico/net/session.h
index 76e628692..568b82a82 100644
--- a/include/zenoh-pico/net/session.h
+++ b/include/zenoh-pico/net/session.h
@@ -24,7 +24,7 @@
  */
 typedef struct {
 #if Z_MULTI_THREAD == 1
-    _z_mutex_t _mutex_inner;
+    z_mutex_t _mutex_inner;
 #endif  // Z_MULTI_THREAD == 1
 
     // Zenoh-pico is considering a single transport per session.
diff --git a/include/zenoh-pico/session/session.h b/include/zenoh-pico/session/session.h
index 88ab2e631..b9eff20d4 100644
--- a/include/zenoh-pico/session/session.h
+++ b/include/zenoh-pico/session/session.h
@@ -168,7 +168,7 @@ _Z_LIST_DEFINE(_z_pending_query, _z_pending_query_t)
 
 typedef struct {
 #if Z_MULTI_THREAD == 1
-    _z_mutex_t _mutex;
+    z_mutex_t _mutex;
     _z_condvar_t _cond_var;
 #endif  // Z_MULTI_THREAD == 1
     _z_reply_data_list_t *_replies;
diff --git a/include/zenoh-pico/system/platform.h b/include/zenoh-pico/system/platform.h
index 07e1f009e..701c76855 100644
--- a/include/zenoh-pico/system/platform.h
+++ b/include/zenoh-pico/system/platform.h
@@ -64,19 +64,19 @@ int8_t _z_task_cancel(_z_task_t *task);
 void _z_task_free(_z_task_t **task);
 
 /*------------------ Mutex ------------------*/
-int8_t _z_mutex_init(_z_mutex_t *m);
-int8_t _z_mutex_free(_z_mutex_t *m);
+int8_t z_mutex_init(z_mutex_t *m);
+int8_t z_mutex_free(z_mutex_t *m);
 
-int8_t _z_mutex_lock(_z_mutex_t *m);
-int8_t _z_mutex_trylock(_z_mutex_t *m);
-int8_t _z_mutex_unlock(_z_mutex_t *m);
+int8_t z_mutex_lock(z_mutex_t *m);
+int8_t z_mutex_trylock(z_mutex_t *m);
+int8_t z_mutex_unlock(z_mutex_t *m);
 
 /*------------------ CondVar ------------------*/
 int8_t _z_condvar_init(_z_condvar_t *cv);
 int8_t _z_condvar_free(_z_condvar_t *cv);
 
 int8_t _z_condvar_signal(_z_condvar_t *cv);
-int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m);
+int8_t _z_condvar_wait(_z_condvar_t *cv, z_mutex_t *m);
 #endif  // Z_MULTI_THREAD == 1
 
 /*------------------ Sleep ------------------*/
diff --git a/include/zenoh-pico/system/platform/arduino/esp32.h b/include/zenoh-pico/system/platform/arduino/esp32.h
index bac42aa72..148401ed3 100644
--- a/include/zenoh-pico/system/platform/arduino/esp32.h
+++ b/include/zenoh-pico/system/platform/arduino/esp32.h
@@ -26,7 +26,7 @@
 #if Z_MULTI_THREAD == 1
 typedef TaskHandle_t _z_task_t;
 typedef void *_z_task_attr_t;  // Not used in ESP32
-typedef pthread_mutex_t _z_mutex_t;
+typedef pthread_mutex_t z_mutex_t;
 typedef pthread_cond_t _z_condvar_t;
 #endif  // Z_MULTI_THREAD == 1
 
diff --git a/include/zenoh-pico/system/platform/arduino/opencr.h b/include/zenoh-pico/system/platform/arduino/opencr.h
index 85f4b5752..dd7558b67 100644
--- a/include/zenoh-pico/system/platform/arduino/opencr.h
+++ b/include/zenoh-pico/system/platform/arduino/opencr.h
@@ -23,7 +23,7 @@
 #if Z_MULTI_THREAD == 1
 typedef void *_z_task_t;
 typedef void *_z_task_attr_t;
-typedef void *_z_mutex_t;
+typedef void *z_mutex_t;
 typedef void *_z_condvar_t;
 #endif  // Z_MULTI_THREAD == 1
 
@@ -42,7 +42,7 @@ typedef struct {
 #if Z_LINK_UDP_MULTICAST == 1 || Z_LINK_UDP_UNICAST == 1
         WiFiUDP *_udp;  // As pointer to cross the boundary between C and C++
 #endif
-    _Bool _err;
+        _Bool _err;
     };
 } _z_sys_net_socket_t;
 
diff --git a/include/zenoh-pico/system/platform/emscripten.h b/include/zenoh-pico/system/platform/emscripten.h
index a2f340921..739f65c6c 100644
--- a/include/zenoh-pico/system/platform/emscripten.h
+++ b/include/zenoh-pico/system/platform/emscripten.h
@@ -23,7 +23,7 @@
 #if Z_MULTI_THREAD == 1
 typedef pthread_t _z_task_t;
 typedef pthread_attr_t _z_task_attr_t;
-typedef pthread_mutex_t _z_mutex_t;
+typedef pthread_mutex_t z_mutex_t;
 typedef pthread_cond_t _z_condvar_t;
 #endif  // Z_MULTI_THREAD == 1
 
diff --git a/include/zenoh-pico/system/platform/espidf.h b/include/zenoh-pico/system/platform/espidf.h
index 6c35dd1f0..7b22700ca 100644
--- a/include/zenoh-pico/system/platform/espidf.h
+++ b/include/zenoh-pico/system/platform/espidf.h
@@ -25,7 +25,7 @@
 #if Z_MULTI_THREAD == 1
 typedef TaskHandle_t _z_task_t;
 typedef void *_z_task_attr_t;  // Not used in ESP32
-typedef pthread_mutex_t _z_mutex_t;
+typedef pthread_mutex_t z_mutex_t;
 typedef pthread_cond_t _z_condvar_t;
 #endif  // Z_MULTI_THREAD == 1
 
diff --git a/include/zenoh-pico/system/platform/mbed.h b/include/zenoh-pico/system/platform/mbed.h
index ca10d0459..296184912 100644
--- a/include/zenoh-pico/system/platform/mbed.h
+++ b/include/zenoh-pico/system/platform/mbed.h
@@ -25,7 +25,7 @@ typedef int _z_socket_t;
 #if Z_MULTI_THREAD == 1
 typedef void *_z_task_t;       // Workaround as MBED is a C++ library
 typedef void *_z_task_attr_t;  // Workaround as MBED is a C++ library
-typedef void *_z_mutex_t;      // Workaround as MBED is a C++ library
+typedef void *z_mutex_t;       // Workaround as MBED is a C++ library
 typedef void *_z_condvar_t;    // Workaround as MBED is a C++ library
 #endif                         // Z_MULTI_THREAD == 1
 
diff --git a/include/zenoh-pico/system/platform/unix.h b/include/zenoh-pico/system/platform/unix.h
index 3faa48333..2f47edf01 100644
--- a/include/zenoh-pico/system/platform/unix.h
+++ b/include/zenoh-pico/system/platform/unix.h
@@ -26,7 +26,7 @@
 #if Z_MULTI_THREAD == 1
 typedef pthread_t _z_task_t;
 typedef pthread_attr_t _z_task_attr_t;
-typedef pthread_mutex_t _z_mutex_t;
+typedef pthread_mutex_t z_mutex_t;
 typedef pthread_cond_t _z_condvar_t;
 #endif  // Z_MULTI_THREAD == 1
 
diff --git a/include/zenoh-pico/system/platform/void.h b/include/zenoh-pico/system/platform/void.h
index 26197d375..7779302aa 100644
--- a/include/zenoh-pico/system/platform/void.h
+++ b/include/zenoh-pico/system/platform/void.h
@@ -20,7 +20,7 @@
 #if Z_MULTI_THREAD == 1
 typedef void *_z_task_t;
 typedef void *_z_task_attr_t;
-typedef void *_z_mutex_t;
+typedef void *z_mutex_t;
 typedef void *_z_condvar_t;
 #endif  // Z_MULTI_THREAD == 1
 
diff --git a/include/zenoh-pico/system/platform/windows.h b/include/zenoh-pico/system/platform/windows.h
index f7c7d1ccb..1f528d47a 100644
--- a/include/zenoh-pico/system/platform/windows.h
+++ b/include/zenoh-pico/system/platform/windows.h
@@ -23,7 +23,7 @@
 #if Z_MULTI_THREAD == 1
 typedef HANDLE *_z_task_t;
 typedef void *_z_task_attr_t;  // Not used in Windows
-typedef SRWLOCK _z_mutex_t;
+typedef SRWLOCK z_mutex_t;
 typedef CONDITION_VARIABLE _z_condvar_t;
 #endif  // Z_MULTI_THREAD == 1
 
diff --git a/include/zenoh-pico/system/platform/zephyr.h b/include/zenoh-pico/system/platform/zephyr.h
index 19c8795c3..98490c7af 100644
--- a/include/zenoh-pico/system/platform/zephyr.h
+++ b/include/zenoh-pico/system/platform/zephyr.h
@@ -15,15 +15,15 @@
 #ifndef ZENOH_PICO_SYSTEM_ZEPHYR_TYPES_H
 #define ZENOH_PICO_SYSTEM_ZEPHYR_TYPES_H
 
-#include <pthread.h>
 #include <kernel.h>
+#include <pthread.h>
 
 #include "zenoh-pico/config.h"
 
 #if Z_MULTI_THREAD == 1
 typedef pthread_t _z_task_t;
 typedef pthread_attr_t _z_task_attr_t;
-typedef pthread_mutex_t _z_mutex_t;
+typedef pthread_mutex_t z_mutex_t;
 typedef pthread_cond_t _z_condvar_t;
 #endif  // Z_MULTI_THREAD == 1
 
diff --git a/include/zenoh-pico/transport/transport.h b/include/zenoh-pico/transport/transport.h
index b764657bb..97537e52f 100644
--- a/include/zenoh-pico/transport/transport.h
+++ b/include/zenoh-pico/transport/transport.h
@@ -54,8 +54,8 @@ typedef struct {
 
 #if Z_MULTI_THREAD == 1
     // TX and RX mutexes
-    _z_mutex_t _mutex_rx;
-    _z_mutex_t _mutex_tx;
+    z_mutex_t _mutex_rx;
+    z_mutex_t _mutex_tx;
 #endif  // Z_MULTI_THREAD == 1
 
     _z_link_t _link;
@@ -96,11 +96,11 @@ typedef struct {
 
 #if Z_MULTI_THREAD == 1
     // TX and RX mutexes
-    _z_mutex_t _mutex_rx;
-    _z_mutex_t _mutex_tx;
+    z_mutex_t _mutex_rx;
+    z_mutex_t _mutex_tx;
 
     // Peer list mutex
-    _z_mutex_t _mutex_peer;
+    z_mutex_t _mutex_peer;
 #endif  // Z_MULTI_THREAD == 1
 
     _z_link_t _link;
diff --git a/src/session/query.c b/src/session/query.c
index aae6d3cee..3d7ceb514 100644
--- a/src/session/query.c
+++ b/src/session/query.c
@@ -94,13 +94,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_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     _z_pending_query_t *pql = __unsafe__z_get_pending_query_by_id(zn, id);
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
     return pql;
 }
@@ -111,7 +111,7 @@ int8_t _z_register_pending_query(_z_session_t *zn, _z_pending_query_t *pen_qry)
     _Z_DEBUG(">>> Allocating query for (%zu:%s,%s)\n", pen_qry->_key._id, pen_qry->_key._suffix, pen_qry->_parameters);
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     _z_pending_query_t *pql = __unsafe__z_get_pending_query_by_id(zn, pen_qry->_id);
@@ -122,7 +122,7 @@ int8_t _z_register_pending_query(_z_session_t *zn, _z_pending_query_t *pen_qry)
     }
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     return ret;
@@ -139,7 +139,7 @@ int8_t _z_trigger_query_reply_partial(_z_session_t *zn, const _z_reply_context_t
     }
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     _z_pending_query_t *pen_qry = __unsafe__z_get_pending_query_by_id(zn, reply_context->_qid);
@@ -211,7 +211,7 @@ int8_t _z_trigger_query_reply_partial(_z_session_t *zn, const _z_reply_context_t
     }
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     // Trigger the user callback
@@ -231,7 +231,7 @@ int8_t _z_trigger_query_reply_final(_z_session_t *zn, const _z_reply_context_t *
     int8_t ret = _Z_RES_OK;
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     if ((ret == _Z_RES_OK) && (_Z_HAS_FLAG(reply_context->_header, _Z_FLAG_Z_F) ==
@@ -263,7 +263,7 @@ int8_t _z_trigger_query_reply_final(_z_session_t *zn, const _z_reply_context_t *
     }
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     return ret;
@@ -271,24 +271,24 @@ int8_t _z_trigger_query_reply_final(_z_session_t *zn, const _z_reply_context_t *
 
 void _z_unregister_pending_query(_z_session_t *zn, _z_pending_query_t *pen_qry) {
 #if Z_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     zn->_pending_queries = _z_pending_query_list_drop_filter(zn->_pending_queries, _z_pending_query_eq, pen_qry);
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 }
 
 void _z_flush_pending_queries(_z_session_t *zn) {
 #if Z_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     _z_pending_query_list_free(&zn->_pending_queries);
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 }
diff --git a/src/session/queryable.c b/src/session/queryable.c
index 928481a23..9ac573aa3 100644
--- a/src/session/queryable.c
+++ b/src/session/queryable.c
@@ -87,13 +87,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_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     _z_questionable_sptr_t *qle = __unsafe_z_get_questionable_by_id(zn, id);
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     return qle;
@@ -101,14 +101,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_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     _z_keyexpr_t key = __unsafe_z_get_expanded_key_from_key(zn, _Z_RESOURCE_IS_LOCAL, keyexpr);
     _z_questionable_sptr_list_t *qles = __unsafe_z_get_questionable_by_key(zn, key);
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     return qles;
@@ -119,7 +119,7 @@ _z_questionable_sptr_t *_z_register_questionable(_z_session_t *zn, _z_questionab
     _z_questionable_sptr_t *ret = NULL;
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     ret = (_z_questionable_sptr_t *)z_malloc(sizeof(_z_questionable_sptr_t));
@@ -129,7 +129,7 @@ _z_questionable_sptr_t *_z_register_questionable(_z_session_t *zn, _z_questionab
     }
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     return ret;
@@ -139,7 +139,7 @@ int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *query) {
     int8_t ret = _Z_RES_OK;
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     _z_keyexpr_t key = __unsafe_z_get_expanded_key_from_key(zn, _Z_RESOURCE_IS_REMOTE, &query->_key);
@@ -147,7 +147,7 @@ int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *query) {
         _z_questionable_sptr_list_t *qles = __unsafe_z_get_questionable_by_key(zn, key);
 
 #if Z_MULTI_THREAD == 1
-        _z_mutex_unlock(&zn->_mutex_inner);
+        z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
         // Build the query
@@ -189,7 +189,7 @@ int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *query) {
         _z_msg_clear(&z_msg);
     } else {
 #if Z_MULTI_THREAD == 1
-        _z_mutex_unlock(&zn->_mutex_inner);
+        z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
         ret = _Z_ERR_KEYEXPR_UNKNOWN;
@@ -200,25 +200,25 @@ int8_t _z_trigger_queryables(_z_session_t *zn, const _z_msg_query_t *query) {
 
 void _z_unregister_questionable(_z_session_t *zn, _z_questionable_sptr_t *qle) {
 #if Z_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     zn->_local_questionable =
         _z_questionable_sptr_list_drop_filter(zn->_local_questionable, _z_questionable_sptr_eq, qle);
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 }
 
 void _z_flush_questionables(_z_session_t *zn) {
 #if Z_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     _z_questionable_sptr_list_free(&zn->_local_questionable);
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 }
diff --git a/src/session/resource.c b/src/session/resource.c
index efa3f3acc..cc2331701 100644
--- a/src/session/resource.c
+++ b/src/session/resource.c
@@ -166,13 +166,13 @@ _z_keyexpr_t __unsafe_z_get_expanded_key_from_key(_z_session_t *zn, uint8_t is_l
 
 _z_resource_t *_z_get_resource_by_id(_z_session_t *zn, uint8_t is_local, _z_zint_t rid) {
 #if Z_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     _z_resource_t *res = __unsafe_z_get_resource_by_id(zn, is_local, rid);
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     return res;
@@ -180,13 +180,13 @@ _z_resource_t *_z_get_resource_by_id(_z_session_t *zn, uint8_t is_local, _z_zint
 
 _z_resource_t *_z_get_resource_by_key(_z_session_t *zn, uint8_t is_local, const _z_keyexpr_t *keyexpr) {
 #if Z_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     _z_resource_t *res = __unsafe_z_get_resource_by_key(zn, is_local, keyexpr);
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     return res;
@@ -194,13 +194,13 @@ _z_resource_t *_z_get_resource_by_key(_z_session_t *zn, uint8_t is_local, const
 
 _z_keyexpr_t _z_get_expanded_key_from_key(_z_session_t *zn, uint8_t is_local, const _z_keyexpr_t *keyexpr) {
 #if Z_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     _z_keyexpr_t res = __unsafe_z_get_expanded_key_from_key(zn, is_local, keyexpr);
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     return res;
@@ -212,7 +212,7 @@ int8_t _z_register_resource(_z_session_t *zn, uint8_t is_local, _z_resource_t *r
     _Z_DEBUG(">>> Allocating res decl for (%zu,%zu:%s)\n", res->_id, res->_key._id, res->_key._suffix);
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     // FIXME: check by keyexpr instead
@@ -229,7 +229,7 @@ int8_t _z_register_resource(_z_session_t *zn, uint8_t is_local, _z_resource_t *r
     }
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     return ret;
@@ -237,7 +237,7 @@ int8_t _z_register_resource(_z_session_t *zn, uint8_t is_local, _z_resource_t *r
 
 void _z_unregister_resource(_z_session_t *zn, uint8_t is_local, _z_resource_t *res) {
 #if Z_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     if (is_local == _Z_RESOURCE_IS_LOCAL) {
@@ -247,19 +247,19 @@ void _z_unregister_resource(_z_session_t *zn, uint8_t is_local, _z_resource_t *r
     }
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 }
 
 void _z_flush_resources(_z_session_t *zn) {
 #if Z_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     _z_resource_list_free(&zn->_local_resources);
     _z_resource_list_free(&zn->_remote_resources);
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 }
diff --git a/src/session/subscription.c b/src/session/subscription.c
index f7e002b33..28ccdf859 100644
--- a/src/session/subscription.c
+++ b/src/session/subscription.c
@@ -95,13 +95,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_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     _z_subscription_sptr_t *sub = __unsafe_z_get_subscription_by_id(zn, is_local, id);
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     return sub;
@@ -109,13 +109,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_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     _z_subscription_sptr_list_t *subs = __unsafe_z_get_subscriptions_by_key(zn, is_local, *key);
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     return subs;
@@ -126,7 +126,7 @@ _z_subscription_sptr_t *_z_register_subscription(_z_session_t *zn, uint8_t is_lo
     _z_subscription_sptr_t *ret = NULL;
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     _z_subscription_sptr_list_t *subs = __unsafe_z_get_subscriptions_by_key(zn, is_local, s->_key);
@@ -143,7 +143,7 @@ _z_subscription_sptr_t *_z_register_subscription(_z_session_t *zn, uint8_t is_lo
     }
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     return ret;
@@ -154,7 +154,7 @@ int8_t _z_trigger_subscriptions(_z_session_t *zn, const _z_keyexpr_t keyexpr, co
     int8_t ret = _Z_RES_OK;
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     _z_keyexpr_t key = __unsafe_z_get_expanded_key_from_key(zn, _Z_RESOURCE_IS_REMOTE, &keyexpr);
@@ -162,7 +162,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_MULTI_THREAD == 1
-        _z_mutex_unlock(&zn->_mutex_inner);
+        z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
         // Build the sample
@@ -183,7 +183,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_MULTI_THREAD == 1
-        _z_mutex_unlock(&zn->_mutex_inner);
+        z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
         ret = _Z_ERR_KEYEXPR_UNKNOWN;
     }
@@ -193,7 +193,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_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     if (is_local == _Z_RESOURCE_IS_LOCAL) {
@@ -205,19 +205,19 @@ void _z_unregister_subscription(_z_session_t *zn, uint8_t is_local, _z_subscript
     }
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 }
 
 void _z_flush_subscriptions(_z_session_t *zn) {
 #if Z_MULTI_THREAD == 1
-    _z_mutex_lock(&zn->_mutex_inner);
+    z_mutex_lock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 
     _z_subscription_sptr_list_free(&zn->_local_subscriptions);
     _z_subscription_sptr_list_free(&zn->_remote_subscriptions);
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&zn->_mutex_inner);
+    z_mutex_unlock(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 }
diff --git a/src/session/utils.c b/src/session/utils.c
index 341dfbe2c..45b52bc49 100644
--- a/src/session/utils.c
+++ b/src/session/utils.c
@@ -78,7 +78,7 @@ int8_t _z_session_init(_z_session_t *zn, _z_bytes_t *zid) {
     zn->_pending_queries = NULL;
 
 #if Z_MULTI_THREAD == 1
-    ret = _z_mutex_init(&zn->_mutex_inner);
+    ret = z_mutex_init(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
     if (ret == _Z_RES_OK) {
         zn->_local_zid = _z_bytes_empty();
@@ -118,7 +118,7 @@ void _z_session_clear(_z_session_t *zn) {
     _z_flush_pending_queries(zn);
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_free(&zn->_mutex_inner);
+    z_mutex_free(&zn->_mutex_inner);
 #endif  // Z_MULTI_THREAD == 1
 }
 
diff --git a/src/system/arduino/esp32/system.c b/src/system/arduino/esp32/system.c
index 1d823c14c..71e3f0bd9 100644
--- a/src/system/arduino/esp32/system.c
+++ b/src/system/arduino/esp32/system.c
@@ -94,15 +94,15 @@ void _z_task_free(_z_task_t **task) {
 }
 
 /*------------------ Mutex ------------------*/
-int8_t _z_mutex_init(_z_mutex_t *m) { return pthread_mutex_init(m, NULL); }
+int8_t z_mutex_init(z_mutex_t *m) { return pthread_mutex_init(m, NULL); }
 
-int8_t _z_mutex_free(_z_mutex_t *m) { return pthread_mutex_destroy(m); }
+int8_t z_mutex_free(z_mutex_t *m) { return pthread_mutex_destroy(m); }
 
-int8_t _z_mutex_lock(_z_mutex_t *m) { return pthread_mutex_lock(m); }
+int8_t z_mutex_lock(z_mutex_t *m) { return pthread_mutex_lock(m); }
 
-int8_t _z_mutex_trylock(_z_mutex_t *m) { return pthread_mutex_trylock(m); }
+int8_t z_mutex_trylock(z_mutex_t *m) { return pthread_mutex_trylock(m); }
 
-int8_t _z_mutex_unlock(_z_mutex_t *m) { return pthread_mutex_unlock(m); }
+int8_t z_mutex_unlock(z_mutex_t *m) { return pthread_mutex_unlock(m); }
 
 /*------------------ Condvar ------------------*/
 int8_t _z_condvar_init(_z_condvar_t *cv) { return pthread_cond_init(cv, NULL); }
@@ -111,7 +111,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv) { return pthread_cond_destroy(cv); }
 
 int8_t _z_condvar_signal(_z_condvar_t *cv) { return pthread_cond_signal(cv); }
 
-int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wait(cv, m); }
+int8_t _z_condvar_wait(_z_condvar_t *cv, z_mutex_t *m) { return pthread_cond_wait(cv, m); }
 #endif  // Z_MULTI_THREAD == 1
 
 /*------------------ Sleep ------------------*/
diff --git a/src/system/arduino/opencr/system.c b/src/system/arduino/opencr/system.c
index 946392bb3..d4b787734 100644
--- a/src/system/arduino/opencr/system.c
+++ b/src/system/arduino/opencr/system.c
@@ -76,15 +76,15 @@ void _z_task_free(_z_task_t **task) {
 }
 
 /*------------------ Mutex ------------------*/
-int8_t _z_mutex_init(_z_mutex_t *m) { return -1; }
+int8_t z_mutex_init(z_mutex_t *m) { return -1; }
 
-int8_t _z_mutex_free(_z_mutex_t *m) { return -1; }
+int8_t z_mutex_free(z_mutex_t *m) { return -1; }
 
-int8_t _z_mutex_lock(_z_mutex_t *m) { return -1; }
+int8_t z_mutex_lock(z_mutex_t *m) { return -1; }
 
-int8_t _z_mutex_trylock(_z_mutex_t *m) { return -1; }
+int8_t z_mutex_trylock(z_mutex_t *m) { return -1; }
 
-int8_t _z_mutex_unlock(_z_mutex_t *m) { return -1; }
+int8_t z_mutex_unlock(z_mutex_t *m) { return -1; }
 
 /*------------------ Condvar ------------------*/
 int8_t _z_condvar_init(_z_condvar_t *cv) { return -1; }
@@ -93,7 +93,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv) { return -1; }
 
 int8_t _z_condvar_signal(_z_condvar_t *cv) { return -1; }
 
-int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return -1; }
+int8_t _z_condvar_wait(_z_condvar_t *cv, z_mutex_t *m) { return -1; }
 #endif  // Z_MULTI_THREAD == 1
 
 /*------------------ Sleep ------------------*/
diff --git a/src/system/emscripten/system.c b/src/system/emscripten/system.c
index 89242bd72..18b94226a 100644
--- a/src/system/emscripten/system.c
+++ b/src/system/emscripten/system.c
@@ -59,15 +59,15 @@ void _z_task_free(_z_task_t **task) {
 }
 
 /*------------------ Mutex ------------------*/
-int8_t _z_mutex_init(_z_mutex_t *m) { return pthread_mutex_init(m, 0); }
+int8_t z_mutex_init(z_mutex_t *m) { return pthread_mutex_init(m, 0); }
 
-int8_t _z_mutex_free(_z_mutex_t *m) { return pthread_mutex_destroy(m); }
+int8_t z_mutex_free(z_mutex_t *m) { return pthread_mutex_destroy(m); }
 
-int8_t _z_mutex_lock(_z_mutex_t *m) { return pthread_mutex_lock(m); }
+int8_t z_mutex_lock(z_mutex_t *m) { return pthread_mutex_lock(m); }
 
-int8_t _z_mutex_trylock(_z_mutex_t *m) { return pthread_mutex_trylock(m); }
+int8_t z_mutex_trylock(z_mutex_t *m) { return pthread_mutex_trylock(m); }
 
-int8_t _z_mutex_unlock(_z_mutex_t *m) { return pthread_mutex_unlock(m); }
+int8_t z_mutex_unlock(z_mutex_t *m) { return pthread_mutex_unlock(m); }
 
 /*------------------ Condvar ------------------*/
 int8_t _z_condvar_init(_z_condvar_t *cv) { return pthread_cond_init(cv, 0); }
@@ -76,7 +76,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv) { return pthread_cond_destroy(cv); }
 
 int8_t _z_condvar_signal(_z_condvar_t *cv) { return pthread_cond_signal(cv); }
 
-int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wait(cv, m); }
+int8_t _z_condvar_wait(_z_condvar_t *cv, z_mutex_t *m) { return pthread_cond_wait(cv, m); }
 #endif  // Z_MULTI_THREAD == 1
 
 /*------------------ Sleep ------------------*/
diff --git a/src/system/espidf/system.c b/src/system/espidf/system.c
index a3a4dd472..0fb78fb96 100644
--- a/src/system/espidf/system.c
+++ b/src/system/espidf/system.c
@@ -95,15 +95,15 @@ void _z_task_free(_z_task_t **task) {
 }
 
 /*------------------ Mutex ------------------*/
-int8_t _z_mutex_init(_z_mutex_t *m) { return pthread_mutex_init(m, NULL); }
+int8_t z_mutex_init(z_mutex_t *m) { return pthread_mutex_init(m, NULL); }
 
-int8_t _z_mutex_free(_z_mutex_t *m) { return pthread_mutex_destroy(m); }
+int8_t z_mutex_free(z_mutex_t *m) { return pthread_mutex_destroy(m); }
 
-int8_t _z_mutex_lock(_z_mutex_t *m) { return pthread_mutex_lock(m); }
+int8_t z_mutex_lock(z_mutex_t *m) { return pthread_mutex_lock(m); }
 
-int8_t _z_mutex_trylock(_z_mutex_t *m) { return pthread_mutex_trylock(m); }
+int8_t z_mutex_trylock(z_mutex_t *m) { return pthread_mutex_trylock(m); }
 
-int8_t _z_mutex_unlock(_z_mutex_t *m) { return pthread_mutex_unlock(m); }
+int8_t z_mutex_unlock(z_mutex_t *m) { return pthread_mutex_unlock(m); }
 
 /*------------------ Condvar ------------------*/
 int8_t _z_condvar_init(_z_condvar_t *cv) { return pthread_cond_init(cv, NULL); }
@@ -112,7 +112,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv) { return pthread_cond_destroy(cv); }
 
 int8_t _z_condvar_signal(_z_condvar_t *cv) { return pthread_cond_signal(cv); }
 
-int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wait(cv, m); }
+int8_t _z_condvar_wait(_z_condvar_t *cv, z_mutex_t *m) { return pthread_cond_wait(cv, m); }
 #endif  // Z_MULTI_THREAD == 1
 
 /*------------------ Sleep ------------------*/
diff --git a/src/system/mbed/system.cpp b/src/system/mbed/system.cpp
index 68dc20b01..068608be5 100644
--- a/src/system/mbed/system.cpp
+++ b/src/system/mbed/system.cpp
@@ -66,24 +66,24 @@ void _z_task_free(_z_task_t **task) {
 }
 
 /*------------------ Mutex ------------------*/
-int8_t _z_mutex_init(_z_mutex_t *m) {
+int8_t z_mutex_init(z_mutex_t *m) {
     *m = new Mutex();
     return 0;
 }
 
-int8_t _z_mutex_free(_z_mutex_t *m) {
+int8_t z_mutex_free(z_mutex_t *m) {
     delete ((Mutex *)*m);
     return 0;
 }
 
-int8_t _z_mutex_lock(_z_mutex_t *m) {
+int8_t z_mutex_lock(z_mutex_t *m) {
     ((Mutex *)*m)->lock();
     return 0;
 }
 
-int8_t _z_mutex_trylock(_z_mutex_t *m) { return (((Mutex *)*m)->trylock() == true) ? 0 : -1; }
+int8_t z_mutex_trylock(z_mutex_t *m) { return (((Mutex *)*m)->trylock() == true) ? 0 : -1; }
 
-int8_t _z_mutex_unlock(_z_mutex_t *m) {
+int8_t z_mutex_unlock(z_mutex_t *m) {
     ((Mutex *)*m)->unlock();
     return 0;
 }
@@ -101,7 +101,7 @@ int8_t _z_condvar_signal(_z_condvar_t *cv) {
     return 0;
 }
 
-int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) {
+int8_t _z_condvar_wait(_z_condvar_t *cv, z_mutex_t *m) {
     *cv = new ConditionVariable(*((Mutex *)*m));
     ((ConditionVariable *)*cv)->wait();
     return 0;
diff --git a/src/system/unix/system.c b/src/system/unix/system.c
index cc26734e1..a5d92f141 100644
--- a/src/system/unix/system.c
+++ b/src/system/unix/system.c
@@ -117,15 +117,15 @@ void _z_task_free(_z_task_t **task) {
 }
 
 /*------------------ Mutex ------------------*/
-int8_t _z_mutex_init(_z_mutex_t *m) { return pthread_mutex_init(m, 0); }
+int8_t z_mutex_init(z_mutex_t *m) { return pthread_mutex_init(m, 0); }
 
-int8_t _z_mutex_free(_z_mutex_t *m) { return pthread_mutex_destroy(m); }
+int8_t z_mutex_free(z_mutex_t *m) { return pthread_mutex_destroy(m); }
 
-int8_t _z_mutex_lock(_z_mutex_t *m) { return pthread_mutex_lock(m); }
+int8_t z_mutex_lock(z_mutex_t *m) { return pthread_mutex_lock(m); }
 
-int8_t _z_mutex_trylock(_z_mutex_t *m) { return pthread_mutex_trylock(m); }
+int8_t z_mutex_trylock(z_mutex_t *m) { return pthread_mutex_trylock(m); }
 
-int8_t _z_mutex_unlock(_z_mutex_t *m) { return pthread_mutex_unlock(m); }
+int8_t z_mutex_unlock(z_mutex_t *m) { return pthread_mutex_unlock(m); }
 
 /*------------------ Condvar ------------------*/
 int8_t _z_condvar_init(_z_condvar_t *cv) { return pthread_cond_init(cv, 0); }
@@ -134,7 +134,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv) { return pthread_cond_destroy(cv); }
 
 int8_t _z_condvar_signal(_z_condvar_t *cv) { return pthread_cond_signal(cv); }
 
-int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wait(cv, m); }
+int8_t _z_condvar_wait(_z_condvar_t *cv, z_mutex_t *m) { return pthread_cond_wait(cv, m); }
 #endif  // Z_MULTI_THREAD == 1
 
 /*------------------ Sleep ------------------*/
diff --git a/src/system/windows/system.c b/src/system/windows/system.c
index 519a9ba01..226ae3e38 100644
--- a/src/system/windows/system.c
+++ b/src/system/windows/system.c
@@ -98,25 +98,25 @@ void _z_task_free(_z_task_t **task) {
 }
 
 /*------------------ Mutex ------------------*/
-int8_t _z_mutex_init(_z_mutex_t *m) {
+int8_t z_mutex_init(z_mutex_t *m) {
     int8_t ret = _Z_RES_OK;
     InitializeSRWLock(m);
     return ret;
 }
 
-int8_t _z_mutex_free(_z_mutex_t *m) {
+int8_t z_mutex_free(z_mutex_t *m) {
     (void)(m);
     int8_t ret = _Z_RES_OK;
     return ret;
 }
 
-int8_t _z_mutex_lock(_z_mutex_t *m) {
+int8_t z_mutex_lock(z_mutex_t *m) {
     int8_t ret = _Z_RES_OK;
     AcquireSRWLockExclusive(m);
     return ret;
 }
 
-int8_t _z_mutex_trylock(_z_mutex_t *m) {
+int8_t z_mutex_trylock(z_mutex_t *m) {
     int8_t ret = _Z_RES_OK;
     if (TryAcquireSRWLockExclusive(m) == 0) {
         ret = _Z_ERR_GENERIC;
@@ -124,7 +124,7 @@ int8_t _z_mutex_trylock(_z_mutex_t *m) {
     return ret;
 }
 
-int8_t _z_mutex_unlock(_z_mutex_t *m) {
+int8_t z_mutex_unlock(z_mutex_t *m) {
     int8_t ret = _Z_RES_OK;
     ReleaseSRWLockExclusive(m);
     return ret;
@@ -149,7 +149,7 @@ int8_t _z_condvar_signal(_z_condvar_t *cv) {
     return ret;
 }
 
-int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) {
+int8_t _z_condvar_wait(_z_condvar_t *cv, z_mutex_t *m) {
     int8_t ret = _Z_RES_OK;
     SleepConditionVariableSRW(cv, m, INFINITE, 0);
     return ret;
diff --git a/src/system/zephyr/system.c b/src/system/zephyr/system.c
index d34dc2581..c11eb89de 100644
--- a/src/system/zephyr/system.c
+++ b/src/system/zephyr/system.c
@@ -88,15 +88,15 @@ void _z_task_free(_z_task_t **task) {
 }
 
 /*------------------ Mutex ------------------*/
-int8_t _z_mutex_init(_z_mutex_t *m) { return pthread_mutex_init(m, 0); }
+int8_t z_mutex_init(z_mutex_t *m) { return pthread_mutex_init(m, 0); }
 
-int8_t _z_mutex_free(_z_mutex_t *m) { return pthread_mutex_destroy(m); }
+int8_t z_mutex_free(z_mutex_t *m) { return pthread_mutex_destroy(m); }
 
-int8_t _z_mutex_lock(_z_mutex_t *m) { return pthread_mutex_lock(m); }
+int8_t z_mutex_lock(z_mutex_t *m) { return pthread_mutex_lock(m); }
 
-int8_t _z_mutex_trylock(_z_mutex_t *m) { return pthread_mutex_trylock(m); }
+int8_t z_mutex_trylock(z_mutex_t *m) { return pthread_mutex_trylock(m); }
 
-int8_t _z_mutex_unlock(_z_mutex_t *m) { return pthread_mutex_unlock(m); }
+int8_t z_mutex_unlock(z_mutex_t *m) { return pthread_mutex_unlock(m); }
 
 /*------------------ Condvar ------------------*/
 int8_t _z_condvar_init(_z_condvar_t *cv) { return pthread_cond_init(cv, 0); }
@@ -105,7 +105,7 @@ int8_t _z_condvar_free(_z_condvar_t *cv) { return pthread_cond_destroy(cv); }
 
 int8_t _z_condvar_signal(_z_condvar_t *cv) { return pthread_cond_signal(cv); }
 
-int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wait(cv, m); }
+int8_t _z_condvar_wait(_z_condvar_t *cv, z_mutex_t *m) { return pthread_cond_wait(cv, m); }
 #endif  // Z_MULTI_THREAD == 1
 
 /*------------------ Sleep ------------------*/
diff --git a/src/transport/multicast/link/rx.c b/src/transport/multicast/link/rx.c
index 987a3ac2b..6895ecf2e 100644
--- a/src/transport/multicast/link/rx.c
+++ b/src/transport/multicast/link/rx.c
@@ -48,7 +48,7 @@ int8_t _z_multicast_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_transport_me
 
 #if Z_MULTI_THREAD == 1
     // Acquire the lock
-    _z_mutex_lock(&ztm->_mutex_rx);
+    z_mutex_lock(&ztm->_mutex_rx);
 #endif  // Z_MULTI_THREAD == 1
 
     // Prepare the buffer
@@ -87,7 +87,7 @@ int8_t _z_multicast_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_transport_me
     }
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&ztm->_mutex_rx);
+    z_mutex_unlock(&ztm->_mutex_rx);
 #endif  // Z_MULTI_THREAD == 1
 
     return ret;
@@ -102,7 +102,7 @@ int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_t
     int8_t ret = _Z_RES_OK;
 #if Z_MULTI_THREAD == 1
     // Acquire and keep the lock
-    _z_mutex_lock(&ztm->_mutex_peer);
+    z_mutex_lock(&ztm->_mutex_peer);
 #endif  // Z_MULTI_THREAD == 1
 
     // Mark the session that we have received data from this peer
@@ -327,7 +327,7 @@ int8_t _z_multicast_handle_transport_message(_z_transport_multicast_t *ztm, _z_t
     }
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&ztm->_mutex_peer);
+    z_mutex_unlock(&ztm->_mutex_peer);
 #endif  // Z_MULTI_THREAD == 1
 
     return ret;
diff --git a/src/transport/multicast/link/task/lease.c b/src/transport/multicast/link/task/lease.c
index 2bec9330f..4893629fb 100644
--- a/src/transport/multicast/link/task/lease.c
+++ b/src/transport/multicast/link/task/lease.c
@@ -83,7 +83,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);
+        z_mutex_lock(&ztm->_mutex_peer);
 
         if (next_lease <= 0) {
             it = ztm->_peers;
@@ -142,13 +142,13 @@ void *_zp_multicast_lease_task(void *ztm_arg) {
             }
         }
 
-        _z_mutex_unlock(&ztm->_mutex_peer);
+        z_mutex_unlock(&ztm->_mutex_peer);
 
         // The keep alive and lease intervals are expressed in milliseconds
         z_sleep_ms(interval);
 
         // Decrement all intervals
-        _z_mutex_lock(&ztm->_mutex_peer);
+        z_mutex_lock(&ztm->_mutex_peer);
 
         it = ztm->_peers;
         while (it != NULL) {
@@ -160,7 +160,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);
+        z_mutex_unlock(&ztm->_mutex_peer);
     }
 #endif  // Z_MULTI_THREAD == 1
 
diff --git a/src/transport/multicast/link/task/read.c b/src/transport/multicast/link/task/read.c
index 36b8b7a0f..e6d6b072d 100644
--- a/src/transport/multicast/link/task/read.c
+++ b/src/transport/multicast/link/task/read.c
@@ -43,7 +43,7 @@ void *_zp_multicast_read_task(void *ztm_arg) {
     ztm->_read_task_running = true;
 
     // Acquire and keep the lock
-    _z_mutex_lock(&ztm->_mutex_rx);
+    z_mutex_lock(&ztm->_mutex_rx);
 
     // Prepare the buffer
     _z_zbuf_reset(&ztm->_zbuf);
@@ -112,7 +112,7 @@ void *_zp_multicast_read_task(void *ztm_arg) {
         _z_zbuf_set_rpos(&ztm->_zbuf, _z_zbuf_get_rpos(&ztm->_zbuf) + to_read);
     }
 
-    _z_mutex_unlock(&ztm->_mutex_rx);
+    z_mutex_unlock(&ztm->_mutex_rx);
 #endif  // Z_MULTI_THREAD == 1
 
     return NULL;
diff --git a/src/transport/multicast/link/tx.c b/src/transport/multicast/link/tx.c
index a84ab8a10..70ccbfd3b 100644
--- a/src/transport/multicast/link/tx.c
+++ b/src/transport/multicast/link/tx.c
@@ -44,7 +44,7 @@ int8_t _z_multicast_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport
 
 #if Z_MULTI_THREAD == 1
     // Acquire the lock
-    _z_mutex_lock(&ztm->_mutex_tx);
+    z_mutex_lock(&ztm->_mutex_tx);
 #endif  // Z_MULTI_THREAD == 1
 
     // Prepare the buffer eventually reserving space for the message length
@@ -63,7 +63,7 @@ int8_t _z_multicast_send_t_msg(_z_transport_multicast_t *ztm, const _z_transport
     }
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&ztm->_mutex_tx);
+    z_mutex_unlock(&ztm->_mutex_tx);
 #endif  // Z_MULTI_THREAD == 1
 
     return ret;
@@ -80,11 +80,11 @@ int8_t _z_multicast_send_z_msg(_z_session_t *zn, _z_zenoh_message_t *z_msg, z_re
     _Bool drop = false;
     if (cong_ctrl == Z_CONGESTION_CONTROL_BLOCK) {
 #if Z_MULTI_THREAD == 1
-        _z_mutex_lock(&ztm->_mutex_tx);
+        z_mutex_lock(&ztm->_mutex_tx);
 #endif  // Z_MULTI_THREAD == 1
     } else {
 #if Z_MULTI_THREAD == 1
-        int8_t locked = _z_mutex_trylock(&ztm->_mutex_tx);
+        int8_t locked = z_mutex_trylock(&ztm->_mutex_tx);
         if (locked != (int8_t)0) {
             _Z_INFO("Dropping zenoh message because of congestion control\n");
             // We failed to acquire the lock, drop the message
@@ -147,7 +147,7 @@ int8_t _z_multicast_send_z_msg(_z_session_t *zn, _z_zenoh_message_t *z_msg, z_re
         }
 
 #if Z_MULTI_THREAD == 1
-        _z_mutex_unlock(&ztm->_mutex_tx);
+        z_mutex_unlock(&ztm->_mutex_tx);
 #endif  // Z_MULTI_THREAD == 1
     }
 
diff --git a/src/transport/transport.c b/src/transport/transport.c
index 0abf6e2a5..d421c8749 100644
--- a/src/transport/transport.c
+++ b/src/transport/transport.c
@@ -81,11 +81,11 @@ int8_t _z_transport_unicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_unic
 
 #if Z_MULTI_THREAD == 1
     // Initialize the mutexes
-    ret = _z_mutex_init(&zt->_transport._unicast._mutex_tx);
+    ret = z_mutex_init(&zt->_transport._unicast._mutex_tx);
     if (ret == _Z_RES_OK) {
-        ret = _z_mutex_init(&zt->_transport._unicast._mutex_rx);
+        ret = z_mutex_init(&zt->_transport._unicast._mutex_rx);
         if (ret != _Z_RES_OK) {
-            _z_mutex_free(&zt->_transport._unicast._mutex_tx);
+            z_mutex_free(&zt->_transport._unicast._mutex_tx);
         }
     }
 #endif  // Z_MULTI_THREAD == 1
@@ -114,8 +114,8 @@ int8_t _z_transport_unicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_unic
             ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY;
 
 #if Z_MULTI_THREAD == 1
-            _z_mutex_free(&zt->_transport._unicast._mutex_tx);
-            _z_mutex_free(&zt->_transport._unicast._mutex_rx);
+            z_mutex_free(&zt->_transport._unicast._mutex_tx);
+            z_mutex_free(&zt->_transport._unicast._mutex_rx);
 #endif  // Z_MULTI_THREAD == 1
 
             _z_wbuf_clear(&zt->_transport._unicast._wbuf);
@@ -174,17 +174,17 @@ int8_t _z_transport_multicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_mu
 
 #if Z_MULTI_THREAD == 1
     // Initialize the mutexes
-    ret = _z_mutex_init(&zt->_transport._multicast._mutex_tx);
+    ret = z_mutex_init(&zt->_transport._multicast._mutex_tx);
     if (ret == _Z_RES_OK) {
-        ret = _z_mutex_init(&zt->_transport._multicast._mutex_rx);
+        ret = z_mutex_init(&zt->_transport._multicast._mutex_rx);
         if (ret == _Z_RES_OK) {
-            ret = _z_mutex_init(&zt->_transport._multicast._mutex_peer);
+            ret = z_mutex_init(&zt->_transport._multicast._mutex_peer);
             if (ret != _Z_RES_OK) {
-                _z_mutex_free(&zt->_transport._multicast._mutex_tx);
-                _z_mutex_free(&zt->_transport._multicast._mutex_rx);
+                z_mutex_free(&zt->_transport._multicast._mutex_tx);
+                z_mutex_free(&zt->_transport._multicast._mutex_rx);
             }
         } else {
-            _z_mutex_free(&zt->_transport._multicast._mutex_tx);
+            z_mutex_free(&zt->_transport._multicast._mutex_tx);
         }
     }
 #endif  // Z_MULTI_THREAD == 1
@@ -201,9 +201,9 @@ int8_t _z_transport_multicast(_z_transport_t *zt, _z_link_t *zl, _z_transport_mu
             ret = _Z_ERR_SYSTEM_OUT_OF_MEMORY;
 
 #if Z_MULTI_THREAD == 1
-            _z_mutex_free(&zt->_transport._multicast._mutex_tx);
-            _z_mutex_free(&zt->_transport._multicast._mutex_rx);
-            _z_mutex_free(&zt->_transport._multicast._mutex_peer);
+            z_mutex_free(&zt->_transport._multicast._mutex_tx);
+            z_mutex_free(&zt->_transport._multicast._mutex_rx);
+            z_mutex_free(&zt->_transport._multicast._mutex_peer);
 #endif  // Z_MULTI_THREAD == 1
 
             _z_wbuf_clear(&zt->_transport._multicast._wbuf);
@@ -419,8 +419,8 @@ void _z_transport_unicast_clear(_z_transport_unicast_t *ztu) {
     }
 
     // Clean up the mutexes
-    _z_mutex_free(&ztu->_mutex_tx);
-    _z_mutex_free(&ztu->_mutex_rx);
+    z_mutex_free(&ztu->_mutex_tx);
+    z_mutex_free(&ztu->_mutex_rx);
 #endif  // Z_MULTI_THREAD == 1
 
     // Clean up the buffers
@@ -449,9 +449,9 @@ void _z_transport_multicast_clear(_z_transport_multicast_t *ztm) {
     }
 
     // Clean up the mutexes
-    _z_mutex_free(&ztm->_mutex_tx);
-    _z_mutex_free(&ztm->_mutex_rx);
-    _z_mutex_free(&ztm->_mutex_peer);
+    z_mutex_free(&ztm->_mutex_tx);
+    z_mutex_free(&ztm->_mutex_rx);
+    z_mutex_free(&ztm->_mutex_peer);
 #endif  // Z_MULTI_THREAD == 1
 
     // Clean up the buffers
diff --git a/src/transport/unicast/link/rx.c b/src/transport/unicast/link/rx.c
index d8cd12a9e..c65f2dcb6 100644
--- a/src/transport/unicast/link/rx.c
+++ b/src/transport/unicast/link/rx.c
@@ -29,7 +29,7 @@ int8_t _z_unicast_recv_t_msg_na(_z_transport_unicast_t *ztu, _z_transport_messag
 
 #if Z_MULTI_THREAD == 1
     // Acquire the lock
-    _z_mutex_lock(&ztu->_mutex_rx);
+    z_mutex_lock(&ztu->_mutex_rx);
 #endif  // Z_MULTI_THREAD == 1
 
     // Prepare the buffer
@@ -73,7 +73,7 @@ int8_t _z_unicast_recv_t_msg_na(_z_transport_unicast_t *ztu, _z_transport_messag
     }
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&ztu->_mutex_rx);
+    z_mutex_unlock(&ztu->_mutex_rx);
 #endif  // Z_MULTI_THREAD == 1
 
     return ret;
diff --git a/src/transport/unicast/link/task/read.c b/src/transport/unicast/link/task/read.c
index 1046ba5e0..ff006326d 100644
--- a/src/transport/unicast/link/task/read.c
+++ b/src/transport/unicast/link/task/read.c
@@ -43,7 +43,7 @@ void *_zp_unicast_read_task(void *ztu_arg) {
     uint8_t ret;
 
     // Acquire and keep the lock
-    _z_mutex_lock(&ztu->_mutex_rx);
+    z_mutex_lock(&ztu->_mutex_rx);
 
     // Prepare the buffer
     _z_zbuf_reset(&ztu->_zbuf);
@@ -108,7 +108,7 @@ void *_zp_unicast_read_task(void *ztu_arg) {
         _z_zbuf_set_rpos(&ztu->_zbuf, _z_zbuf_get_rpos(&ztu->_zbuf) + to_read);
     }
 
-    _z_mutex_unlock(&ztu->_mutex_rx);
+    z_mutex_unlock(&ztu->_mutex_rx);
 #endif  // Z_MULTI_THREAD == 1
 
     return NULL;
diff --git a/src/transport/unicast/link/tx.c b/src/transport/unicast/link/tx.c
index 394be48cb..b0130bd04 100644
--- a/src/transport/unicast/link/tx.c
+++ b/src/transport/unicast/link/tx.c
@@ -44,7 +44,7 @@ int8_t _z_unicast_send_t_msg(_z_transport_unicast_t *ztu, const _z_transport_mes
 
 #if Z_MULTI_THREAD == 1
     // Acquire the lock
-    _z_mutex_lock(&ztu->_mutex_tx);
+    z_mutex_lock(&ztu->_mutex_tx);
 #endif  // Z_MULTI_THREAD == 1
 
     // Prepare the buffer eventually reserving space for the message length
@@ -63,7 +63,7 @@ int8_t _z_unicast_send_t_msg(_z_transport_unicast_t *ztu, const _z_transport_mes
     }
 
 #if Z_MULTI_THREAD == 1
-    _z_mutex_unlock(&ztu->_mutex_tx);
+    z_mutex_unlock(&ztu->_mutex_tx);
 #endif  // Z_MULTI_THREAD == 1
 
     return ret;
@@ -80,11 +80,11 @@ int8_t _z_unicast_send_z_msg(_z_session_t *zn, _z_zenoh_message_t *z_msg, z_reli
     _Bool drop = false;
     if (cong_ctrl == Z_CONGESTION_CONTROL_BLOCK) {
 #if Z_MULTI_THREAD == 1
-        _z_mutex_lock(&ztu->_mutex_tx);
+        z_mutex_lock(&ztu->_mutex_tx);
 #endif  // Z_MULTI_THREAD == 1
     } else {
 #if Z_MULTI_THREAD == 1
-        int8_t locked = _z_mutex_trylock(&ztu->_mutex_tx);
+        int8_t locked = z_mutex_trylock(&ztu->_mutex_tx);
         if (locked != (int8_t)0) {
             _Z_INFO("Dropping zenoh message because of congestion control\n");
             // We failed to acquire the lock, drop the message
@@ -147,7 +147,7 @@ int8_t _z_unicast_send_z_msg(_z_session_t *zn, _z_zenoh_message_t *z_msg, z_reli
         }
 
 #if Z_MULTI_THREAD == 1
-        _z_mutex_unlock(&ztu->_mutex_tx);
+        z_mutex_unlock(&ztu->_mutex_tx);
 #endif  // Z_MULTI_THREAD == 1
     }
 

From c214f3b56d3d2b594326b16b6801b12324a60269 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20Guimar=C3=A3es?= <carlos.em.guimaraes@gmail.com>
Date: Fri, 28 Jul 2023 13:42:12 +0200
Subject: [PATCH 5/7] Fix not in cmakelist

---
 CMakeLists.txt | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d713ffce3..8874a7130 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -263,7 +263,7 @@ if(BUILD_EXAMPLES)
 endif()
 
 if(BUILD_TOOLS)
-  if(BUILD_WITH_CUSTOM_ALLOCATOR)
+  if(NOT BUILD_WITH_CUSTOM_ALLOCATOR)
     set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tools)
     add_executable(z_keyexpr_canonizer ${PROJECT_SOURCE_DIR}/tools/z_keyexpr_canonizer.c)
     target_link_libraries(z_keyexpr_canonizer ${Libname})
@@ -273,7 +273,7 @@ endif()
 if(BUILD_TESTING)
   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
 
-  if(!BUILD_WITH_CUSTOM_ALLOCATOR)
+  if(NOT BUILD_WITH_CUSTOM_ALLOCATOR)
     add_executable(z_data_struct_test ${PROJECT_SOURCE_DIR}/tests/z_data_struct_test.c)
     add_executable(z_endpoint_test ${PROJECT_SOURCE_DIR}/tests/z_endpoint_test.c)
     add_executable(z_iobuf_test ${PROJECT_SOURCE_DIR}/tests/z_iobuf_test.c)
@@ -292,13 +292,15 @@ if(BUILD_TESTING)
     add_test(z_iobuf_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_iobuf_test)
     add_test(z_msgcodec_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_msgcodec_test)
     add_test(z_keyexpr_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_keyexpr_test)
+    add_test(z_api_null_drop_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_api_null_drop_test)
+    add_test(z_api_double_drop_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_api_double_drop_test)
   endif()
 endif()
 
 if(BUILD_MULTICAST)
   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
 
-  if(!BUILD_WITH_CUSTOM_ALLOCATOR)
+  if(NOT BUILD_WITH_CUSTOM_ALLOCATOR)
     if(CMAKE_C_STANDARD MATCHES "11")
       add_executable(z_peer_multicast_test ${PROJECT_SOURCE_DIR}/tests/z_peer_multicast_test.c)
       target_link_libraries(z_peer_multicast_test ${Libname})
@@ -314,7 +316,7 @@ endif()
 if(BUILD_INTEGRATION)
   set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
 
-  if(!BUILD_WITH_CUSTOM_ALLOCATOR)
+  if(NOT BUILD_WITH_CUSTOM_ALLOCATOR)
     if(CMAKE_C_STANDARD MATCHES "11")
       add_executable(z_client_test ${PROJECT_SOURCE_DIR}/tests/z_client_test.c)
       add_executable(z_api_alignment_test ${PROJECT_SOURCE_DIR}/tests/z_api_alignment_test.c)

From 0b0de313c55d86aa6fb0bca6f5067821baff67ae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20Guimar=C3=A3es?= <carlos.em.guimaraes@gmail.com>
Date: Fri, 28 Jul 2023 13:42:24 +0200
Subject: [PATCH 6/7] Add missing tests from the merge

---
 CMakeLists.txt | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8874a7130..7774f7194 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -279,12 +279,16 @@ if(BUILD_TESTING)
     add_executable(z_iobuf_test ${PROJECT_SOURCE_DIR}/tests/z_iobuf_test.c)
     add_executable(z_msgcodec_test ${PROJECT_SOURCE_DIR}/tests/z_msgcodec_test.c)
     add_executable(z_keyexpr_test ${PROJECT_SOURCE_DIR}/tests/z_keyexpr_test.c)
+    add_executable(z_api_null_drop_test ${PROJECT_SOURCE_DIR}/tests/z_api_null_drop_test.c)
+    add_executable(z_api_double_drop_test ${PROJECT_SOURCE_DIR}/tests/z_api_double_drop_test.c)
 
     target_link_libraries(z_data_struct_test ${Libname})
     target_link_libraries(z_endpoint_test ${Libname})
     target_link_libraries(z_iobuf_test ${Libname})
     target_link_libraries(z_msgcodec_test ${Libname})
     target_link_libraries(z_keyexpr_test ${Libname})
+    target_link_libraries(z_api_null_drop_test ${Libname})
+    target_link_libraries(z_api_double_drop_test ${Libname})
 
     enable_testing()
     add_test(z_data_struct_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/z_data_struct_test)

From cfa95f08f78173ac49e10f92f6f01b96f4ae7a4e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20Guimar=C3=A3es?= <carlos.em.guimaraes@gmail.com>
Date: Fri, 28 Jul 2023 14:00:13 +0200
Subject: [PATCH 7/7] Add local testing in the CI

---
 .github/workflows/testing.yaml | 52 ++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 .github/workflows/testing.yaml

diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml
new file mode 100644
index 000000000..6284a08de
--- /dev/null
+++ b/.github/workflows/testing.yaml
@@ -0,0 +1,52 @@
+#
+# Copyright (c) 2022 ZettaScale Technology
+#
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License 2.0 which is available at
+# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
+# which is available at https://www.apache.org/licenses/LICENSE-2.0.
+#
+# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
+#
+# Contributors:
+#   ZettaScale Zenoh Team, <zenoh@zettascale.tech>
+#
+name: testing
+
+on:
+  push:
+    branches: [ '**' ]
+  pull_request:
+    branches: [ '**' ]
+  schedule:
+    - cron: '0 6 * * 1-5'
+
+jobs:
+  build:
+
+    name: Build on ${{ matrix.os }}
+    runs-on: ${{ matrix.os }}
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [ ubuntu-latest, macOS-latest ]
+
+    steps:
+    - uses: actions/checkout@v2
+      
+    - name: Compile debug
+      run: make all
+      env:
+        BUILD_TYPE: Debug
+        BUILD_TESTING: ON
+        BUILD_MULTICAST: OFF
+        BUILD_INTEGRATION: OFF
+
+    - name: Test debug
+      run: make test
+      env:
+        BUILD_TYPE: Debug     # Workaround for Windows as it seems the previous step is being ignored
+        BUILD_TESTING: OFF    # Workaround for Windows as it seems the previous step is being ignored
+        BUILD_MULTICAST: OFF  # Workaround for Windows as it seems the previous step is being ignored
+        BUILD_INTEGRATION: ON # Workaround for Windows as it seems the previous step is being ignored
+        ZENOH_BRANCH: master