xiaoxiang781216 commented on code in PR #10776:
URL: https://github.com/apache/nuttx/pull/10776#discussion_r1346235964


##########
include/nuttx/spinlock.h:
##########
@@ -285,7 +290,7 @@ void spin_unlock_wo_note(FAR volatile spinlock_t *lock);
  ****************************************************************************/
 
 /* bool spin_islocked(FAR spinlock_t lock); */
-#define spin_islocked(l) (*(l) == SP_LOCKED)
+#define spin_islocked(l) (*(l) != SP_UNLOCKED)

Review Comment:
   why change this



##########
include/nuttx/spinlock.h:
##########
@@ -51,6 +51,11 @@ typedef uint8_t spinlock_t;
 
 #include <arch/spinlock.h>
 
+#if defined(CONFIG_RW_SPINLOCK)

Review Comment:
   where you define CONFIG_RW_SPINLOCK?



##########
include/nuttx/spinlock.h:
##########
@@ -449,4 +454,98 @@ void spin_unlock_irqrestore_wo_note(FAR spinlock_t *lock, 
irqstate_t flags);
 #  define spin_unlock_irqrestore_wo_note(l, f) up_irq_restore(f)
 #endif
 
+#if defined(CONFIG_RW_SPINLOCK)
+
+/****************************************************************************
+ * Name: rw_read_spin_lock
+ *
+ * Description:
+ *   If this CPU does not already hold the spinlock, then loop until the
+ *   spinlock is successfully locked.
+ *
+ *   This implementation is non-reentrant and set a bit of lock.
+ *
+ *  The priority of reader is higher than writter if a reader hold the
+ *  lock, a new reader can get its lock but writer can't get this lock.
+ *
+ * Input Parameters:
+ *   lock - A reference to the spinlock object to lock.
+ *
+ * Returned Value:
+ *   None.  When the function returns, the spinlock was successfully locked
+ *   by this CPU.
+ *
+ * Assumptions:
+ *   Not running at the interrupt level.
+ *
+ ****************************************************************************/
+
+void rw_read_spin_lock(FAR volatile rw_spinlock_t *lock);
+
+/****************************************************************************
+ * Name: rw_read_spin_unlock
+ *
+ * Description:
+ *   Release a bit on a non-reentrant spinlock.
+ *
+ * Input Parameters:
+ *   lock - A reference to the spinlock object to unlock.
+ *
+ * Returned Value:
+ *   None.
+ *
+ * Assumptions:
+ *   Not running at the interrupt level.
+ *
+ ****************************************************************************/
+
+void rw_read_spin_unlock(FAR volatile rw_spinlock_t *lock);
+
+/****************************************************************************
+ * Name: rw_wrt_spin_lock
+ *
+ * Description:
+ *   If this CPU does not already hold the spinlock, then loop until the
+ *   spinlock is successfully locked.
+ *
+ *   This implementation is non-reentrant and set all bit on lock to avoid
+ *   readers and writers.
+ *
+ *  The priority of reader is higher than writter if a reader hold the
+ *  lock, a new reader can get its lock but writer can't get this lock.
+ *
+ * Input Parameters:
+ *   lock - A reference to the spinlock object to lock.
+ *
+ * Returned Value:
+ *   None.  When the function returns, the spinlock was successfully locked
+ *   by this CPU.
+ *
+ * Assumptions:
+ *   Not running at the interrupt level.
+ *
+ ****************************************************************************/
+
+void rw_wrt_spin_lock(FAR volatile rw_spinlock_t *lock);
+
+/****************************************************************************
+ * Name: rw_wrt_spin_unlock
+ *
+ * Description:
+ *   Release all bit on a non-reentrant spinlock.
+ *
+ * Input Parameters:
+ *   lock - A reference to the spinlock object to unlock.
+ *
+ * Returned Value:
+ *   None.
+ *
+ * Assumptions:
+ *   Not running at the interrupt level.
+ *
+ ****************************************************************************/
+
+void rw_wrt_spin_unlock(FAR volatile rw_spinlock_t *lock);

Review Comment:
   let's add irq and try version



##########
include/nuttx/spinlock.h:
##########
@@ -51,6 +51,11 @@ typedef uint8_t spinlock_t;
 
 #include <arch/spinlock.h>
 
+#if defined(CONFIG_RW_SPINLOCK)
+typedef uint32_t rw_spinlock_t;
+#  include <stdatomic.h>

Review Comment:
   move the inclusion to source file



##########
include/nuttx/spinlock.h:
##########
@@ -449,4 +454,98 @@ void spin_unlock_irqrestore_wo_note(FAR spinlock_t *lock, 
irqstate_t flags);
 #  define spin_unlock_irqrestore_wo_note(l, f) up_irq_restore(f)
 #endif
 
+#if defined(CONFIG_RW_SPINLOCK)
+
+/****************************************************************************
+ * Name: rw_read_spin_lock

Review Comment:
   let's use the same name from 
https://elixir.bootlin.com/linux/latest/source/include/linux/rwlock.h:
   rwlock_t, rwlock_init, read_trylock, write_trylock, read_lock, write_lock, 
read_unlock and write_unlock.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to