Skip to content

Commit

Permalink
fix: remove read mutex double lock
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Dec 1, 2023
1 parent 55cc05e commit 66ca132
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/transport/raweth/lease.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ int8_t _zp_raweth_start_lease_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_
// Init memory
(void)memset(task, 0, sizeof(_z_task_t));
// Attach task
zt->_transport._multicast._lease_task = task;
zt->_transport._multicast._lease_task_running = true;
zt->_transport._raweth._lease_task = task;
zt->_transport._raweth._lease_task_running = true;
// Init task
if (_z_task_init(task, attr, _zp_raweth_lease_task, &zt->_transport._multicast) != _Z_RES_OK) {
zt->_transport._multicast._lease_task_running = false;
if (_z_task_init(task, attr, _zp_raweth_lease_task, &zt->_transport._raweth) != _Z_RES_OK) {
zt->_transport._raweth._lease_task_running = false;
return _Z_ERR_SYSTEM_TASK_FAILED;
}
return _Z_RES_OK;
}

int8_t _zp_raweth_stop_lease_task(_z_transport_t *zt) {
zt->_transport._multicast._lease_task_running = false;
zt->_transport._raweth._lease_task_running = false;
return _Z_RES_OK;
}

Expand Down
16 changes: 5 additions & 11 deletions src/transport/raweth/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ int8_t _zp_raweth_start_read_task(_z_transport_t *zt, _z_task_attr_t *attr, _z_t
// Init memory
(void)memset(task, 0, sizeof(_z_task_t));
// Attach task
zt->_transport._multicast._read_task = task;
zt->_transport._multicast._read_task_running = true;
zt->_transport._raweth._read_task = task;
zt->_transport._raweth._read_task_running = true;
// Init task
if (_z_task_init(task, attr, _zp_raweth_read_task, &zt->_transport._multicast) != _Z_RES_OK) {
zt->_transport._multicast._read_task_running = false;
if (_z_task_init(task, attr, _zp_raweth_read_task, &zt->_transport._raweth) != _Z_RES_OK) {
zt->_transport._raweth._read_task_running = false;
return _Z_ERR_SYSTEM_TASK_FAILED;
}
return _Z_RES_OK;
}

int8_t _zp_raweth_stop_read_task(_z_transport_t *zt) {
zt->_transport._multicast._read_task_running = false;
zt->_transport._raweth._read_task_running = false;
return _Z_RES_OK;
}

Expand All @@ -64,10 +64,6 @@ void *_zp_raweth_read_task(void *ztm_arg) {
_z_transport_message_t t_msg;
_z_bytes_t addr = _z_bytes_wrap(NULL, 0);

// Acquire and keep the lock
_z_mutex_lock(&ztm->_mutex_rx);
// Prepare the buffer
_z_zbuf_reset(&ztm->_zbuf);
// Task loop
while (ztm->_read_task_running == true) {
// Read message from link
Expand All @@ -87,8 +83,6 @@ void *_zp_raweth_read_task(void *ztm_arg) {
_z_t_msg_clear(&t_msg);
_z_bytes_clear(&addr);
}

_z_mutex_unlock(&ztm->_mutex_rx);
#endif // Z_FEATURE_MULTI_THREAD == 1

return NULL;
Expand Down
3 changes: 3 additions & 0 deletions src/transport/raweth/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ int8_t _z_raweth_recv_t_msg_na(_z_transport_multicast_t *ztm, _z_transport_messa
_z_mutex_lock(&ztm->_mutex_rx);
#endif // Z_FEATURE_MULTI_THREAD == 1

// Prepare the buffer
_z_zbuf_reset(&ztm->_zbuf);

switch (ztm->_link._cap._flow) {
// Datagram capable links
case Z_LINK_CAP_FLOW_DATAGRAM: {
Expand Down

0 comments on commit 66ca132

Please sign in to comment.