Skip to content

Commit

Permalink
Rework cyclic block enqueue when talking to v0.x IIOD
Browse files Browse the repository at this point in the history
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 <paul@crapouillou.net>
  • Loading branch information
pcercuei committed Dec 14, 2023
1 parent 9466de6 commit b8f3ea0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
18 changes: 3 additions & 15 deletions block.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions iio-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit b8f3ea0

Please sign in to comment.