From: Rupert Eibauer <Rupert@ces.ch>
To: linux-kernel@vger.kernel.org
Cc: rusty@rustcorp.com.au
Subject: [RFC] Fwd: Re: Fwd: Linux Kernel: down_timeout
Date: Thu, 15 Aug 2002 11:57:17 +0200 [thread overview]
Message-ID: <200208151157327.SM00152@there> (raw)
Please reply to me directly, I am not
subscribed to the lkml.
---------- Forwarded Message ----------
Subject: Re: Fwd: Linux Kernel: down_timeout
Date: Thu, 15 Aug 2002 10:44:55 +0100 (BST)
From: Matthew Kirkwood <matthew@hairy.beasts.org>
To: Rupert Eibauer <Rupert@ces.ch>
On Thu, 15 Aug 2002, Rupert Eibauer wrote:
> I found your thread
> [PATCH][RFC] Lightweight user-level semaphores
> (jan 2002)
> later, so please read on..
I'm no kernel guru, but this looks really useful. You
should probably send it to the linux-kernel list and to
Rusty Russel -- it would be a particularly useful extra
feature for his futexes.
Cheers,
Matthew.
> ---------- Forwarded Message ----------
>
> Subject: Linux Kernel: down_timeout
> Date: Thu, 15 Aug 2002 11:14:24 +0200
> From: Rupert Eibauer <Rupert@ces.ch>
> To: andrew.grover@intel.com, ingo.oeser@informatik.tu-chemnitz.de,
> robert.moore@intel.com
>
> Hi,
>
> I found your thread (Apr 2001) about down_timeout on the lkml.
> down_timeout is needed more often then you might think.
>
> Does anybody of you know why it hasnt been implemented in
> the kernel until now?
>
> My version of down_timeout is attached below.
>
>
> waiting for your answer,
>
> Rupert
>
>
---------- End of Forwarded Message ----------
Here is the header snippet:
-8<--------------------------------------------------------------------------
extern int __down_timeout(struct semaphore * sem, int timeout);
extern inline int down_timeout(struct semaphore * sem, int timeout)
{
int ret = 0;
if (atomic_dec_if_positive(&sem->count) < 0)
ret = __down_timeout(sem, timeout);
smp_wmb();
return ret;
}
-8<--------------------------------------------------------------------------
This is for the .c file:
-8<--------------------------------------------------------------------------
static void process_sema_timeout(unsigned long data) {
struct task_struct *p = (struct task_struct *)data;
wake_up_process(p);
}
extern int __down_timeout(struct semaphore * sem, int timeout)
{
int ret = 0;
unsigned long expire;
struct timer_list timer;
if (timeout > 0) {
expire = jiffies + timeout;
init_timer(&timer);
timer.expires = expire;
timer.data = (unsigned long) current;
timer.function = process_sema_timeout;
add_timer(&timer);
if (ret = __down_interruptible(sema)) {
/* check whether the timeout woke us up */
if (jiffies > expire)
ret = -ETIME;
else
del_timer_sync(&timer);
} else
del_timer_sync(&timer);
} else if (timeout == 0) { // timeout=0 means now
/* our caller (inline int down_timeout) already tried to
get the semaphore _now_ and it failed ! */
ret = !0;
} else { // timeout<0 means wait forever
ret = __down_interruptible(sema)
}
return ret;
}
-8<--------------------------------------------------------------------------
--
+-----------------------------------------------------------------------------+
| CCCC EEEE SSSS Creative Electronic Systems | Rupert Eibauer |
| C E S 38 av. Eugene Lance | Linux Kernel Hacker |
| C EEE SSSS PO Box 584 | |
| C E S CH-1212 Grand-Lancy 1 | |
| CCCC EEEE SSSS Switzerland | email: rupert@ces.ch |
+-----------------------------------------------------------------------------+
next reply other threads:[~2002-08-15 9:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-08-15 9:57 Rupert Eibauer [this message]
2002-08-17 7:54 ` [RFC] Fwd: Re: Fwd: Linux Kernel: down_timeout Rusty Russell
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=200208151157327.SM00152@there \
--to=rupert@ces.ch \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
/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.