Skip to content

Commit

Permalink
feat: remove nop instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Jan 8, 2024
1 parent 203bae5 commit ebe338b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
6 changes: 0 additions & 6 deletions src/link/endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,7 @@ size_t _z_endpoint_config_strlen(const _z_str_intmap_t *s, const char *proto) {
#endif
if (_z_str_eq(proto, RAWETH_SCHEMA) == true) {
len = _z_raweth_config_strlen(s);
} else {
__asm__("nop");
}

return len;
}

Expand Down Expand Up @@ -398,10 +395,7 @@ char *_z_endpoint_config_to_str(const _z_str_intmap_t *s, const char *proto) {
#endif
if (_z_str_eq(proto, RAWETH_SCHEMA) == true) {
_z_raweth_config_to_str(s);
} else {
__asm__("nop");
}

return res;
}

Expand Down
8 changes: 2 additions & 6 deletions src/system/arduino/esp32/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,7 @@ int8_t _z_open_bt(_z_sys_net_socket_t *sock, const char *gname, uint8_t mode, ui
sock->_bts->begin(gname, true);
uint8_t connected = sock->_bts->connect(gname);
if (!connected) {
while (!sock->_bts->connected(tout)) {
__asm__("nop");
}
while (!sock->_bts->connected(tout));
}
} else {
delete sock->_bts;
Expand All @@ -583,9 +581,7 @@ int8_t _z_listen_bt(_z_sys_net_socket_t *sock, const char *gname, uint8_t mode,
sock->_bts->begin(gname, true);
uint8_t connected = sock->_bts->connect(gname);
if (!connected) {
while (!sock->_bts->connected(tout)) {
__asm__("nop");
}
while (!sock->_bts->connected(tout));
}
} else {
delete sock->_bts;
Expand Down
25 changes: 10 additions & 15 deletions src/system/unix/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@
uint8_t z_random_u8(void) {
uint8_t ret = 0;
#if defined(ZENOH_LINUX)
while (getrandom(&ret, sizeof(uint8_t), 0) <= 0) {
__asm__("nop");
}
while (getrandom(&ret, sizeof(uint8_t), 0) <= 0)
;
#elif defined(ZENOH_MACOS) || defined(ZENOH_BSD)
ret = z_random_u32();
#endif
Expand All @@ -44,9 +43,8 @@ uint8_t z_random_u8(void) {
uint16_t z_random_u16(void) {
uint16_t ret = 0;
#if defined(ZENOH_LINUX)
while (getrandom(&ret, sizeof(uint16_t), 0) <= 0) {
__asm__("nop");
}
while (getrandom(&ret, sizeof(uint16_t), 0) <= 0)
;
#elif defined(ZENOH_MACOS) || defined(ZENOH_BSD)
ret = z_random_u32();
#endif
Expand All @@ -57,9 +55,8 @@ uint16_t z_random_u16(void) {
uint32_t z_random_u32(void) {
uint32_t ret = 0;
#if defined(ZENOH_LINUX)
while (getrandom(&ret, sizeof(uint32_t), 0) <= 0) {
__asm__("nop");
}
while (getrandom(&ret, sizeof(uint32_t), 0) <= 0)
;
#elif defined(ZENOH_MACOS) || defined(ZENOH_BSD)
ret = arc4random();
#endif
Expand All @@ -70,9 +67,8 @@ uint32_t z_random_u32(void) {
uint64_t z_random_u64(void) {
uint64_t ret = 0;
#if defined(ZENOH_LINUX)
while (getrandom(&ret, sizeof(uint64_t), 0) <= 0) {
__asm__("nop");
}
while (getrandom(&ret, sizeof(uint64_t), 0) <= 0)
;
#elif defined(ZENOH_MACOS) || defined(ZENOH_BSD)
ret |= z_random_u32();
ret = ret << 32;
Expand All @@ -84,9 +80,8 @@ 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");
}
while (getrandom(buf, len, 0) <= 0)
;
#elif defined(ZENOH_MACOS) || defined(ZENOH_BSD)
arc4random_buf(buf, len);
#endif
Expand Down

0 comments on commit ebe338b

Please sign in to comment.