From 981f105e17b5d473ec4e4279d27dbaf08c7cf102 Mon Sep 17 00:00:00 2001 From: zhangyuan29 Date: Mon, 4 Nov 2024 14:27:49 +0800 Subject: [PATCH] sched/semaphore: change semcount type to int Some memory on the ESP32 requires aligned access, so the semcount type has been changed to int. Signed-off-by: zhangyuan29 --- .../risc-v/src/common/espressif/platform_include/sys/lock.h | 2 +- .../xtensa/src/common/espressif/platform_include/sys/lock.h | 6 +++--- include/semaphore.h | 2 +- sched/semaphore/sem_destroy.c | 2 +- sched/semaphore/sem_post.c | 2 +- sched/semaphore/sem_reset.c | 2 +- sched/semaphore/sem_trywait.c | 4 ++-- sched/semaphore/sem_wait.c | 2 +- sched/semaphore/semaphore.h | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/arch/risc-v/src/common/espressif/platform_include/sys/lock.h b/arch/risc-v/src/common/espressif/platform_include/sys/lock.h index 4f177097bcf36..2f48b0a01637a 100644 --- a/arch/risc-v/src/common/espressif/platform_include/sys/lock.h +++ b/arch/risc-v/src/common/espressif/platform_include/sys/lock.h @@ -39,7 +39,7 @@ struct __lock { - int reserved[4]; + int reserved[6]; }; typedef _LOCK_T _lock_t; diff --git a/arch/xtensa/src/common/espressif/platform_include/sys/lock.h b/arch/xtensa/src/common/espressif/platform_include/sys/lock.h index 55ca1525908f7..db65336494bb2 100644 --- a/arch/xtensa/src/common/espressif/platform_include/sys/lock.h +++ b/arch/xtensa/src/common/espressif/platform_include/sys/lock.h @@ -41,12 +41,12 @@ struct __lock { #ifdef CONFIG_PRIORITY_INHERITANCE # if CONFIG_SEM_PREALLOCHOLDERS > 0 - int reserved[5]; + int reserved[7]; # else - int reserved[8]; + int reserved[10]; # endif #else - int reserved[4]; + int reserved[6]; #endif }; diff --git a/include/semaphore.h b/include/semaphore.h index bfd96cab57a81..f8f985818dab7 100644 --- a/include/semaphore.h +++ b/include/semaphore.h @@ -104,7 +104,7 @@ struct semholder_s struct sem_s { - volatile int16_t semcount; /* >0 -> Num counts available */ + volatile int semcount; /* >0 -> Num counts available */ /* <0 -> Num tasks waiting for semaphore */ /* If priority inheritance is enabled, then we have to keep track of which diff --git a/sched/semaphore/sem_destroy.c b/sched/semaphore/sem_destroy.c index fa94ef92ad456..26178e6fcab9c 100644 --- a/sched/semaphore/sem_destroy.c +++ b/sched/semaphore/sem_destroy.c @@ -60,7 +60,7 @@ int nxsem_destroy(FAR sem_t *sem) { - short old; + int old; DEBUGASSERT(sem != NULL); diff --git a/sched/semaphore/sem_post.c b/sched/semaphore/sem_post.c index 500b00f5954ce..8fc218e022686 100644 --- a/sched/semaphore/sem_post.c +++ b/sched/semaphore/sem_post.c @@ -259,7 +259,7 @@ int nxsem_post(FAR sem_t *sem) #if !defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_PRIORITY_PROTECT) if (sem->flags & SEM_TYPE_MUTEX) { - short old = 0; + int old = 0; if (atomic_compare_exchange_weak_explicit(NXSEM_COUNT(sem), &old, 1, memory_order_release, memory_order_relaxed)) diff --git a/sched/semaphore/sem_reset.c b/sched/semaphore/sem_reset.c index d7774ea504291..f24701c1be019 100644 --- a/sched/semaphore/sem_reset.c +++ b/sched/semaphore/sem_reset.c @@ -60,7 +60,7 @@ int nxsem_reset(FAR sem_t *sem, int16_t count) { irqstate_t flags; - short semcount; + int semcount; DEBUGASSERT(sem != NULL && count >= 0); diff --git a/sched/semaphore/sem_trywait.c b/sched/semaphore/sem_trywait.c index c4b512547bd7f..aa4e4fa445c57 100644 --- a/sched/semaphore/sem_trywait.c +++ b/sched/semaphore/sem_trywait.c @@ -64,7 +64,7 @@ static int nxsem_trywait_slow(FAR sem_t *sem) { FAR struct tcb_s *rtcb; irqstate_t flags; - short semcount; + int semcount; int ret; /* The following operations must be performed with interrupts disabled @@ -153,7 +153,7 @@ int nxsem_trywait(FAR sem_t *sem) #if !defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_PRIORITY_PROTECT) if (sem->flags & SEM_TYPE_MUTEX) { - short old = 1; + int old = 1; if (atomic_compare_exchange_weak_explicit(NXSEM_COUNT(sem), &old, 0, memory_order_acquire, memory_order_relaxed)) diff --git a/sched/semaphore/sem_wait.c b/sched/semaphore/sem_wait.c index a0a8b9d76f177..7a5a3dad7ab1f 100644 --- a/sched/semaphore/sem_wait.c +++ b/sched/semaphore/sem_wait.c @@ -259,7 +259,7 @@ int nxsem_wait(FAR sem_t *sem) #if !defined(CONFIG_PRIORITY_INHERITANCE) && !defined(CONFIG_PRIORITY_PROTECT) if (sem->flags & SEM_TYPE_MUTEX) { - short old = 1; + int old = 1; if (atomic_compare_exchange_weak_explicit(NXSEM_COUNT(sem), &old, 0, memory_order_acquire, memory_order_relaxed)) diff --git a/sched/semaphore/semaphore.h b/sched/semaphore/semaphore.h index 45f745f58bc26..d9af16894717f 100644 --- a/sched/semaphore/semaphore.h +++ b/sched/semaphore/semaphore.h @@ -40,7 +40,7 @@ * Pre-processor Definitions ****************************************************************************/ -#define NXSEM_COUNT(s) ((FAR atomic_short *)&(s)->semcount) +#define NXSEM_COUNT(s) ((FAR atomic_int *)&(s)->semcount) /**************************************************************************** * Public Function Prototypes