Skip to content

Commit

Permalink
feat: replace nops by configurable macro
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Jan 8, 2024
1 parent 0869657 commit 8ee8712
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
7 changes: 7 additions & 0 deletions include/zenoh-pico/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
4 changes: 2 additions & 2 deletions src/system/arduino/esp32/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions src/system/unix/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit 8ee8712

Please sign in to comment.