From 5bcd1dbb64137d478d525304c26b5558c1d91ae8 Mon Sep 17 00:00:00 2001 From: Ville Juven Date: Thu, 12 May 2022 09:49:44 +0300 Subject: [PATCH] sched: Remove task_restart in case of CONFIG_BUILD_KERNEL Same treatment as task_delete, this is not usable in kernel build either. --- include/sys/syscall_lookup.h | 2 +- sched/task/task_restart.c | 56 +++++++++++++++++++++++++++++------- syscall/syscall.csv | 2 +- 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/include/sys/syscall_lookup.h b/include/sys/syscall_lookup.h index 6af2547def..6da43cbe55 100644 --- a/include/sys/syscall_lookup.h +++ b/include/sys/syscall_lookup.h @@ -93,11 +93,11 @@ SYSCALL_LOOKUP(sem_wait, 1) SYSCALL_LOOKUP(task_create, 5) SYSCALL_LOOKUP(task_spawn, 6) SYSCALL_LOOKUP(task_delete, 1) + SYSCALL_LOOKUP(task_restart, 1) #else SYSCALL_LOOKUP(pgalloc, 2) #endif -SYSCALL_LOOKUP(task_restart, 1) SYSCALL_LOOKUP(task_setcancelstate, 2) SYSCALL_LOOKUP(up_assert, 2) diff --git a/sched/task/task_restart.c b/sched/task/task_restart.c index 8cad71ebc5..4047d786ff 100644 --- a/sched/task/task_restart.c +++ b/sched/task/task_restart.c @@ -41,7 +41,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: task_restart + * Name: nxtask_restart * * Description: * This function "restarts" a task. The task is first terminated and then @@ -53,8 +53,7 @@ * calling task. * * Returned Value: - * Zero (OK) on success; -1 (ERROR) on failure with the errno variable set - * appropriately. + * Zero (OK) on success; or negated errno on failure * * This function can fail if: * (1) A pid of zero or the pid of the calling task is provided @@ -63,13 +62,13 @@ * ****************************************************************************/ -int task_restart(pid_t pid) +int nxtask_restart(pid_t pid) { FAR struct tcb_s *rtcb; FAR struct task_tcb_s *tcb; FAR dq_queue_t *tasklist; irqstate_t flags; - int errcode; + int ret; #ifdef CONFIG_SMP int cpu; #endif @@ -81,7 +80,7 @@ int task_restart(pid_t pid) { /* Not implemented */ - errcode = ENOSYS; + ret = -ENOSYS; goto errout; } @@ -106,7 +105,7 @@ int task_restart(pid_t pid) { /* There is no TCB with this pid or, if there is, it is not a task. */ - errcode = ESRCH; + ret = -ESRCH; goto errout_with_lock; } @@ -187,10 +186,9 @@ int task_restart(pid_t pid) if (cpu >= 0) { - int ret = up_cpu_resume(cpu); + ret = up_cpu_resume(cpu); if (ret < 0) { - errcode = -ret; goto errout_with_lock; } } @@ -206,6 +204,42 @@ int task_restart(pid_t pid) errout_with_lock: leave_critical_section(flags); errout: - set_errno(errcode); - return ERROR; + return ret; } + +/**************************************************************************** + * Name: task_restart + * + * Description: + * This function "restarts" a task. The task is first terminated and then + * reinitialized with same ID, priority, original entry point, stack size, + * and parameters it had when it was first started. + * + * Input Parameters: + * pid - The task ID of the task to delete. An ID of zero signifies the + * calling task. + * + * Returned Value: + * Zero (OK) on success; -1 (ERROR) on failure with the errno variable set + * appropriately. + * + * This function can fail if: + * (1) A pid of zero or the pid of the calling task is provided + * (functionality not implemented) + * (2) The pid is not associated with any task known to the system. + * + ****************************************************************************/ + +#ifndef CONFIG_BUILD_KERNEL +int task_restart(pid_t pid) +{ + int ret = nxtask_restart(pid); + if (ret < 0) + { + set_errno(-ret); + ret = ERROR; + } + + return ret; +} +#endif diff --git a/syscall/syscall.csv b/syscall/syscall.csv index ede18e7113..0b903a42c0 100644 --- a/syscall/syscall.csv +++ b/syscall/syscall.csv @@ -173,7 +173,7 @@ "sysinfo","sys/sysinfo.h","","int","FAR struct sysinfo *" "task_create","sched.h","!defined(CONFIG_BUILD_KERNEL)", "int","FAR const char *","int","int","main_t","FAR char * const []|FAR char * const *" "task_delete","sched.h","!defined(CONFIG_BUILD_KERNEL)","int","pid_t" -"task_restart","sched.h","","int","pid_t" +"task_restart","sched.h","!defined(CONFIG_BUILD_KERNEL)","int","pid_t" "task_setcancelstate","sched.h","","int","int","FAR int *" "task_setcanceltype","sched.h","defined(CONFIG_CANCELLATION_POINTS)","int","int","FAR int *" "task_spawn","nuttx/spawn.h","!defined(CONFIG_BUILD_KERNEL)","int","FAR const char *","main_t","FAR const posix_spawn_file_actions_t *","FAR const posix_spawnattr_t *","FAR char * const []|FAR char * const *","FAR char * const []|FAR char * const *"