From 34032374dbc0b88781014d0c1990faf04e8791a5 Mon Sep 17 00:00:00 2001 From: Frank Mori Hess Date: Tue, 1 May 2007 20:16:51 +0000 Subject: [PATCH] Be more careful about using all the write-allocated buffer space available, in the cases where it was allocated previously but never used. --- comedi/comedi_fops.c | 7 ++++--- include/linux/comedidev.h | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/comedi/comedi_fops.c b/comedi/comedi_fops.c index cdea1bf0..c54b8ba1 100644 --- a/comedi/comedi_fops.c +++ b/comedi/comedi_fops.c @@ -1394,7 +1394,6 @@ static ssize_t comedi_write(struct file *file,const char *buf,size_t nbytes,loff if(s->busy != file) return -EACCES; - add_wait_queue(&dev->write_wait,&wait); while(nbytes>0 && !retval){ current->state=TASK_INTERRUPTIBLE; @@ -1405,7 +1404,9 @@ static ssize_t comedi_write(struct file *file,const char *buf,size_t nbytes,loff if(async->buf_write_ptr + m > async->prealloc_bufsz){ m = async->prealloc_bufsz - async->buf_write_ptr; } - m = comedi_buf_write_alloc(async, m); + comedi_buf_write_alloc(async, async->prealloc_bufsz); + if(m > comedi_buf_write_n_allocated(async)) + m = comedi_buf_write_n_allocated(async); if(m < n) n = m; @@ -1828,7 +1829,7 @@ void comedi_event(comedi_device *dev,comedi_subdevice *s, unsigned int mask) mask = s->async->events; s->async->events = 0; - //DPRINTK("comedi_event %x\n",mask); + //DPRINTK("comedi_event 0x%x\n",mask); if( (s->subdev_flags & SDF_RUNNING) == 0) return; diff --git a/include/linux/comedidev.h b/include/linux/comedidev.h index eb1f6205..b28fe322 100644 --- a/include/linux/comedidev.h +++ b/include/linux/comedidev.h @@ -447,6 +447,14 @@ void comedi_buf_memcpy_to( comedi_async *async, unsigned int offset, const void unsigned int num_bytes ); void comedi_buf_memcpy_from( comedi_async *async, unsigned int offset, void *destination, unsigned int num_bytes ); +static inline unsigned comedi_buf_write_n_allocated(comedi_async *async) +{ + return async->buf_write_alloc_count - async->buf_write_count; +} +static inline unsigned comedi_buf_read_n_allocated(comedi_async *async) +{ + return async->buf_read_alloc_count - async->buf_read_count; +} void comedi_reset_async_buf(comedi_async *async); -- 2.26.2