Fix for not calculating buffer fullness through a counter wraparound
authorDavid Schleef <ds@schleef.org>
Thu, 10 Oct 2002 01:19:56 +0000 (01:19 +0000)
committerDavid Schleef <ds@schleef.org>
Thu, 10 Oct 2002 01:19:56 +0000 (01:19 +0000)
comedi/comedi_fops.c
comedi/drivers.c
include/linux/comedidev.h

index 70eaf9c84290bcc236bc056deb43cb2be1c50de8..a575cb8eb9cf2e81b4d969d79ee3d772fef853d1 100644 (file)
@@ -1260,19 +1260,18 @@ static unsigned int comedi_poll_v22(struct file *file, poll_table * wait)
        if(dev->read_subdev && dev->read_subdev->async){
                s = dev->read_subdev;
                async = s->async;
-               if(!s->busy ||
-                  (async->buf_read_count < async->buf_write_count) ||
-                  !(s->subdev_flags&SDF_RUNNING)){
+               if(!s->busy
+                  || comedi_buf_read_n_available(async)>0
+                  || !(s->subdev_flags&SDF_RUNNING)){
                        mask |= POLLIN | POLLRDNORM;
                }
        }
        if(dev->write_subdev && dev->write_subdev->async){
                s = dev->write_subdev;
                async = s->async;
-               if(!s->busy ||
-                  !(s->subdev_flags&SDF_RUNNING) ||
-                  (async->buf_write_count < async->buf_read_count +
-                   async->prealloc_bufsz)){
+               if(!s->busy
+                  || !(s->subdev_flags&SDF_RUNNING)
+                  || comedi_buf_write_n_available(async)>0){
                        mask |= POLLOUT | POLLWRNORM;
                }
        }
index 2e1f6696eb393052a3c2f0132c97eaa232e2689b..bb6cb000509b839023cad84c6bf9dfe9fc69f5ea 100644 (file)
@@ -391,6 +391,12 @@ static int buf_alloc(comedi_device *dev, comedi_subdevice *s,
        return 0;
 }
 
+unsigned int comedi_buf_write_n_available(comedi_async *async)
+{
+       unsigned int free_end = async->buf_read_count + async->prealloc_bufsz;
+
+       return free_end - async->buf_free_count;
+}
 
 unsigned int comedi_buf_write_alloc(comedi_async *async, unsigned int nbytes)
 {
index dcf1b79f73bfd3631ccf9f14b9e2c48106a233b5..19c46087304b1c5bc9ce12b78e03629a8464c000 100644 (file)
@@ -339,6 +339,7 @@ int comedi_buf_get_array(comedi_async *async, sampl_t *array, unsigned int num_s
 #endif
 int comedi_buf_get(comedi_async *async, sampl_t *x);
 
+unsigned int comedi_buf_write_n_available(comedi_async *async);
 unsigned int comedi_buf_write_alloc(comedi_async *async, unsigned int nbytes);
 unsigned int comedi_buf_write_alloc_strict(comedi_async *async, unsigned int nbytes);
 void comedi_buf_write_free(comedi_async *async, unsigned int nbytes);