Re: is there a spin_trylock_irqsave?

Robert Love (rml@tech9.net)
26 Feb 2002 21:27:37 -0500


On Tue, 2002-02-26 at 21:14, Gigi Sebastian Alapatt wrote:
>
> Is there a spin_trylock_irqsave?
>
> Basicially
>
> spin_once_trylock_irqsave?

No, although there is a spin_trylock_bh for whatever reason.

Implementing this would not be hard, you just need to disable irqs
_before_ spin_trylock to avoid a race. Something like:

int dog;
unsigned long flags;

local_irq_save(flags);
dog = spin_trylock(lock);
if (!dog)
local_irq_restore(flags);

Oh, I'll just attach a patch. Enjoy,

Robert Love

diff -urN linus/include/linux/spinlock.h linux/include/linux/spinlock.h
--- linus/include/linux/spinlock.h Tue Feb 26 20:17:12 2002
+++ linux/include/linux/spinlock.h Tue Feb 26 21:22:22 2002
@@ -38,6 +38,12 @@
__r = spin_trylock(lock); \
if (!__r) local_bh_enable(); \
__r; })
+#define spin_trylock_irqsave(lock, flags) ({ int __r; \
+ local_irq_save(flags); \
+ __r = spin_trylock(lock); \
+ if (!__r) \
+ local_irq_restore(flags); \
+ __r; })

/* Must define these before including other files, inline functions need them */

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/