Skip to contentSkip to conversation

xen/common: rwlock: Constify the parameter of _rw_is{,_write}_locked()

PATCH In review Julien Grall 1 participant 2 messages Jan 30, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/common: rwlock: Constify the parameter of _rw_is{,_write}_locked()

From: Julien Grall <[email protected]>

The lock is not meant to be modified by _rw_is{,_write}_locked(). So constify it.

This is helpful to be able to assert if the lock is taken when the underlying structure is const.

---
 xen/include/xen/rwlock.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/include/xen/rwlock.h +2 -2
index b8d52a5aa939..e0d2b41c5c7e 100644
@@ -149,7 +149,7 @@ static inline void _read_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
     local_irq_restore(flags);
 }
 
-static inline int _rw_is_locked(rwlock_t *lock)
+static inline int _rw_is_locked(const rwlock_t *lock)
 {
     return atomic_read(&lock->cnts);
 }
@@ -254,7 +254,7 @@ static inline void _write_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
     local_irq_restore(flags);
 }
 
-static inline int _rw_is_write_locked(rwlock_t *lock)
+static inline int _rw_is_write_locked(const rwlock_t *lock)
 {
     return (atomic_read(&lock->cnts) & _QW_WMASK) == _QW_LOCKED;
 }
Signature · 1 line
2.38.1
#1 lore raw

Hi,

I forgot to CC the maintainers. Please ignore this version.

Cheers,

Quoted 35 lines · Julien Grall

From: Julien Grall <[email protected]>

The lock is not meant to be modified by _rw_is{,_write}_locked(). So constify it.

This is helpful to be able to assert if the lock is taken when the underlying structure is const.

---
  xen/include/xen/rwlock.h | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
xen/include/xen/rwlock.h +2 -2
index b8d52a5aa939..e0d2b41c5c7e 100644
@@ -149,7 +149,7 @@ static inline void _read_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
      local_irq_restore(flags);
  }
 
-static inline int _rw_is_locked(rwlock_t *lock)
+static inline int _rw_is_locked(const rwlock_t *lock)
  {
      return atomic_read(&lock->cnts);
  }
@@ -254,7 +254,7 @@ static inline void _write_unlock_irqrestore(rwlock_t *lock, unsigned long flags)
      local_irq_restore(flags);
  }
 
-static inline int _rw_is_write_locked(rwlock_t *lock)
+static inline int _rw_is_write_locked(const rwlock_t *lock)
  {
      return (atomic_read(&lock->cnts) & _QW_WMASK) == _QW_LOCKED;
  }
Signature · 1 line
Julien Grall