Skip to contentSkip to conversation

rwlock_is_locked undefined for UP systems

PATCH In review Prashanth T 6 participants 7 messages Jan 16, 2004 – Jan 19, 2004 Locking primitives

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rwlock_is_locked undefined for UP systems

Hi,
I had to use rwlock_is_locked( ) with linux2.6 for kdb and noticed that
this routine to be undefined for UP. I have attached the patch for 2.6.1 below to return 0 for rwlock_is_locked( ) on UP systems. Please let me know.

Thanks
Prashanth

include/linux/spinlock.h +1 -0
diff -urN linux-2.6.1/include/linux/spinlock.h linux-2.6.1-rwlock-patch/include/linux/spinlock.h
@@ -176,6 +176,7 @@
 #endif
 
 #define rwlock_init(lock)	do { (void)(lock); } while(0)
+#define rwlock_is_locked(lock)  ((void)(lock), 0)
 #define _raw_read_lock(lock)	do { (void)(lock); } while(0)
 #define _raw_read_unlock(lock)	do { (void)(lock); } while(0)
 #define _raw_write_lock(lock)	do { (void)(lock); } while(0)
#1 lore raw
Quoted 5 lines · Prashanth T

Hi,
I had to use rwlock_is_locked( ) with linux2.6 for kdb and noticed that
this routine to be undefined for UP. I have attached the patch for 2.6.1 below to return 0 for rwlock_is_locked( ) on UP systems.
Please let me know.

I consider any user of this on UP to be broken, just like UP use of spin_is_locked() is always a bug..... better a compiletime bug than a runtime bug I guess...

#2 lore raw
Quoted 10 lines · Arjan van de Ven
Quoted 5 lines · Prashanth T

Hi,
I had to use rwlock_is_locked( ) with linux2.6 for kdb and noticed that
this routine to be undefined for UP. I have attached the patch for 2.6.1 below to return 0 for rwlock_is_locked( ) on UP systems.
Please let me know.

I consider any user of this on UP to be broken, just like UP use of spin_is_locked() is always a bug..... better a compiletime bug than a runtime bug I guess...

Then maybe a #error explaining this is in order ?

- Joe

#3 lore raw
Quoted 8 lines · Joe Thornber
Quoted 7 lines · Arjan van de Ven
Quoted 5 lines · Prashanth T

Hi,
I had to use rwlock_is_locked( ) with linux2.6 for kdb and noticed that
this routine to be undefined for UP. I have attached the patch for 2.6.1 below to return 0 for rwlock_is_locked( ) on UP systems.
Please let me know.

Quoted 5 lines
Quoted 3 lines

I consider any user of this on UP to be broken, just like UP use of spin_is_locked() is always a bug..... better a compiletime bug than a runtime bug I guess...

Then maybe a #error explaining this is in order ?

So, if there is a function

void foo_locked(struct bar *obj)

{
    /* check that we are called with obj's lock held */
    BUG_ON(!rwlock_is_locked(&obj->lock));
    /* proceed with obj. */
}

it should now be changed to the

void foo_locked(struct bar *obj)
{

#ifdef CONFIG_SMP
    BUG_ON(!rwlock_is_locked(&obj->lock));
#endif
    /* proceed with obj. */
}

?

Quoted 3 lines

- Joe

Nikita.

Quoted 1 line
#4 lore raw
Quoted 9 lines · Nikita Danilov

it should now be changed to the

void foo_locked(struct bar *obj)
{

#ifdef CONFIG_SMP
    BUG_ON(!rwlock_is_locked(&obj->lock));
#endif
    /* proceed with obj. */
}

You forgot preempt... ;)

#5 lore raw
In reply to Prashanth T
Quoted 5 lines · Prashanth T

Hi,
I had to use rwlock_is_locked( ) with linux2.6 for kdb and noticed that
this routine to be undefined for UP. I have attached the patch for 2.6.1 below to return 0 for rwlock_is_locked( ) on UP systems.
Please let me know.

we don't implement spin_is_locked on UP either because there's no really usefull return value. The lock will never be taken on !SMP && !PREEMPT, but OTOH it's also not needed, so any assert on will give false results. And the assert is probably the only thing that the _is_locked routines could used for sanely.

#6 lore raw

ok....I understand that rwlock_is_locked( ) is to be protected by
CONFIG_SMP. But I was tempted when I saw spin_is_locked( )
to be returning zero for !SMP in include/linux/spinlock.h . Am I seeing something wrong here?

Quoted 20 lines · Christoph Hellwig
Quoted 7 lines · Prashanth T

Hi,
I had to use rwlock_is_locked( ) with linux2.6 for kdb and noticed that
this routine to be undefined for UP. I have attached the patch for 2.6.1 below to return 0 for rwlock_is_locked( ) on UP systems. Please let me know.

we don't implement spin_is_locked on UP either because there's no really usefull return value. The lock will never be taken on !SMP && !PREEMPT, but OTOH it's also not needed, so any assert on will give false results. And the assert is probably the only thing that the _is_locked routines could used for sanely.