shced:sem: replace mutex with spinlock

The overhead of spinlok is less than mutext (mutex need to call
enter_critical section.)
After this patch, `down_write_trylock` and `down_read_trylock` can be
use in interrupt context.

The instruction is protected with mutex only one instruction so using
spinlock is better.

Signed-off-by: TaiJu Wu <tjwu1217@gmail.com>
This commit is contained in:
TaiJu Wu
2024-02-26 01:45:21 +00:00
committed by Xiang Xiao
parent a7389c0057
commit 23d65cb97f
2 changed files with 28 additions and 31 deletions
+7 -6
View File
@@ -25,7 +25,8 @@
* Included Files
****************************************************************************/
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/spinlock.h>
/****************************************************************************
* Public Type Definitions
@@ -33,11 +34,11 @@
typedef struct
{
mutex_t protected; /* Protecting Locks for Read/Write Locked Tables */
sem_t waiting; /* Reader/writer Waiting queue */
int waiter; /* Waiter Count */
int writer; /* Writer Count */
int reader; /* Reader Count */
spinlock_t protected;
sem_t waiting;
int waiter;
int writer;
int reader;
} rw_semaphore_t;
/****************************************************************************