lkml.org 
[lkml]   [2002]   [Feb]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: is there a spin_trylock_irqsave?
From
Date
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/

\
 
 \ /
  Last update: 2005-03-22 13:24    [W:0.031 / U:5.120 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site