From 5cd65092967a1dbaa35bb7fdd80cf3a0e2f9cc9f Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sat, 28 Sep 2019 11:56:03 +0800 Subject: [Kernel] cleanup code of spinlock in SMP Kernel --- include/rthw.h | 12 ++---------- include/rtthread.h | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/rthw.h b/include/rthw.h index a77f2c1e46..2a602dcfe7 100644 --- a/include/rthw.h +++ b/include/rthw.h @@ -143,10 +143,10 @@ typedef union { } tickets; } rt_hw_spinlock_t; -typedef struct +struct rt_spinlock { rt_hw_spinlock_t lock; -} rt_spinlock_t; +}; void rt_hw_spin_lock_init(rt_hw_spinlock_t *lock); void rt_hw_spin_lock(rt_hw_spinlock_t *lock); @@ -187,16 +187,8 @@ void rt_hw_secondary_cpu_idle_exec(void); #define rt_hw_spin_lock(lock) *(lock) = rt_hw_interrupt_disable() #define rt_hw_spin_unlock(lock) rt_hw_interrupt_enable(*(lock)) -typedef int rt_spinlock_t; - #endif -void rt_spin_lock_init(rt_spinlock_t *lock); -void rt_spin_lock(rt_spinlock_t *lock); -void rt_spin_unlock(rt_spinlock_t *lock); -rt_base_t rt_spin_lock_irqsave(rt_spinlock_t *lock); -void rt_spin_unlock_irqrestore(rt_spinlock_t *lock, rt_base_t level); - #ifdef __cplusplus } #endif diff --git a/include/rtthread.h b/include/rtthread.h index d703f36268..13a1a4424b 100644 --- a/include/rtthread.h +++ b/include/rtthread.h @@ -391,6 +391,27 @@ rt_err_t rt_mq_recv(rt_mq_t mq, rt_err_t rt_mq_control(rt_mq_t mq, int cmd, void *arg); #endif +/* + * spinlock + */ +#ifdef RT_USING_SMP +struct rt_spinlock; + +void rt_spin_lock_init(struct rt_spinlock *lock); +void rt_spin_lock(struct rt_spinlock *lock); +void rt_spin_unlock(struct rt_spinlock *lock); +rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock); +void rt_spin_unlock_irqrestore(struct rt_spinlock *lock, rt_base_t level); + +#else +#define rt_spin_lock_init(lock) /* nothing */ +#define rt_spin_lock(lock) rt_enter_critical() +#define rt_spin_unlock(lock) rt_exit_critical() +#define rt_spin_lock_irqsave(lock) rt_hw_interrupt_disable() +#define rt_spin_unlock_irqrestore(lock, level) rt_hw_interrupt_enable(level) + +#endif + /**@}*/ #ifdef RT_USING_DEVICE -- cgit v1.3.1