🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #13602

Re: Programacion timeout en driver

#13602
From: Javier Cantero
Date: Sat, 10 Feb 2001 09:05
102 lines
4592 bytes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

  >>>>> El Wed, 07 Feb 2001 13:16:26 +0100, "Eduardo Ferro"
  >>>>> nos contaba en es.comp.os.linux.programacion:

>caso es que tengo que ahcer una driver para mi empresa y me etoy
>volviendo loco intentando implementar un timeout, a la espera de una
>interrupci�n, es decir quiero quedarme durmiendo hasta que pase una de
>las dos cosas, se produzca una interrupci�n, o se llegue al timeout.
>
>El caso es que las dos cosas por separado ya las he hecho en otros
>driver mediante schedule_timeout e interruptible_sleep_on, pero me
>estoy volviendo loco para ver como esperar las dos cosas a la vez.

    Esta semana se ha hablado de estas cosas en el kernel. He sacado
esto de LWN. Es la forma correcta(tm) de hacerlo *para un solo* evento.
Pero me imagino que es la base para hacerlo con dos o m�s...

  
Date:   Wed, 31 Jan 2001 09:14:30 +0000 (GMT)
From:   David Woodhouse <dwmw2@infradead.org>
To:     Timur Tabi <ttabi@interactivesi.com>
Subject: Re: [ANNOUNCE] Kernel Janitor's TODO list

On Tue, 30 Jan 2001, Timur Tabi wrote:

> > If you have a task that looks like:
> >
> >     loop:
> >         <do something important>
> >         sleep_on(q)
> >
> > And you do wakeup(q) hoping to get something important done, then if the
> > task isn't sleeping at the time of the wakeup it will ignore the wakeup
> > and go to sleep, which imay not be what you wanted.
>
> Ok, so how should this code have been written?

DECLARE_WAIT_QUEUE(wait, current);

while(1) {
        do_something_important()

        set_current_state(TASK_INTERRUPTIBLE);
        add_wait_queue(&q, &wait);

        /* Now if something arrives, we'll be 'woken' immediately -
           - that is; our state will be set to TASK_RUNNING */

        if (!stuff_to_do()) {
                /* If the 'stuff' arrives here, we get woken anyway,
                        so the schedule() returns immediately. You
                        can use schedule_timeout() here if you need
                        a timeout, obviously */
                schedule();
        }

        set_current_state(TASK_RUNNING);
        remove_wait_queue(&q, &wait);

        if (signal_pending(current)) {
                /* You've been signalled. Deal with it. If you don't
                        want signals to wake you, use TASK_UNINTERRUPTIBLE
                        above instead of TASK_INTERRUPTIBLE. Be aware
                        that you'll add one to the load average all the
                        time your task is sleeping then. */
                return -EINTR;
        }
}


Alternatively, you could up() a semaphore for each task that's do be done,
and down() it again each time you remove one from the queue.

 --
dwmw2


- -
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/




                                       Saludos de Javier Cantero
                                    (jcantero at escomposlinux.org)


- -- 
"Yo uso Software Libre" (declaraci�n a petici�n de Richard M. Stallman)

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: Clave p�blica en <http://escomposlinux.org/jcantero/>

iEYEARECAAYFAjqFBGYACgkQ/2BrePPqGDlakACfUt38XSEcdugwK8u8v/IbnxV2
kOIAn272OC+lmwtPuLbu6Ewq+woI0t/U
=DPsW
-----END PGP SIGNATURE-----
Technical Details
Message-ID: <slrn98a130.qn.javier@eb2dsn.ampr.org>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!193.251.151.101!opentransit.net!newsfeed.comtenidos.com!m2newsfeeder01!javier
References: <95rcfc$nn1$1@diana.bcn.ttd.net>

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f86c8,32c2f1d215b76f48
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2001-02-10 02:48:56 PST
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!193.251.151.101!opentransit.net!newsfeed.comtenidos.com!m2newsfeeder01!javier
From: javier@eb2dsn.ampr.org (Javier Cantero)
Newsgroups: es.comp.os.linux.programacion
Subject: Re: Programacion timeout en driver
Date: Sat, 10 Feb 2001 10:05:42 +0100
Organization: Wanadoo
Lines: 102
Message-ID: <slrn98a130.qn.javier@eb2dsn.ampr.org>
References: <95rcfc$nn1$1@diana.bcn.ttd.net>
Reply-To: mira@abajo.por.favor
NNTP-Posting-Host: usuario2-36-86-157.dialup.uni2.es
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: m2wpersoisp01.wanadoo.es 981801379 22630 62.36.86.157 (10 Feb 2001 10:36:19 GMT)
X-Complaints-To: usenet@m2wpersoisp01.wanadoo.es
NNTP-Posting-Date: Sat, 10 Feb 2001 10:36:19 +0000 (UTC)
X-Operating-System: Debian GNU/Linux 2.2 "potato"
User-Agent: slrn/0.9.6.2 (Linux)