Skip to content

Commit

Permalink
Fix task cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Feb 3, 2025
1 parent 708b7a0 commit da2d45c
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/system/emscripten/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ z_result_t _z_task_cancel(_z_task_t *task) { _Z_CHECK_SYS_ERR(pthread_cancel(*ta

void _z_task_exit(void) { pthread_exit(NULL); }

void _z_task_free(_z_task_t **task) { *task = NULL; }
void _z_task_free(_z_task_t **task) {
_z_task_t *ptr = *task;
z_free(ptr);
*task = NULL;
}

/*------------------ Mutex ------------------*/
z_result_t _z_mutex_init(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_init(m, 0)); }
Expand Down
5 changes: 3 additions & 2 deletions src/system/espidf/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ z_result_t z_task_cancel(_z_task_t *task) {
void _z_task_exit(void) { vTaskDelete(NULL); }

void _z_task_free(_z_task_t **task) {
z_free((*task)->join_event);
z_free(*task);
_z_task_t *ptr = *task;
z_free(ptr->join_event);
z_free(ptr);
*task = NULL;
}

Expand Down
1 change: 1 addition & 0 deletions src/system/flipper/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ void _z_task_free(_z_task_t** task) {
return;
}
furi_thread_free(**task);
z_free(*task);
*task = NULL;
}

Expand Down
1 change: 1 addition & 0 deletions src/system/freertos_plus_tcp/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ void _z_task_exit(void) { vTaskDelete(NULL); }
void _z_task_free(_z_task_t **task) {
_z_task_t *ptr = *task;
vEventGroupDelete(ptr->join_event);
z_free(ptr);
*task = NULL;
}

Expand Down
5 changes: 3 additions & 2 deletions src/system/rpi_pico/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ z_result_t _z_task_cancel(_z_task_t *task) {
void _z_task_exit(void) { vTaskDelete(NULL); }

void _z_task_free(_z_task_t **task) {
z_free((*task)->join_event);
z_free(*task);
_z_task_t *ptr = *task;
z_free(ptr->join_event);
z_free(ptr);
*task = NULL;
}

Expand Down
6 changes: 5 additions & 1 deletion src/system/unix/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ z_result_t _z_task_cancel(_z_task_t *task) { _Z_CHECK_SYS_ERR(pthread_cancel(*ta

void _z_task_exit(void) { pthread_exit(NULL); }

void _z_task_free(_z_task_t **task) { *task = NULL; }
void _z_task_free(_z_task_t **task) {
_z_task_t *ptr = *task;
z_free(ptr);
*task = NULL;
}

/*------------------ Mutex ------------------*/
z_result_t _z_mutex_init(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_init(m, 0)); }
Expand Down
5 changes: 4 additions & 1 deletion src/system/windows/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ z_result_t _z_task_join(_z_task_t *task) {
z_result_t _z_task_detach(_z_task_t *task) {
z_result_t ret = _Z_RES_OK;
CloseHandle(*task);
*task = 0;
return ret;
}

Expand All @@ -92,7 +93,9 @@ void _z_task_exit(void) { ExitThread(0); }

void _z_task_free(_z_task_t **task) {
_z_task_t *ptr = *task;
CloseHandle(*ptr);
if (*ptr != 0) {
CloseHandle(*ptr);
}
z_free(ptr);
*task = NULL;
}
Expand Down
6 changes: 5 additions & 1 deletion src/system/zephyr/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ z_result_t _z_task_cancel(_z_task_t *task) { _Z_CHECK_SYS_ERR(pthread_cancel(*ta

void _z_task_exit(void) { pthread_exit(NULL); }

void _z_task_free(_z_task_t **task) { *task = NULL; }
void _z_task_free(_z_task_t **task) {
_z_task_t *ptr = *task;
z_free(ptr);
*task = NULL;
}

/*------------------ Mutex ------------------*/
z_result_t _z_mutex_init(_z_mutex_t *m) { _Z_CHECK_SYS_ERR(pthread_mutex_init(m, 0)); }
Expand Down
2 changes: 0 additions & 2 deletions src/transport/common/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ void _z_common_transport_clear(_z_transport_common_t *ztc, bool detach_tasks) {
_z_task_join(ztc->_read_task);
}
_z_task_free(&ztc->_read_task);
z_free(ztc->_read_task);
ztc->_read_task = NULL;
}
if (ztc->_lease_task != NULL) {
Expand All @@ -41,7 +40,6 @@ void _z_common_transport_clear(_z_transport_common_t *ztc, bool detach_tasks) {
_z_task_join(ztc->_lease_task);
}
_z_task_free(&ztc->_lease_task);
z_free(ztc->_lease_task);
ztc->_lease_task = NULL;
}

Expand Down
2 changes: 2 additions & 0 deletions src/transport/unicast/lease.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ static void _zp_unicast_failed(_z_transport_unicast_t *ztu) {
_Z_ERROR("Reopen failed: %i", ret);
}
#endif

_z_task_exit();
}

void *_zp_unicast_lease_task(void *ztu_arg) {
Expand Down

0 comments on commit da2d45c

Please sign in to comment.