Skip to content

Commit

Permalink
test_fc
Browse files Browse the repository at this point in the history
  • Loading branch information
nunojsa committed Feb 10, 2025
1 parent 9033f9a commit 09b0e61
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
12 changes: 12 additions & 0 deletions iiod-responder.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,18 @@ void iiod_io_cancel(struct iiod_io *io)
iiod_io_cancel_response(io);
}

void iiod_io_cancel_writer(struct iiod_io *io)
{
struct iiod_responder *priv = io->responder;
struct iio_task_token *token;

iio_mutex_lock(priv->lock);
token = io->write_token;
iio_mutex_unlock(priv->lock);

iio_task_cancel_ongoing(token);
}

static void iiod_io_destroy(struct iiod_io *io)
{
iio_mutex_destroy(io->lock);
Expand Down
2 changes: 2 additions & 0 deletions iiod-responder.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ iiod_command_get_default_io(struct iiod_command_data *data);
/* Remove queued asynchronous requests for commands or responses. */
void iiod_io_cancel(struct iiod_io *io);

void iiod_io_cancel_writer(struct iiod_io *io);

/* Increase the internal reference counter */
void iiod_io_ref(struct iiod_io *io);

Expand Down
3 changes: 1 addition & 2 deletions iiod/responder.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ struct iio_mutex *evlist_lock;

static void free_block_entry(struct block_entry *entry)
{
iiod_io_cancel(entry->io);
iiod_io_unref(entry->io);
iio_block_destroy(entry->block);
iio_task_token_destroy(entry->enqueue_token);
Expand Down Expand Up @@ -779,7 +778,7 @@ static void handle_free_block(struct parser_pdata *pdata,
SLIST_REMOVE(&buf_entry->blocklist, entry, block_entry, entry);

printf("Cancel io on block(%p) %d\n", entry, entry->idx);
iiod_io_cancel(entry->io);
iiod_io_cancel_writer(entry->io);

printf("Sync up block(%p) %u on enqueue thread\n",
entry, entry->idx);
Expand Down
1 change: 1 addition & 0 deletions include/iio/iio-lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ __api _Bool iio_task_is_done(struct iio_task_token *token);
__api int iio_task_sync(struct iio_task_token *token, unsigned int timeout_ms);
__api int iio_task_cancel_sync(struct iio_task_token *token, unsigned int timeout_ms);
__api void iio_task_cancel(struct iio_task_token *token);
__api void iio_task_cancel_ongoing(struct iio_task_token *token);
__api const char * iio_thrd_get_name(struct iio_thrd *thrd);

#undef __api
Expand Down
28 changes: 25 additions & 3 deletions task.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,28 @@ int iio_task_cancel_sync(struct iio_task_token *token, unsigned int timeout_ms)
return ret;
}

void iio_task_cancel_ongoing(struct iio_task_token *token)
{
struct iio_task *task = token->task;
bool found;

if (!token)
return;

iio_mutex_lock(task->lock);
found = iio_task_token_find(task, token, true);
iio_mutex_unlock(task->lock);

if (found)
return;

iio_mutex_lock(token->done_lock);
token->done = true;
token->ret = -ETIMEDOUT;
iio_cond_signal(token->done_cond);
iio_mutex_unlock(token->done_lock);
}

void iio_task_cancel(struct iio_task_token *token)
{
struct iio_task *task = token->task;
Expand All @@ -380,17 +402,17 @@ void iio_task_cancel(struct iio_task_token *token)
found = iio_task_token_find(task, token, true);
iio_mutex_unlock(task->lock);

//if (found) {
if (found) {
iio_mutex_lock(token->done_lock);
token->done = true;
token->ret = -ETIMEDOUT;
iio_cond_signal(token->done_cond);
iio_mutex_unlock(token->done_lock);
/*} else {
} else {
iio_mutex_lock(token->done_lock);
printf("Token entry done/ongoing... %d\n", token->done);
iio_mutex_unlock(token->done_lock);
}*/
}

/* If it wasn't removed from the list, it's being processed or
* has been processed already; there is nothing to do here. */
Expand Down

0 comments on commit 09b0e61

Please sign in to comment.