lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1236611904-9843-1-git-send-email-timur@freescale.com>
Date:	Mon,  9 Mar 2009 10:18:24 -0500
From:	Timur Tabi <timur@...escale.com>
To:	linux-kernel@...r.kernel.org, rdreier@...co.com,
	jirislaby@...il.com
Subject: [PATCH v2] add function spin_event_timeout()

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@...escale.com>
---

v2: changes based on feedback

 include/linux/delay.h |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/include/linux/delay.h b/include/linux/delay.h
index fd832c6..235ca25 100644
--- a/include/linux/delay.h
+++ b/include/linux/delay.h
@@ -51,4 +51,26 @@ 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)			\
+({								\
+	unsigned long __timeout = jiffies + (timeout);		\
+	while (!(condition) && time_before(jiffies, __timeout))	\
+		cpu_relax();					\
+	(condition);						\
+})
+
 #endif /* defined(_LINUX_DELAY_H) */
-- 
1.6.1.3

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ