From b8f3ea0be33ee90a7dfc4614752615acb65dc978 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Mon, 11 Dec 2023 11:50:34 +0100 Subject: [PATCH] Rework cyclic block enqueue when talking to v0.x IIOD Instead of continuously sending the same block again and again, set the "cyclic" parameter of the .enable_buffer() backend callback to the value of the "cyclic" parameter of the last call to iio_buffer_enqueue(). Signed-off-by: Paul Cercueil --- block.c | 18 +++--------------- buffer.c | 1 + iio-private.h | 3 +++ 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/block.c b/block.c index 8a263100e..f6b0f9bbc 100644 --- a/block.c +++ b/block.c @@ -19,9 +19,8 @@ struct iio_block { size_t size; void *data; - struct iio_task_token *token, *old_token; + struct iio_task_token *token; size_t bytes_used; - bool cyclic; }; struct iio_block * @@ -83,9 +82,6 @@ void iio_block_destroy(struct iio_block *block) struct iio_buffer *buf = block->buffer; const struct iio_backend_ops *ops = buf->dev->ctx->ops; - /* Stop the cyclic task */ - block->cyclic = false; - if (block->token) { iio_task_cancel(block->token); iio_task_sync(block->token, 0); @@ -132,20 +128,12 @@ int iio_block_io(struct iio_block *block) if (!iio_device_is_tx(block->buffer->dev)) return iio_block_read(block); - if (block->old_token) - iio_task_sync(block->old_token, 0); - - if (block->cyclic) { - block->old_token = block->token; - block->token = iio_task_enqueue(block->buffer->worker, block); - } - return iio_block_write(block); } int iio_block_enqueue(struct iio_block *block, size_t bytes_used, bool cyclic) { - const struct iio_buffer *buffer = block->buffer; + struct iio_buffer *buffer = block->buffer; const struct iio_device *dev = buffer->dev; const struct iio_backend_ops *ops = dev->ctx->ops; @@ -164,7 +152,7 @@ int iio_block_enqueue(struct iio_block *block, size_t bytes_used, bool cyclic) } block->bytes_used = bytes_used; - block->cyclic = cyclic; + buffer->cyclic = cyclic; block->token = iio_task_enqueue(buffer->worker, block); return iio_err(block->token); diff --git a/buffer.c b/buffer.c index e8b35afd7..654fd9490 100644 --- a/buffer.c +++ b/buffer.c @@ -51,6 +51,7 @@ static int iio_buffer_set_enabled(const struct iio_buffer *buf, bool enabled) if (buf->block_size) { sample_size = iio_device_get_sample_size(buf->dev, buf->mask); nb_samples = buf->block_size / sample_size; + cyclic = buf->cyclic; } if (ops->enable_buffer) diff --git a/iio-private.h b/iio-private.h index 5d6ec2951..575b5ac73 100644 --- a/iio-private.h +++ b/iio-private.h @@ -146,7 +146,10 @@ struct iio_buffer { struct iio_task *worker; + /* These two fields are set by the last block created. They are only + * used when communicating with v0.x IIOD. */ size_t block_size; + bool cyclic; struct iio_attr_list attrlist;