From 7f7c7e293df050f75c023dcce7511352cd0aadc8 Mon Sep 17 00:00:00 2001 From: Heesub Shin Date: Thu, 6 Apr 2017 11:11:50 +0900 Subject: [PATCH] kernel/semaphore: fix broken macros Fixes compilation errors that might happen when CONFIG_PRIORITY_INHERITANCE is not set. Change-Id: I926c32914e928de03c11015aa64a63164f19d25c Signed-off-by: Gregory Nutt [Shin: backported 4c8ec0d2 from NuttX] Signed-off-by: Heesub Shin --- lib/libc/semaphore/Make.defs | 6 +----- lib/libc/semaphore/sem_getprotocol.c | 14 ++++++++------ os/include/tinyara/semaphore.h | 8 -------- os/kernel/semaphore/Make.defs | 4 ++-- os/kernel/semaphore/sem_setprotocol.c | 8 ++++---- os/syscall/syscall.csv | 2 +- 6 files changed, 16 insertions(+), 26 deletions(-) diff --git a/lib/libc/semaphore/Make.defs b/lib/libc/semaphore/Make.defs index 37f2056..56300e7 100644 --- a/lib/libc/semaphore/Make.defs +++ b/lib/libc/semaphore/Make.defs @@ -52,11 +52,7 @@ # Add the semaphore C files to the build -CSRCS += sem_init.c sem_getvalue.c - -ifeq ($(CONFIG_PRIORITY_INHERITANCE),y) -CSRCS += sem_getprotocol.c -endif +CSRCS += sem_init.c sem_getprotocol.c sem_getvalue.c # Add the semaphore directory to the build diff --git a/lib/libc/semaphore/sem_getprotocol.c b/lib/libc/semaphore/sem_getprotocol.c index 22be7a1..b7091a9 100644 --- a/lib/libc/semaphore/sem_getprotocol.c +++ b/lib/libc/semaphore/sem_getprotocol.c @@ -61,8 +61,6 @@ #include -#ifdef CONFIG_PRIORITY_INHERITANCE - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -89,11 +87,15 @@ int sem_getprotocol(FAR sem_t *sem, FAR int *protocol) { DEBUGASSERT(sem != NULL && protocol != NULL); +#ifdef CONFIG_PRIORITY_INHERITANCE if ((sem->flags & PRIOINHERIT_FLAGS_DISABLE) != 0) { - return SEM_PRIO_NONE; + *protocol = SEM_PRIO_NONE; } else { - return SEM_PRIO_INHERIT; + *protocol = SEM_PRIO_INHERIT; } -} +#else + *protocol = SEM_PRIO_NONE; +#endif -#endif /* CONFIG_PRIORITY_INHERITANCE */ + return OK; +} diff --git a/os/include/tinyara/semaphore.h b/os/include/tinyara/semaphore.h index f5db2a9..b84ee5b 100644 --- a/os/include/tinyara/semaphore.h +++ b/os/include/tinyara/semaphore.h @@ -162,11 +162,7 @@ int sem_reset(FAR sem_t *sem, int16_t count); * ****************************************************************************/ -#ifdef CONFIG_PRIORITY_INHERITANCE int sem_getprotocol(FAR sem_t *sem, FAR int *protocol); -#else -#define sem_getprotocol(s,p) do { *(p) == SEM_PRIO_NONE); } while (0) -#endif /**************************************************************************** * Function: sem_setprotocol @@ -204,11 +200,7 @@ int sem_getprotocol(FAR sem_t *sem, FAR int *protocol); * ****************************************************************************/ -#ifdef CONFIG_PRIORITY_INHERITANCE int sem_setprotocol(FAR sem_t *sem, int protocol); -#else -#define sem_setprotocol(s,p) ((p) == SEM_PRIO_NONE ? 0 : -ENOSYS); -#endif #undef EXTERN #ifdef __cplusplus diff --git a/os/kernel/semaphore/Make.defs b/os/kernel/semaphore/Make.defs index 5f0b1aa..4b90458 100644 --- a/os/kernel/semaphore/Make.defs +++ b/os/kernel/semaphore/Make.defs @@ -53,10 +53,10 @@ # Add semaphore-related files to the build CSRCS += sem_destroy.c sem_wait.c sem_trywait.c sem_timedwait.c -CSRCS += sem_post.c sem_recover.c sem_reset.c sem_waitirq.c +CSRCS += sem_post.c sem_recover.c sem_reset.c sem_setprotocol.c sem_waitirq.c ifeq ($(CONFIG_PRIORITY_INHERITANCE),y) -CSRCS += sem_initialize.c sem_holder.c sem_setprotocol.c +CSRCS += sem_initialize.c sem_holder.c endif # Include semaphore build support diff --git a/os/kernel/semaphore/sem_setprotocol.c b/os/kernel/semaphore/sem_setprotocol.c index 85ba240..e3eded7 100644 --- a/os/kernel/semaphore/sem_setprotocol.c +++ b/os/kernel/semaphore/sem_setprotocol.c @@ -63,8 +63,6 @@ #include "semaphore/semaphore.h" -#ifdef CONFIG_PRIORITY_INHERITANCE - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -113,6 +111,7 @@ int sem_setprotocol(FAR sem_t *sem, int protocol) switch (protocol) { case SEM_PRIO_NONE: +#ifdef CONFIG_PRIORITY_INHERITANCE /* Disable priority inheritance */ sem->flags |= PRIOINHERIT_FLAGS_DISABLE; @@ -120,13 +119,16 @@ int sem_setprotocol(FAR sem_t *sem, int protocol) /* Remove any current holders */ sem_destroyholder(sem); +#endif return OK; case SEM_PRIO_INHERIT: +#ifdef CONFIG_PRIORITY_INHERITANCE /* Enable priority inheritance (dangerous) */ sem->flags &= ~PRIOINHERIT_FLAGS_DISABLE; return OK; +#endif case SEM_PRIO_PROTECT: /* Not yet supported */ @@ -142,5 +144,3 @@ int sem_setprotocol(FAR sem_t *sem, int protocol) set_errno(errcode); return ERROR; } - -#endif /* CONFIG_PRIORITY_INHERITANCE */ diff --git a/os/syscall/syscall.csv b/os/syscall/syscall.csv index ed2677d..2bd106a 100644 --- a/os/syscall/syscall.csv +++ b/os/syscall/syscall.csv @@ -113,7 +113,7 @@ "sem_destroy", "semaphore.h", "", "int", "FAR sem_t*" "sem_open", "semaphore.h", "defined(CONFIG_FS_NAMED_SEMAPHORES)", "FAR sem_t*", "FAR const char*", "int", "..." "sem_post", "semaphore.h", "", "int", "FAR sem_t*" -"sem_setprotocol","tinyara/semaphore.h","defined(CONFIG_PRIORITY_INHERITANCE)","int","FAR sem_t*","int" +"sem_setprotocol","tinyara/semaphore.h","","int","FAR sem_t*","int" "sem_timedwait", "semaphore.h", "", "int", "FAR sem_t*", "FAR const struct timespec *" "sem_trywait", "semaphore.h", "", "int", "FAR sem_t*" "sem_unlink", "semaphore.h", "defined(CONFIG_FS_NAMED_SEMAPHORES)", "int", "FAR const char*" -- 2.7.4