public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC] Fwd: Re: Fwd: Linux Kernel: down_timeout
@ 2002-08-15  9:57 Rupert Eibauer
  2002-08-17  7:54 ` Rusty Russell
  0 siblings, 1 reply; 2+ messages in thread
From: Rupert Eibauer @ 2002-08-15  9:57 UTC (permalink / raw)
  To: linux-kernel; +Cc: rusty

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          |
+-----------------------------------------------------------------------------+

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

* Re: [RFC] Fwd: Re: Fwd: Linux Kernel: down_timeout
  2002-08-15  9:57 [RFC] Fwd: Re: Fwd: Linux Kernel: down_timeout Rupert Eibauer
@ 2002-08-17  7:54 ` Rusty Russell
  0 siblings, 0 replies; 2+ messages in thread
From: Rusty Russell @ 2002-08-17  7:54 UTC (permalink / raw)
  To: Rupert Eibauer; +Cc: linux-kernel

In message <200208151157327.SM00152@there> you write:
> 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.

Hi Rupert,
	That's Russell (two l's) 8)

> > Does anybody of you know why it hasnt been implemented in
> > the kernel until now?

I think because it can be faked up with SIGALRM.  And if that's too
slow, you can use futexes which have this anyway.

Rusty.
--
  Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

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

end of thread, other threads:[~2002-08-19  0:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-15  9:57 [RFC] Fwd: Re: Fwd: Linux Kernel: down_timeout Rupert Eibauer
2002-08-17  7:54 ` Rusty Russell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox