Skip to content

Commit

Permalink
feat: switch tasks to zp namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-roland committed Jan 8, 2024
1 parent 474e9b6 commit 6df2e19
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 55 deletions.
8 changes: 4 additions & 4 deletions include/zenoh-pico/system/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ void z_free(void *ptr);

#if Z_FEATURE_MULTI_THREAD == 1
/*------------------ Thread ------------------*/
int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg);
int8_t z_task_join(z_task_t *task);
int8_t z_task_cancel(z_task_t *task);
void z_task_free(z_task_t **task);
int8_t zp_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg);
int8_t zp_task_join(z_task_t *task);
int8_t zp_task_cancel(z_task_t *task);
void zp_task_free(z_task_t **task);

/*------------------ Mutex ------------------*/
int8_t z_mutex_init(z_mutex_t *m);
Expand Down
10 changes: 5 additions & 5 deletions src/system/arduino/esp32/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void z_task_wrapper(z_task_arg *targ) {
}

/*------------------ Task ------------------*/
int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) {
int8_t zp_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) {
int ret = 0;

z_task_arg *z_arg = (z_task_arg *)z_malloc(sizeof(z_task_arg));
Expand All @@ -77,17 +77,17 @@ int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), vo
return ret;
}

int8_t z_task_join(z_task_t *task) {
int8_t zp_task_join(z_task_t *task) {
// Note: task/thread join not supported on FreeRTOS API, so we force its deletion instead.
return z_task_cancel(task);
return zp_task_cancel(task);
}

int8_t z_task_cancel(z_task_t *task) {
int8_t zp_task_cancel(z_task_t *task) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
vTaskDelete(*task);
return 0;
}

void z_task_free(z_task_t **task) {
void zp_task_free(z_task_t **task) {
z_task_t *ptr = *task;
z_free(ptr);
*task = NULL;
Expand Down
8 changes: 4 additions & 4 deletions src/system/arduino/opencr/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ void z_free(void *ptr) {
#error "Multi-threading not supported yet on OpenCR port. Disable it by defining Z_FEATURE_MULTI_THREAD=0"

/*------------------ Task ------------------*/
int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { return -1; }
int8_t zp_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) { return -1; }

int8_t z_task_join(z_task_t *task) { return -1; }
int8_t zp_task_join(z_task_t *task) { return -1; }

int8_t z_task_cancel(z_task_t *task) { return -1; }
int8_t zp_task_cancel(z_task_t *task) { return -1; }

void z_task_free(z_task_t **task) {
void zp_task_free(z_task_t **task) {
z_task_t *ptr = *task;
z_free(ptr);
*task = NULL;
Expand Down
8 changes: 4 additions & 4 deletions src/system/emscripten/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ void z_free(void *ptr) { free(ptr); }

#if Z_FEATURE_MULTI_THREAD == 1
/*------------------ Task ------------------*/
int8_t z_task_init(z_task_t *task, pthread_attr_t *attr, void *(*fun)(void *), void *arg) {
int8_t zp_task_init(z_task_t *task, pthread_attr_t *attr, void *(*fun)(void *), void *arg) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
return pthread_create(task, attr, fun, arg);
}

int8_t z_task_join(z_task_t *task) { return pthread_join(*task, NULL); }
int8_t zp_task_join(z_task_t *task) { return pthread_join(*task, NULL); }

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file

int8_t z_task_cancel(z_task_t *task) { return pthread_cancel(*task); }
int8_t zp_task_cancel(z_task_t *task) { return pthread_cancel(*task); }

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file

void z_task_free(z_task_t **task) {
void zp_task_free(z_task_t **task) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
z_task_t *ptr = *task;
z_free(ptr);
*task = NULL;
Expand Down
10 changes: 5 additions & 5 deletions src/system/espidf/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void z_task_wrapper(z_task_arg *targ) {
}

/*------------------ Task ------------------*/
int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) {
int8_t zp_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 207 with no text in the supplied rule-texts-file Warning

misra violation 207 with no text in the supplied rule-texts-file
int ret = 0;

z_task_arg *z_arg = (z_task_arg *)z_malloc(sizeof(z_task_arg));

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 11.5 rule Note

MISRA 11.5 rule
Expand All @@ -78,17 +78,17 @@ int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), vo
return ret;
}

int8_t z_task_join(z_task_t *task) {
int8_t zp_task_join(z_task_t *task) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
// Note: task/thread join not supported on FreeRTOS API, so we force its deletion instead.
return z_task_cancel(task);
return zp_task_cancel(task);
}

int8_t z_task_cancel(z_task_t *task) {
int8_t zp_task_cancel(z_task_t *task) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
vTaskDelete(*task);
return 0;
}

void z_task_free(z_task_t **task) {
void zp_task_free(z_task_t **task) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
z_task_t *ptr = *task;
z_free(ptr);
*task = NULL;
Expand Down
8 changes: 4 additions & 4 deletions src/system/freertos_plus_tcp/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static z_task_attr_t z_default_task_attr = {
};

/*------------------ Thread ------------------*/
int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) {
int8_t zp_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
z_task_arg *z_arg = (z_task_arg *)z_malloc(sizeof(z_task_arg));

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 11.5 rule Note

MISRA 11.5 rule
if (z_arg == NULL) {
return -1;
Expand Down Expand Up @@ -119,17 +119,17 @@ int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), vo
return 0;
}

int8_t z_task_join(z_task_t *task) {
int8_t zp_task_join(z_task_t *task) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
xEventGroupWaitBits(task->join_event, 1, pdFALSE, pdFALSE, portMAX_DELAY);
return 0;
}

int8_t z_task_cancel(z_task_t *task) {
int8_t zp_task_cancel(z_task_t *task) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
vTaskDelete(task->handle);
return 0;
}

void z_task_free(z_task_t **task) {
void zp_task_free(z_task_t **task) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
z_free((*task)->join_event);
z_free(*task);
}
Expand Down
8 changes: 4 additions & 4 deletions src/system/mbed/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@ void z_free(void *ptr) { free(ptr); }

#if Z_FEATURE_MULTI_THREAD == 1
/*------------------ Task ------------------*/
int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) {
int8_t zp_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) {
*task = new Thread();
mbed::Callback<void()> c = mbed::Callback<void()>(fun, arg);
return ((Thread *)*task)->start(c);
}

int8_t z_task_join(z_task_t *task) {
int8_t zp_task_join(z_task_t *task) {
int res = ((Thread *)*task)->join();
delete ((Thread *)*task);
return res;
}

int8_t z_task_cancel(z_task_t *task) {
int8_t zp_task_cancel(z_task_t *task) {
int res = ((Thread *)*task)->terminate();
delete ((Thread *)*task);
return res;
}

void z_task_free(z_task_t **task) {
void zp_task_free(z_task_t **task) {
z_task_t *ptr = *task;
z_free(ptr);
*task = NULL;
Expand Down
8 changes: 4 additions & 4 deletions src/system/unix/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ void z_free(void *ptr) { free(ptr); }

#if Z_FEATURE_MULTI_THREAD == 1
/*------------------ Task ------------------*/
int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) {
int8_t zp_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
return pthread_create(task, attr, fun, arg);
}

int8_t z_task_join(z_task_t *task) { return pthread_join(*task, NULL); }
int8_t zp_task_join(z_task_t *task) { return pthread_join(*task, NULL); }

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file

int8_t z_task_cancel(z_task_t *task) { return pthread_cancel(*task); }
int8_t zp_task_cancel(z_task_t *task) { return pthread_cancel(*task); }

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file

void z_task_free(z_task_t **task) {
void zp_task_free(z_task_t **task) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
z_task_t *ptr = *task;
z_free(ptr);
*task = NULL;
Expand Down
8 changes: 4 additions & 4 deletions src/system/windows/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void z_free(void *ptr) { free(ptr); }

#if Z_FEATURE_MULTI_THREAD == 1
/*------------------ Task ------------------*/
int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) {
int8_t zp_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
(void)(attr);
int8_t ret = _Z_RES_OK;
*task = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)fun, arg, 0, NULL);
Expand All @@ -70,19 +70,19 @@ int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), vo
return ret;
}

int8_t z_task_join(z_task_t *task) {
int8_t zp_task_join(z_task_t *task) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
int8_t ret = _Z_RES_OK;
WaitForSingleObject(*task, INFINITE);
return ret;
}

int8_t z_task_cancel(z_task_t *task) {
int8_t zp_task_cancel(z_task_t *task) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
int8_t ret = _Z_RES_OK;
TerminateThread(*task, 0);
return ret;
}

void z_task_free(z_task_t **task) {
void zp_task_free(z_task_t **task) {

Check warning

Code scanning / Cppcheck (reported by Codacy)

misra violation 804 with no text in the supplied rule-texts-file Warning

misra violation 804 with no text in the supplied rule-texts-file
z_task_t *ptr = *task;
CloseHandle(*ptr);
z_free(ptr);
Expand Down
8 changes: 4 additions & 4 deletions src/system/zephyr/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ K_THREAD_STACK_ARRAY_DEFINE(thread_stack_area, Z_THREADS_NUM, Z_PTHREAD_STACK_SI
static int thread_index = 0;

/*------------------ Task ------------------*/
int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) {
int8_t zp_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), void *arg) {
z_task_attr_t *lattr = NULL;
z_task_attr_t tmp;
if (attr == NULL) {
Expand All @@ -83,11 +83,11 @@ int8_t z_task_init(z_task_t *task, z_task_attr_t *attr, void *(*fun)(void *), vo
return pthread_create(task, lattr, fun, arg);
}

int8_t z_task_join(z_task_t *task) { return pthread_join(*task, NULL); }
int8_t zp_task_join(z_task_t *task) { return pthread_join(*task, NULL); }

int8_t z_task_cancel(z_task_t *task) { return pthread_cancel(*task); }
int8_t zp_task_cancel(z_task_t *task) { return pthread_cancel(*task); }

void z_task_free(z_task_t **task) {
void zp_task_free(z_task_t **task) {
z_task_t *ptr = *task;
z_free(ptr);
*task = NULL;
Expand Down
2 changes: 1 addition & 1 deletion src/transport/multicast/lease.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ int8_t _zp_multicast_start_lease_task(_z_transport_multicast_t *ztm, z_task_attr
// Init memory
(void)memset(task, 0, sizeof(z_task_t));
// Init task
if (z_task_init(task, attr, _zp_multicast_lease_task, ztm) != _Z_RES_OK) {
if (zp_task_init(task, attr, _zp_multicast_lease_task, ztm) != _Z_RES_OK) {
return _Z_ERR_SYSTEM_TASK_FAILED;
}
// Attach task
Expand Down
2 changes: 1 addition & 1 deletion src/transport/multicast/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ int8_t _zp_multicast_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, z_
// Init memory
(void)memset(task, 0, sizeof(z_task_t));
// Init task
if (z_task_init(task, attr, _zp_multicast_read_task, &zt->_transport._multicast) != _Z_RES_OK) {
if (zp_task_init(task, attr, _zp_multicast_read_task, &zt->_transport._multicast) != _Z_RES_OK) {
return _Z_ERR_SYSTEM_TASK_FAILED;
}
// Attach task
Expand Down
8 changes: 4 additions & 4 deletions src/transport/multicast/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ void _z_multicast_transport_clear(_z_transport_t *zt) {
#if Z_FEATURE_MULTI_THREAD == 1
// Clean up tasks
if (ztm->_read_task != NULL) {
z_task_join(ztm->_read_task);
z_task_free(&ztm->_read_task);
zp_task_join(ztm->_read_task);
zp_task_free(&ztm->_read_task);
}
if (ztm->_lease_task != NULL) {
z_task_join(ztm->_lease_task);
z_task_free(&ztm->_lease_task);
zp_task_join(ztm->_lease_task);
zp_task_free(&ztm->_lease_task);
}
// Clean up the mutexes
z_mutex_free(&ztm->_mutex_tx);
Expand Down
2 changes: 1 addition & 1 deletion src/transport/raweth/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ int8_t _zp_raweth_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, z_tas
// Init memory
(void)memset(task, 0, sizeof(z_task_t));
// Init task
if (z_task_init(task, attr, _zp_raweth_read_task, &zt->_transport._raweth) != _Z_RES_OK) {
if (zp_task_init(task, attr, _zp_raweth_read_task, &zt->_transport._raweth) != _Z_RES_OK) {
return _Z_ERR_SYSTEM_TASK_FAILED;
}
// Attach task
Expand Down
2 changes: 1 addition & 1 deletion src/transport/unicast/lease.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int8_t _zp_unicast_start_lease_task(_z_transport_t *zt, z_task_attr_t *attr, z_t
// Init memory
(void)memset(task, 0, sizeof(z_task_t));
// Init task
if (z_task_init(task, attr, _zp_unicast_lease_task, &zt->_transport._unicast) != _Z_RES_OK) {
if (zp_task_init(task, attr, _zp_unicast_lease_task, &zt->_transport._unicast) != _Z_RES_OK) {
return _Z_ERR_SYSTEM_TASK_FAILED;
}
// Attach task
Expand Down
2 changes: 1 addition & 1 deletion src/transport/unicast/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int8_t _zp_unicast_start_read_task(_z_transport_t *zt, z_task_attr_t *attr, z_ta
// Init memory
(void)memset(task, 0, sizeof(z_task_t));
// Init task
if (z_task_init(task, attr, _zp_unicast_read_task, &zt->_transport._unicast) != _Z_RES_OK) {
if (zp_task_init(task, attr, _zp_unicast_read_task, &zt->_transport._unicast) != _Z_RES_OK) {
return _Z_ERR_SYSTEM_TASK_FAILED;
}
// Attach task
Expand Down
8 changes: 4 additions & 4 deletions src/transport/unicast/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,12 @@ void _z_unicast_transport_clear(_z_transport_t *zt) {
#if Z_FEATURE_MULTI_THREAD == 1
// Clean up tasks
if (ztu->_read_task != NULL) {
z_task_join(ztu->_read_task);
z_task_free(&ztu->_read_task);
zp_task_join(ztu->_read_task);
zp_task_free(&ztu->_read_task);
}
if (ztu->_lease_task != NULL) {
z_task_join(ztu->_lease_task);
z_task_free(&ztu->_lease_task);
zp_task_join(ztu->_lease_task);
zp_task_free(&ztu->_lease_task);
}

// Clean up the mutexes
Expand Down

0 comments on commit 6df2e19

Please sign in to comment.