Skip to content

Commit

Permalink
feat: switch transport mutex functions to static inline
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Oct 23, 2024
1 parent fc4b230 commit 32be1f4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 80 deletions.
36 changes: 29 additions & 7 deletions include/zenoh-pico/transport/multicast/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,32 @@ z_result_t _z_multicast_send_close(_z_transport_multicast_t *ztm, uint8_t reason
z_result_t _z_multicast_transport_close(_z_transport_multicast_t *ztm, uint8_t reason);
void _z_multicast_transport_clear(_z_transport_t *zt);

z_result_t _z_multicast_tx_mutex_lock(_z_transport_multicast_t *ztm, bool block);
void _z_multicast_tx_mutex_unlock(_z_transport_multicast_t *ztm);
void _z_multicast_rx_mutex_lock(_z_transport_multicast_t *ztm);
void _z_multicast_rx_mutex_unlock(_z_transport_multicast_t *ztm);
void _z_multicast_peer_mutex_lock(_z_transport_multicast_t *ztm);
void _z_multicast_peer_mutex_unlock(_z_transport_multicast_t *ztm);
#endif /* ZENOH_PICO_MULTICAST_TRANSPORT_H */
#if (Z_FEATURE_MULTICAST_TRANSPORT == 1 || Z_FEATURE_RAWETH_TRANSPORT == 1) && Z_FEATURE_MULTI_THREAD == 1
static inline z_result_t _z_multicast_tx_mutex_lock(_z_transport_multicast_t *ztm, bool block) {
if (block) {
_z_mutex_lock(&ztm->_mutex_tx);
return _Z_RES_OK;
} else {
return _z_mutex_try_lock(&ztm->_mutex_tx);
}
}
static inline void _z_multicast_tx_mutex_unlock(_z_transport_multicast_t *ztm) { _z_mutex_unlock(&ztm->_mutex_tx); }
static inline void _z_multicast_rx_mutex_lock(_z_transport_multicast_t *ztm) { _z_mutex_lock(&ztm->_mutex_rx); }
static inline void _z_multicast_rx_mutex_unlock(_z_transport_multicast_t *ztm) { _z_mutex_unlock(&ztm->_mutex_rx); }
static inline void _z_multicast_peer_mutex_lock(_z_transport_multicast_t *ztm) { _z_mutex_lock(&ztm->_mutex_peer); }
static inline void _z_multicast_peer_mutex_unlock(_z_transport_multicast_t *ztm) { _z_mutex_unlock(&ztm->_mutex_peer); }

#else
static inline z_result_t _z_multicast_tx_mutex_lock(_z_transport_multicast_t *ztm, bool block) {
_ZP_UNUSED(ztm);
_ZP_UNUSED(block);
return _Z_RES_OK;
}
static inline void _z_multicast_tx_mutex_unlock(_z_transport_multicast_t *ztm) { _ZP_UNUSED(ztm); }
static inline void _z_multicast_rx_mutex_lock(_z_transport_multicast_t *ztm) { _ZP_UNUSED(ztm); }
static inline void _z_multicast_rx_mutex_unlock(_z_transport_multicast_t *ztm) { _ZP_UNUSED(ztm); }
static inline void _z_multicast_peer_mutex_lock(_z_transport_multicast_t *ztm) { _ZP_UNUSED(ztm); }
static inline void _z_multicast_peer_mutex_unlock(_z_transport_multicast_t *ztm) { _ZP_UNUSED(ztm); }

#endif // (Z_FEATURE_MULTICAST_TRANSPORT == 1 || Z_FEATURE_RAWETH_TRANSPORT == 1) && Z_FEATURE_MULTI_THREAD == 1
#endif /* ZENOH_PICO_MULTICAST_TRANSPORT_H */
29 changes: 24 additions & 5 deletions include/zenoh-pico/transport/unicast/transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,27 @@ z_result_t _z_unicast_send_close(_z_transport_unicast_t *ztu, uint8_t reason, bo
z_result_t _z_unicast_transport_close(_z_transport_unicast_t *ztu, uint8_t reason);
void _z_unicast_transport_clear(_z_transport_t *zt);

z_result_t _z_unicast_tx_mutex_lock(_z_transport_unicast_t *ztu, z_congestion_control_t cc);
void _z_unicast_tx_mutex_unlock(_z_transport_unicast_t *ztu);
void _z_unicast_rx_mutex_lock(_z_transport_unicast_t *ztu);
void _z_unicast_rx_mutex_unlock(_z_transport_unicast_t *ztu);
#endif /* ZENOH_PICO_UNICAST_TRANSPORT_H */
#if Z_FEATURE_UNICAST_TRANSPORT == 1 && Z_FEATURE_MULTI_THREAD == 1
static inline z_result_t _z_unicast_tx_mutex_lock(_z_transport_unicast_t *ztu, bool block) {
if (block) {
_z_mutex_lock(&ztu->_mutex_tx);
return _Z_RES_OK;
} else {
return _z_mutex_try_lock(&ztu->_mutex_tx);
}
}
static inline void _z_unicast_tx_mutex_unlock(_z_transport_unicast_t *ztu) { _z_mutex_unlock(&ztu->_mutex_tx); }
static inline void _z_unicast_rx_mutex_lock(_z_transport_unicast_t *ztu) { _z_mutex_lock(&ztu->_mutex_rx); }
static inline void _z_unicast_rx_mutex_unlock(_z_transport_unicast_t *ztu) { _z_mutex_unlock(&ztu->_mutex_rx); }

#else
static inline z_result_t _z_unicast_tx_mutex_lock(_z_transport_unicast_t *ztu, bool block) {
_ZP_UNUSED(ztu);
_ZP_UNUSED(block);
return _Z_RES_OK;
}
static inline void _z_unicast_tx_mutex_unlock(_z_transport_unicast_t *ztu) { _ZP_UNUSED(ztu); }
static inline void _z_unicast_rx_mutex_lock(_z_transport_unicast_t *ztu) { _ZP_UNUSED(ztu); }
static inline void _z_unicast_rx_mutex_unlock(_z_transport_unicast_t *ztu) { _ZP_UNUSED(ztu); }
#endif // Z_FEATURE_UNICAST_TRANSPORT == 1 && Z_FEATURE_MULTI_THREAD == 1
#endif /* ZENOH_PICO_UNICAST_TRANSPORT_H */
39 changes: 0 additions & 39 deletions src/transport/multicast/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,44 +219,6 @@ void _z_multicast_transport_clear(_z_transport_t *zt) {
_z_link_clear(&ztm->_link);
}

#if Z_FEATURE_MULTI_THREAD == 1
z_result_t _z_multicast_tx_mutex_lock(_z_transport_multicast_t *ztm, bool block) {
if (block) {
_z_mutex_lock(&ztm->_mutex_tx);
return _Z_RES_OK;
} else {
return _z_mutex_try_lock(&ztm->_mutex_tx);
}
}

void _z_multicast_tx_mutex_unlock(_z_transport_multicast_t *ztm) { _z_mutex_unlock(&ztm->_mutex_tx); }

void _z_multicast_rx_mutex_lock(_z_transport_multicast_t *ztm) { _z_mutex_lock(&ztm->_mutex_rx); }

void _z_multicast_rx_mutex_unlock(_z_transport_multicast_t *ztm) { _z_mutex_unlock(&ztm->_mutex_rx); }

void _z_multicast_peer_mutex_lock(_z_transport_multicast_t *ztm) { _z_mutex_lock(&ztm->_mutex_peer); }

void _z_multicast_peer_mutex_unlock(_z_transport_multicast_t *ztm) { _z_mutex_unlock(&ztm->_mutex_peer); }

#else
z_result_t _z_multicast_tx_mutex_lock(_z_transport_multicast_t *ztm, bool block) {
_ZP_UNUSED(ztm);
_ZP_UNUSED(block);
return _Z_RES_OK;
}
void _z_multicast_tx_mutex_unlock(_z_transport_multicast_t *ztm) { _ZP_UNUSED(ztm); }

void _z_multicast_rx_mutex_lock(_z_transport_multicast_t *ztm) { _ZP_UNUSED(ztm); }

void _z_multicast_rx_mutex_unlock(_z_transport_multicast_t *ztm) { _ZP_UNUSED(ztm); }

void _z_multicast_peer_mutex_lock(_z_transport_multicast_t *ztm) { _ZP_UNUSED(ztm); }

void _z_multicast_peer_mutex_unlock(_z_transport_multicast_t *ztm) { _ZP_UNUSED(ztm); }

#endif // Z_FEATURE_MULTI_THREAD == 1

#else

z_result_t _z_multicast_transport_create(_z_transport_t *zt, _z_link_t *zl,
Expand Down Expand Up @@ -294,7 +256,6 @@ z_result_t _z_multicast_transport_close(_z_transport_multicast_t *ztm, uint8_t r
_ZP_UNUSED(ztm);
_ZP_UNUSED(reason);
return _Z_ERR_TRANSPORT_NOT_AVAILABLE;
;
}

void _z_multicast_transport_clear(_z_transport_t *zt) { _ZP_UNUSED(zt); }
Expand Down
29 changes: 0 additions & 29 deletions src/transport/unicast/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,35 +280,6 @@ void _z_unicast_transport_clear(_z_transport_t *zt) {
_z_link_clear(&ztu->_link);
}

#if Z_FEATURE_MULTI_THREAD == 1
z_result_t _z_unicast_tx_mutex_lock(_z_transport_unicast_t *ztu, bool block) {
if (block) {
_z_mutex_lock(&ztu->_mutex_tx);
return _Z_RES_OK;
} else {
return _z_mutex_try_lock(&ztu->_mutex_tx);
}
}

void _z_unicast_tx_mutex_unlock(_z_transport_unicast_t *ztu) { _z_mutex_unlock(&ztu->_mutex_tx); }

void _z_unicast_rx_mutex_lock(_z_transport_unicast_t *ztu) { _z_mutex_lock(&ztu->_mutex_rx); }

void _z_unicast_rx_mutex_unlock(_z_transport_unicast_t *ztu) { _z_mutex_unlock(&ztu->_mutex_rx); }

#else
z_result_t _z_unicast_tx_mutex_lock(_z_transport_unicast_t *ztu, z_congestion_control_t cc) {
_ZP_UNUSED(ztu);
_ZP_UNUSED(cc);
return _Z_RES_OK;
}
void _z_unicast_tx_mutex_unlock(_z_transport_unicast_t *ztu) { _ZP_UNUSED(ztu); }

void _z_unicast_rx_mutex_lock(_z_transport_unicast_t *ztu) { _ZP_UNUSED(ztu); }

void _z_unicast_rx_mutex_unlock(_z_transport_unicast_t *ztu) { _ZP_UNUSED(ztu); }
#endif // Z_FEATURE_MULTI_THREAD == 1

#else

z_result_t _z_unicast_transport_create(_z_transport_t *zt, _z_link_t *zl,
Expand Down

0 comments on commit 32be1f4

Please sign in to comment.