LKML Archive on
help / color / mirror / Atom feed
From: "Chris Friesen" <>
To: Linux Kernel Mailing List <>
Subject: whatever happened to down_timeout()?
Date: Tue, 13 Feb 2007 16:41:11 -0600	[thread overview]
Message-ID: <> (raw)

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;


             reply	other threads:[~2007-02-13 22:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-13 22:41 Chris Friesen [this message]
2007-02-13 23:44 ` Chris Friesen

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \
    --subject='Re: whatever happened to down_timeout()?' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).