linux-iio.vger.kernel.org archive mirror
 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 2/3] iio: kfifo_buf: Implement data_available() callback
Date: Sat, 30 Nov 2013 12:09:34 +0000	[thread overview]
Message-ID: <5299D57E.9000706@kernel.org> (raw)
In-Reply-To: <1385391404-3112-2-git-send-email-lars@metafoo.de>

On 11/25/13 14:56, Lars-Peter Clausen wrote:
> This patch implements the data_available() callback for the kfifo buffer instead
> of using the stufftoread flag. The kfifo used by the buffer already knows
> whether it is empty or not based on the position of its read and write pointer.
> Using this makes it a lot easier to tell whether data is available or not and it
> is not necessary to take special measures to ensure that no race conditions
> between reading and writing from the buffer occur.
> 
> Note, that we still have to take the buffers lock to protect against concurrent
> resizeing of the kfifo.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Looks good. Applied to the togreg branch of iio.git.

Thanks,

Jonathan
> ---
>  drivers/iio/kfifo_buf.c | 23 ++++++++++++++---------
>  1 file changed, 14 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/iio/kfifo_buf.c b/drivers/iio/kfifo_buf.c
> index 95c6fc8..7134e8a 100644
> --- a/drivers/iio/kfifo_buf.c
> +++ b/drivers/iio/kfifo_buf.c
> @@ -42,7 +42,6 @@ static int iio_request_update_kfifo(struct iio_buffer *r)
>  	} else {
>  		kfifo_reset_out(&buf->kf);
>  	}
> -	r->stufftoread = false;
>  	mutex_unlock(&buf->user_lock);
>  
>  	return ret;
> @@ -108,7 +107,7 @@ static int iio_store_to_kfifo(struct iio_buffer *r,
>  	ret = kfifo_in(&kf->kf, data, 1);
>  	if (ret != 1)
>  		return -EBUSY;
> -	r->stufftoread = true;
> +
>  	wake_up_interruptible_poll(&r->pollq, POLLIN | POLLRDNORM);
>  
>  	return 0;
> @@ -127,13 +126,6 @@ static int iio_read_first_n_kfifo(struct iio_buffer *r,
>  		ret = -EINVAL;
>  	else
>  		ret = kfifo_to_user(&kf->kf, buf, n, &copied);
> -
> -	if (kfifo_is_empty(&kf->kf))
> -		r->stufftoread = false;
> -	/* verify it is still empty to avoid race */
> -	if (!kfifo_is_empty(&kf->kf))
> -		r->stufftoread = true;
> -
>  	mutex_unlock(&kf->user_lock);
>  	if (ret < 0)
>  		return ret;
> @@ -141,6 +133,18 @@ static int iio_read_first_n_kfifo(struct iio_buffer *r,
>  	return copied;
>  }
>  
> +static bool iio_kfifo_buf_data_available(struct iio_buffer *r)
> +{
> +	struct iio_kfifo *kf = iio_to_kfifo(r);
> +	bool empty;
> +
> +	mutex_lock(&kf->user_lock);
> +	empty = kfifo_is_empty(&kf->kf);
> +	mutex_unlock(&kf->user_lock);
> +
> +	return !empty;
> +}
> +
>  static void iio_kfifo_buffer_release(struct iio_buffer *buffer)
>  {
>  	struct iio_kfifo *kf = iio_to_kfifo(buffer);
> @@ -153,6 +157,7 @@ static void iio_kfifo_buffer_release(struct iio_buffer *buffer)
>  static const struct iio_buffer_access_funcs kfifo_access_funcs = {
>  	.store_to = &iio_store_to_kfifo,
>  	.read_first_n = &iio_read_first_n_kfifo,
> +	.data_available = iio_kfifo_buf_data_available,
>  	.request_update = &iio_request_update_kfifo,
>  	.get_bytes_per_datum = &iio_get_bytes_per_datum_kfifo,
>  	.set_bytes_per_datum = &iio_set_bytes_per_datum_kfifo,
> 

  reply	other threads:[~2013-11-30 12:09 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 [this message]
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
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=5299D57E.9000706@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).