Skip to content

Commit

Permalink
test_7
Browse files Browse the repository at this point in the history
  • Loading branch information
nunojsa committed Feb 5, 2025
1 parent 8560b66 commit 5975b37
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
2 changes: 2 additions & 0 deletions iiod/ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ struct block_entry {
bool cyclic;
int dmabuf_fd;
int ep_fd;
uint16_t refcnt;
bool dead;
};

struct buffer_entry {
Expand Down
30 changes: 26 additions & 4 deletions iiod/responder.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,25 @@ struct iio_mutex *evlist_lock;

static void free_block_entry(struct block_entry *entry)
{
printf("Block Entry (%p): %u freed.\n", entry, entry->idx);
iiod_io_cancel(entry->io);
iiod_io_unref(entry->io);
iio_block_destroy(entry->block);
free(entry);
}

static void block_entry_put(struct block_entry *entry)
{
entry->refcnt--;
if (entry->refcnt == 0)
free_block_entry(entry);
}

static void block_entry_get(struct block_entry *entry)
{
entry->refcnt++;
}

static void free_buffer_entry(struct buffer_entry *entry)
{
struct block_entry *block_entry, *block_next;
Expand All @@ -61,7 +74,8 @@ static void free_buffer_entry(struct buffer_entry *entry)
for (block_entry = SLIST_FIRST(&entry->blocklist);
block_entry; block_entry = block_next) {
block_next = SLIST_NEXT(block_entry, entry);
free_block_entry(block_entry);
block_entry_put(block_entry);
//free_block_entry(block_entry);
}

iio_mutex_unlock(entry->lock);
Expand Down Expand Up @@ -348,6 +362,9 @@ static int buffer_dequeue_block(void *priv, void *d)
out_send_response:
printf("Dequeue block(%u) send response\n", entry->idx);
iiod_io_send_response(entry->io, ret, &data, nb_data);
iio_mutex_lock(buffer->lock);
block_entry_put(entry);
iio_mutex_unlock(buffer->lock);
return 0;
}

Expand Down Expand Up @@ -531,6 +548,7 @@ static struct iio_block * get_iio_block(struct parser_pdata *pdata,
SLIST_FOREACH(entry, &entry_buf->blocklist, entry) {
if (entry->idx == cmd->code >> 16) {
block = entry->block;
block_entry_get(entry);
break;
}
}
Expand All @@ -549,7 +567,6 @@ static void handle_free_buffer(struct parser_pdata *pdata,
{
struct iiod_io *io = iiod_command_get_default_io(cmd_data);
const struct iio_device *dev;
struct block_entry *block_entry, *block_next;
struct buffer_entry *entry, *buf_entry;
struct iio_buffer *buf;
int ret;
Expand Down Expand Up @@ -673,6 +690,9 @@ static void handle_create_block(struct parser_pdata *pdata,
/* No error? This block already exists, so return
* -EINVAL. */
ret = -EINVAL;
iio_mutex_lock(buf_entry->lock);
block_entry_put(entry);
iio_mutex_unlock(buf_entry->lock);
goto out_send_response;
}

Expand All @@ -691,6 +711,7 @@ static void handle_create_block(struct parser_pdata *pdata,
entry->block = block;
entry->io = io;
entry->idx = cmd->code >> 16;
entry->refcnt = 1;

if (WITH_IIOD_USB_DMABUF && pdata->is_usb) {
entry->dmabuf_fd = iio_block_get_dmabuf_fd(block);
Expand Down Expand Up @@ -757,12 +778,13 @@ static void handle_free_block(struct parser_pdata *pdata,

SLIST_REMOVE(&buf_entry->blocklist, entry, block_entry, entry);

printf("Block (%p): %u freed.\n", entry, entry->idx);
free_block_entry(entry);
printf("Block (%p): %u put.\n", entry, entry->idx);
block_entry_put(entry);
ret = 0;
break;
}

//block_entry_put(entry);
iio_mutex_unlock(buf_entry->lock);

IIO_DEBUG("Block %u freed.\n", cmd->code);
Expand Down

0 comments on commit 5975b37

Please sign in to comment.