From b5b0608f57c29bfd8bcfa21e2b266f37c35cd06d Mon Sep 17 00:00:00 2001 From: David Schleef Date: Thu, 10 Oct 2002 01:19:56 +0000 Subject: [PATCH] Fix for not calculating buffer fullness through a counter wraparound --- comedi/comedi_fops.c | 13 ++++++------- comedi/drivers.c | 6 ++++++ include/linux/comedidev.h | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index 70eaf9c8..a575cb8e 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -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; } } diff --git a/comedi/drivers.c b/comedi/drivers.c index 2e1f6696..bb6cb000 100644 --- a/comedi/drivers.c +++ b/comedi/drivers.c @@ -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) { diff --git a/include/linux/comedidev.h b/include/linux/comedidev.h index dcf1b79f..19c46087 100644 --- a/include/linux/comedidev.h +++ b/include/linux/comedidev.h @@ -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); -- 2.26.2