All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH 3/3] iio: Add support for blocking IO on buffers
Date: Sat, 30 Nov 2013 12:13:20 +0000	[thread overview]
Message-ID: <5299D660.3060507@kernel.org> (raw)
In-Reply-To: <1385391404-3112-3-git-send-email-lars@metafoo.de>

On 11/25/13 14:56, Lars-Peter Clausen wrote:
> 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>
Applied to the togreg branch of iio.git

Nice little bit of functionality. Thanks.

Jonathan
> ---
>  drivers/iio/industrialio-buffer.c | 23 ++++++++++++++++++++++-
>  1 file changed, 22 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index 4dcc3a0..c67d83b 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -56,13 +56,34 @@ ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf,
>  {
>  	struct iio_dev *indio_dev = filp->private_data;
>  	struct iio_buffer *rb = indio_dev->buffer;
> +	int ret;
>  
>  	if (!indio_dev->info)
>  		return -ENODEV;
>  
>  	if (!rb || !rb->access->read_first_n)
>  		return -EINVAL;
> -	return rb->access->read_first_n(rb, n, buf);
> +
> +	do {
> +		if (!iio_buffer_data_available(rb)) {
> +			if (filp->f_flags & O_NONBLOCK)
> +				return -EAGAIN;
> +
> +			ret = wait_event_interruptible(rb->pollq,
> +					iio_buffer_data_available(rb) ||
> +					indio_dev->info == NULL);
> +			if (ret)
> +				return ret;
> +			if (indio_dev->info == NULL)
> +				return -ENODEV;
> +		}
> +
> +		ret = rb->access->read_first_n(rb, n, buf);
> +		if (ret == 0 && (filp->f_flags & O_NONBLOCK))
> +			ret = -EAGAIN;
> +	 } while (ret == 0);
> +
> +	return ret;
>  }
>  
>  /**
> 

  reply	other threads:[~2013-11-30 12:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-25 14:56 [PATCH 1/3] iio: Add data_available callback for buffers Lars-Peter Clausen
2013-11-25 14:56 ` [PATCH 2/3] iio: kfifo_buf: Implement data_available() callback Lars-Peter Clausen
2013-11-30 12:09   ` Jonathan Cameron
2013-11-25 14:56 ` [PATCH 3/3] iio: Add support for blocking IO on buffers Lars-Peter Clausen
2013-11-30 12:13   ` Jonathan Cameron [this message]
2013-11-30 12:06 ` [PATCH 1/3] iio: Add data_available callback for buffers Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5299D660.3060507@kernel.org \
    --to=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.