From 8ee8712564f452dae96d892bf95853fcd537128f Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Mon, 8 Jan 2024 16:50:25 +0100 Subject: [PATCH] feat: replace nops by configurable macro --- include/zenoh-pico/config.h | 7 +++++++ src/system/arduino/esp32/network.cpp | 4 ++-- src/system/unix/system.c | 10 +++++----- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/zenoh-pico/config.h b/include/zenoh-pico/config.h index c1bb5ad83..084981a3e 100644 --- a/include/zenoh-pico/config.h +++ b/include/zenoh-pico/config.h @@ -309,4 +309,11 @@ #define Z_FRAG_MAX_SIZE 300000 #endif +/** + * Default "nop" instruction + */ +#ifndef ZP_ASM_NOP +#define ZP_ASM_NOP __asm__("nop") +#endif + #endif /* INCLUDE_ZENOH_PICO_CONFIG_H */ diff --git a/src/system/arduino/esp32/network.cpp b/src/system/arduino/esp32/network.cpp index c088f1ce1..cac67f77b 100644 --- a/src/system/arduino/esp32/network.cpp +++ b/src/system/arduino/esp32/network.cpp @@ -558,7 +558,7 @@ int8_t _z_open_bt(_z_sys_net_socket_t *sock, const char *gname, uint8_t mode, ui uint8_t connected = sock->_bts->connect(gname); if (!connected) { while (!sock->_bts->connected(tout)) { - __asm__("nop"); + ZP_ASM_NOP; } } } else { @@ -584,7 +584,7 @@ int8_t _z_listen_bt(_z_sys_net_socket_t *sock, const char *gname, uint8_t mode, uint8_t connected = sock->_bts->connect(gname); if (!connected) { while (!sock->_bts->connected(tout)) { - __asm__("nop"); + ZP_ASM_NOP; } } } else { diff --git a/src/system/unix/system.c b/src/system/unix/system.c index 28223b83f..de5e4e505 100644 --- a/src/system/unix/system.c +++ b/src/system/unix/system.c @@ -32,7 +32,7 @@ uint8_t z_random_u8(void) { uint8_t ret = 0; #if defined(ZENOH_LINUX) while (getrandom(&ret, sizeof(uint8_t), 0) <= 0) { - __asm__("nop"); + ZP_ASM_NOP; } #elif defined(ZENOH_MACOS) || defined(ZENOH_BSD) ret = z_random_u32(); @@ -45,7 +45,7 @@ uint16_t z_random_u16(void) { uint16_t ret = 0; #if defined(ZENOH_LINUX) while (getrandom(&ret, sizeof(uint16_t), 0) <= 0) { - __asm__("nop"); + ZP_ASM_NOP; } #elif defined(ZENOH_MACOS) || defined(ZENOH_BSD) ret = z_random_u32(); @@ -58,7 +58,7 @@ uint32_t z_random_u32(void) { uint32_t ret = 0; #if defined(ZENOH_LINUX) while (getrandom(&ret, sizeof(uint32_t), 0) <= 0) { - __asm__("nop"); + ZP_ASM_NOP; } #elif defined(ZENOH_MACOS) || defined(ZENOH_BSD) ret = arc4random(); @@ -71,7 +71,7 @@ uint64_t z_random_u64(void) { uint64_t ret = 0; #if defined(ZENOH_LINUX) while (getrandom(&ret, sizeof(uint64_t), 0) <= 0) { - __asm__("nop"); + ZP_ASM_NOP; } #elif defined(ZENOH_MACOS) || defined(ZENOH_BSD) ret |= z_random_u32(); @@ -85,7 +85,7 @@ uint64_t z_random_u64(void) { void z_random_fill(void *buf, size_t len) { #if defined(ZENOH_LINUX) while (getrandom(buf, len, 0) <= 0) { - __asm__("nop"); + ZP_ASM_NOP; } #elif defined(ZENOH_MACOS) || defined(ZENOH_BSD) arc4random_buf(buf, len);