summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-06-10 18:10:47 +0200
committerRichard Braun <rbraun@sceen.net>2017-06-10 18:10:47 +0200
commitbe23ca8c9643966e4c685b2d36ef5188e7be6e3e (patch)
tree22d1c3e00d4048481c7faf197e300a1ee1ff8ac9
parent656bf5c2445e691aec91367dee2c70509232f333 (diff)
kern/shell: new SHELL_REGISTER_CMDS macro
-rw-r--r--kern/shell.h14
-rw-r--r--kern/task.c8
-rw-r--r--kern/thread.c8
3 files changed, 17 insertions, 13 deletions
diff --git a/kern/shell.h b/kern/shell.h
index a33abbef..10bc8a38 100644
--- a/kern/shell.h
+++ b/kern/shell.h
@@ -21,6 +21,20 @@
#ifndef _KERN_SHELL_H
#define _KERN_SHELL_H
+#include <kern/error.h>
+#include <kern/macros.h>
+
+#define SHELL_REGISTER_CMDS(cmds) \
+MACRO_BEGIN \
+ size_t ___i; \
+ int ___error; \
+ \
+ for (___i = 0; ___i < ARRAY_SIZE(cmds); ___i++) { \
+ ___error = shell_cmd_register(&(cmds)[___i]); \
+ error_check(___error, __func__); \
+ } \
+MACRO_END
+
typedef void (*shell_fn_t)(int argc, char *argv[]);
struct shell_cmd {
diff --git a/kern/task.c b/kern/task.c
index 66b43bff..0b5217ee 100644
--- a/kern/task.c
+++ b/kern/task.c
@@ -99,19 +99,13 @@ static struct shell_cmd task_shell_cmds[] = {
void __init
task_setup(void)
{
- unsigned int i;
- int error;
-
kmem_cache_init(&task_cache, "task", sizeof(struct task), 0, NULL, 0);
list_init(&task_list);
spinlock_init(&task_list_lock);
task_init(kernel_task, "x15", kernel_map);
list_insert_head(&task_list, &kernel_task->node);
- for (i = 0; i < ARRAY_SIZE(task_shell_cmds); i++) {
- error = shell_cmd_register(&task_shell_cmds[i]);
- error_check(error, __func__);
- }
+ SHELL_REGISTER_CMDS(task_shell_cmds);
}
int
diff --git a/kern/thread.c b/kern/thread.c
index 25d81771..a753eb59 100644
--- a/kern/thread.c
+++ b/kern/thread.c
@@ -2282,8 +2282,7 @@ static struct shell_cmd thread_shell_cmds[] = {
void __init
thread_setup(void)
{
- unsigned int i;
- int cpu, error;
+ int cpu;
for (cpu = 1; (unsigned int)cpu < cpu_count(); cpu++) {
thread_bootstrap_common(cpu);
@@ -2302,10 +2301,7 @@ thread_setup(void)
thread_setup_runq(percpu_ptr(thread_runq, cpu));
}
- for (i = 0; i < ARRAY_SIZE(thread_shell_cmds); i++) {
- error = shell_cmd_register(&thread_shell_cmds[i]);
- error_check(error, __func__);
- }
+ SHELL_REGISTER_CMDS(thread_shell_cmds);
}
int