Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: Add support for blocking IO on buffers

Currently the IIO buffer interface only allows non-blocking reads. This patch
adds support for blocking IO. In blocking mode the thread will go to sleep if no
data is available and will wait for the buffer implementation to signal that new
data is available by waking up the buffers waitqueue.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Lars-Peter Clausen and committed by
Jonathan Cameron
ee551a10 355c1a14

+22 -1
+22 -1
drivers/iio/industrialio-buffer.c
··· 56 56 { 57 57 struct iio_dev *indio_dev = filp->private_data; 58 58 struct iio_buffer *rb = indio_dev->buffer; 59 + int ret; 59 60 60 61 if (!indio_dev->info) 61 62 return -ENODEV; 62 63 63 64 if (!rb || !rb->access->read_first_n) 64 65 return -EINVAL; 65 - return rb->access->read_first_n(rb, n, buf); 66 + 67 + do { 68 + if (!iio_buffer_data_available(rb)) { 69 + if (filp->f_flags & O_NONBLOCK) 70 + return -EAGAIN; 71 + 72 + ret = wait_event_interruptible(rb->pollq, 73 + iio_buffer_data_available(rb) || 74 + indio_dev->info == NULL); 75 + if (ret) 76 + return ret; 77 + if (indio_dev->info == NULL) 78 + return -ENODEV; 79 + } 80 + 81 + ret = rb->access->read_first_n(rb, n, buf); 82 + if (ret == 0 && (filp->f_flags & O_NONBLOCK)) 83 + ret = -EAGAIN; 84 + } while (ret == 0); 85 + 86 + return ret; 66 87 } 67 88 68 89 /**