Re: [PATCH v4] introduce macro spin_event_timeout()

From: Grant Likely
Date: Thu Mar 12 2009 - 12:01:43 EST


On Thu, Mar 12, 2009 at 9:54 AM, Timur Tabi <timur@xxxxxxxxxxxxx> wrote:
> On Wed, Mar 11, 2009 at 9:45 PM, Grant Likely <grant.likely@xxxxxxxxxxxx> wrote:
>
>>> The other big advantage of that approach is that drivers that aren't in
>>> an atomic section can use msleep() and allow the kernel to schedule on
>>> that processor.
>>
>> Ack!  I totally agree.
>
> I'm glad everyone agrees.  I still don't know how to solve the
> problem, though.  I came up with this:
>
> #define spin_until_timeout(condition, timeout)          \
>       for (unsigned long __timeout = jiffies + (timeout);     \
>               (!(condition) && time_after(jiffies, __timeout)); )
>
> Now how do I modify this so that the caller knows whether the loop
> terminated because of a timeout or the condition became true?

How about this:

#define spin_until_timeout(condition, timeout, rc) \
for (unsigned long __timeout = jiffies + (timeout); \
(!(rc = (condition)) && time_after(jiffies, __timeout)); )

g.

--
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/