On Fri, 2 Mar 2001, Dmitry Dicky wrote:

> Hi fellows,
> 
> I'm writing some device driver which should pass some data to the user
> space.
> 
> The part of the device read routine looks as follows:
> 
> ----------------------------------
> int
> dev_read(dev_t dev, struct uio *uio, int ioflag)
> {
>     int err = 0;
> /* ... */
>     amnt = MIN(uio->uio_resid, cntw);
> /* Wait here until data available .... how? */
>     err = uiomove(buf2, amnt, uio);
>     if (err != 0) {
>         return(err);
>     }
>     
>     memset(buf2, 0, amnt);
>     cntw -= amnt;
>     return 0;
> }
> -------------------------------------
> User application hands on read(2).
> 
> But buf2 being filled upon some event and 'dev_read' should
> wait until data in buf2 available.
> 
> So, the question is:
> How can I hang dev_read, issue some signal and then continue uiomove(9)
> data to the user space?

How about something like:

  int  timeout;

  timeout = hz;  /* fail if nothing in one second */

  while(timeout && (NOTREADY)) 
    if(tsleep(softc, PRIBIO, "mydev", 1))
      timeout--;
  if(NOTREADY)
    return(EIO); /* or whatever... */
  uiomove(...)

Then in your interrupt service routine:

  wakeup(softc);

Hope this helps!

-Richard 

-------------------------------------------
   Richard Hodges   | Matriplex, inc.
   Product Manager  | 769 Basque Way
  [EMAIL PROTECTED]  | Carson City, NV 89706
    775-886-6477    | www.matriplex.com 


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to