From: Timur Tabi <timur@freescale.com>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] add function spin_event_timeout()
Date: Fri, 6 Mar 2009 18:13:21 -0600 [thread overview]
Message-ID: <1236384801-10305-1-git-send-email-timur@freescale.com> (raw)
The function spin_event_timeout() takes a condition and timeout value
(in jiffies) as parameters. It spins until either the condition is true
or the timeout expires. It returns non-zero if the condition is true,
zero otherwise.
Signed-off-by: Timur Tabi <timur@freescale.com>
---
include/linux/delay.h | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/include/linux/delay.h b/include/linux/delay.h
index fd832c6..00ac466 100644
--- a/include/linux/delay.h
+++ b/include/linux/delay.h
@@ -51,4 +51,25 @@ static inline void ssleep(unsigned int seconds)
msleep(seconds * 1000);
}
+/**
+ * spin_event_timeout - spin until a condition gets true or a timeout elapses
+ * @condition: a C expression for the event to wait for
+ * @timeout: timeout, in jiffies
+ *
+ * The process spins until the @condition evaluates to true or the @timeout
+ * elapses.
+ *
+ * The function returns non-zero if the @condition evaluated to true, or
+ * zero if the @timeout elapsed. If both occurs (e.g. the loop was
+ * pre-empted and the @condition became true in the meantime, but when the
+ * loop resumed the @timeout had already elapsed), then non-zero will be
+ * returned.
+ */
+#define spin_event_timeout(condition, timeout) \
+({ \
+ long __timeout = jiffies + (timeout); \
+ while (!(condition) && (jiffies < __timeout)); \
+ (condition); \
+})
+
#endif /* defined(_LINUX_DELAY_H) */
--
1.6.1.3
next reply other threads:[~2009-03-07 0:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-07 0:13 Timur Tabi [this message]
2009-03-07 1:11 ` Roland Dreier
2009-03-07 1:25 ` Timur Tabi
2009-03-07 9:13 ` Jiri Slaby
2009-03-09 20:47 ` Jeremy Fitzhardinge
2009-03-09 20:51 ` Timur Tabi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1236384801-10305-1-git-send-email-timur@freescale.com \
--to=timur@freescale.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome