LKML Archive on
help / color / mirror / Atom feed
* whatever happened to down_timeout()?
@ 2007-02-13 22:41 Chris Friesen
  2007-02-13 23:44 ` Chris Friesen
  0 siblings, 1 reply; 2+ messages in thread
From: Chris Friesen @ 2007-02-13 22:41 UTC (permalink / raw)
  To: Linux Kernel Mailing List

There has been some discussion on lkml about a function that would 
either down a semaphore or else abort if it couldn't get the semaphore 
in a certain amount of time.  Something along the lines of:

down_timeout(struct semaphore *sem, long timeout);

Does something like this exist?  Does anyone have a working 
implementation?  Does anyone see anything obviously wrong with the 
following version (that I loosely based on one by Rupert Eibauer)?


extern int __down_timeout(struct semaphore * sem, unsigned int timeout);

/* "timeout" is the number of jiffies to wait.
  * Returns -ETIME if timeout period expires.
static inline int down_timeout(struct semaphore * sem, unsigned int timeout)
	int ret = down_trylock(sem);
	if (!ret)
		ret = __down_timeout(sem, timeout);
	return ret;


int __down_timeout(struct semaphore * sem, int timeout)
	int ret;
	unsigned long expire;
	struct timer_list timer;

	expire = jiffies + timeout;
	timer.expires = expire; = (unsigned long) current;
	timer.function = process_timeout;

	ret = down_interruptible(sema);
	if (ret && (jiffies > expire))
		ret = -ETIME;

         return ret;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-02-13 23:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-13 22:41 whatever happened to down_timeout()? Chris Friesen
2007-02-13 23:44 ` Chris Friesen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).