summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavi Merino <javi.merino@arm.com>2016-07-13 14:07:10 +0100
committerJuri Lelli <juri.lelli@gmail.com>2016-10-31 10:06:38 +0000
commitb194839fb9271d47c8100f98352789c8ba4e4d3a (patch)
treeba5abb9acf919492824904713b054af77c8a099a
parent31d7869e0b18f25651d7e48a8d67808f1b4af038 (diff)
rt-parse: avoid repetition in obj_is_event()
obj_is_event() is a boolean function that returns true if the name is an event. The two users of the function use it as a boolean function. The function has a lot of unnecessary copy&paste and duplication. Avoid repeating ourselves and just loop through all the events in an array. Signed-off-by: Javi Merino <javi.merino@arm.com>
-rw-r--r--src/rt-app_parse_config.c54
1 files changed, 26 insertions, 28 deletions
diff --git a/src/rt-app_parse_config.c b/src/rt-app_parse_config.c
index af18910..99b0e5e 100644
--- a/src/rt-app_parse_config.c
+++ b/src/rt-app_parse_config.c
@@ -550,37 +550,35 @@ unknown_event:
}
+static char *events[] = {
+ "lock",
+ "unlock",
+ "wait",
+ "signal",
+ "broad",
+ "sync",
+ "sleep",
+ "run",
+ "timer",
+ "suspend",
+ "resume",
+ "mem",
+ "iorun",
+ NULL
+};
+
static int
obj_is_event(char *name)
{
- if (!strncmp(name, "lock", strlen("lock")))
- return rtapp_mutex;
- if (!strncmp(name, "unlock", strlen("unlock")))
- return rtapp_lock;
- if (!strncmp(name, "wait", strlen("wait")))
- return rtapp_unlock;
- if (!strncmp(name, "signal", strlen("signal")))
- return rtapp_signal;
- if (!strncmp(name, "broad", strlen("broad")))
- return rtapp_broadcast;
- if (!strncmp(name, "sync", strlen("sync")))
- return rtapp_sig_and_wait;
- if (!strncmp(name, "sleep", strlen("sleep")))
- return rtapp_sleep;
- if (!strncmp(name, "run", strlen("run")))
- return rtapp_run;
- if (!strncmp(name, "timer", strlen("timer")))
- return rtapp_timer;
- if (!strncmp(name, "suspend", strlen("suspend")))
- return rtapp_suspend;
- if (!strncmp(name, "resume", strlen("resume")))
- return rtapp_resume;
- if (!strncmp(name, "mem", strlen("mem")))
- return rtapp_mem;
- if (!strncmp(name, "iorun", strlen("iorun")))
- return rtapp_iorun;
-
- return 0;
+ char **pos;
+
+ for (pos = events; *pos; pos++) {
+ char *event = *pos;
+ if (!strncmp(name, event, strlen(event)))
+ return 1;
+ }
+
+ return 0;
}
static void