lkml.org 
[lkml]   [2008]   [Mar]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    SubjectRe: use of preempt_count instead of in_atomic() at leds-gpio.c
    Date
    corbet@lwn.net (Jonathan Corbet) writes:

    > diff --git a/include/linux/hardirq.h b/include/linux/hardirq.h
    > index 4982998..63a7782 100644
    > --- a/include/linux/hardirq.h
    > +++ b/include/linux/hardirq.h
    > @@ -72,6 +72,13 @@
    > #define in_softirq() (softirq_count())
    > #define in_interrupt() (irq_count())
    >
    > +/*
    > + * Are we running in atomic context? WARNING: this macro cannot
    > + * always detect atomic context; in particular, it cannot know about
    > + * held spinlocks in non-preemptible kernels. Thus it should not be
    > + * used in the general case to determine whether sleeping is possible.
    > + * Do not use in_atomic() in driver code.
    > + */
    > #define in_atomic() ((preempt_count() & ~PREEMPT_ACTIVE) != 0)
    >
    > #ifdef CONFIG_PREEMPT

    Is it just me who feels this comment that says "in_atomic() is not a way
    to tell if we are in atomic reliably and cannot be used for such and such"
    very reader-unfriendly? Ok, maybe the macro is not reliable and is not
    meant to be used for the purpose its name seems to suggest (at least to a
    non-kernel person). An inevitable question is, then what is it good for?
    What's the right situation to use this macro?

    I guess an additional comment "even if this says no, you could still be in
    atomic, but if this says yes, then you definitely are in atomic and cannot
    sleep" may help unconfuse a clueless reader like myself.


    \
     
     \ /
      Last update: 2008-03-25 09:55    [W:2.736 / U:0.232 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site