From: "Chris Friesen" <cfriesen@nortel.com>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: whatever happened to down_timeout()?
Date: Tue, 13 Feb 2007 16:41:11 -0600 [thread overview]
Message-ID: <45D23E87.2030805@nortel.com> (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)?
semaphore.h:
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;
}
kernel/timer.c
int __down_timeout(struct semaphore * sem, int timeout)
{
int ret;
unsigned long expire;
struct timer_list timer;
expire = jiffies + timeout;
init_timer(&timer);
timer.expires = expire;
timer.data = (unsigned long) current;
timer.function = process_timeout;
add_timer(&timer);
ret = down_interruptible(sema);
if (ret && (jiffies > expire))
ret = -ETIME;
else
del_timer_sync(&timer);
return ret;
}
Thanks,
Chris
next 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 ` whatever happened to down_timeout()? 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:
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=45D23E87.2030805@nortel.com \
--to=cfriesen@nortel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.