Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
catkira committed Nov 7, 2024
1 parent e167ea6 commit a8313dd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion iiod-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ static ssize_t iiod_client_read_attr_new(struct iiod_client *client,
char *dest, size_t len)
{
struct iiod_io *io = iiod_responder_get_default_io(client->responder);
printf("* thread = %u, iiod_responder_get_default_io = %d\n", pthread_self(), io);
// printf("* thread = %u, iiod_responder_get_default_io = %d\n", pthread_self(), io);
const struct iio_channel *chn;
const struct iio_device *dev;
const struct iio_buffer *buf;
Expand Down
30 changes: 18 additions & 12 deletions iiod-responder.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#endif

#define NB_BUFS_MAX 2
#define MAX_DEFAULT_IO_ELEMENTS 100

static void iiod_io_ref_unlocked(struct iiod_io *io);
static void iiod_io_unref_unlocked(struct iiod_io *io);
Expand Down Expand Up @@ -70,8 +71,8 @@ struct iiod_responder {
void *d;

struct iiod_io *readers, *writers, *default_io;
struct iiod_io* default_io_pool[100];
unsigned int default_io_pool_thread_ids[100];
struct iiod_io* default_io_pool[MAX_DEFAULT_IO_ELEMENTS];
uint64_t default_io_pool_thread_ids[MAX_DEFAULT_IO_ELEMENTS];
unsigned int default_io_pool_size;
uint16_t next_client_id;

Expand Down Expand Up @@ -126,7 +127,7 @@ static void __iiod_io_cancel_unlocked(struct iiod_io *io)
}

/* Discard the entry from the readers list */
printf("thread = %u, discard reader %d\n", pthread_self(), io);
// printf("thread = %u, discard reader %d\n", pthread_self(), io);
if (io == priv->readers) {
priv->readers = io->r_next;
} else if (priv->readers) {
Expand Down Expand Up @@ -303,7 +304,7 @@ static int iiod_responder_reader_worker(struct iiod_responder *priv)
/* Find the client for the given ID in the readers list */
for (io = priv->readers; io; io = io->r_next) {
if (io->client_id == cmd.client_id) {
printf("thread = %u, selecting io %u with client_id %d\n", pthread_self(), io, io->client_id);
// printf("thread = %u, selecting io %u with client_id %d\n", pthread_self(), io, io->client_id);
break;
}
}
Expand Down Expand Up @@ -585,7 +586,7 @@ int iiod_io_get_response_async(struct iiod_io *io,
io->r_io.start_time = read_counter_us();

/* Add it to the readers list */
printf("thread = %u, adding reader %d\n", pthread_self(), io);
// printf("thread = %u, adding reader %d\n", pthread_self(), io);
bool found = false;
if (priv->readers) {
for (tmp = priv->readers; tmp; ) {
Expand All @@ -606,12 +607,12 @@ int iiod_io_get_response_async(struct iiod_io *io,
} else {
unsigned int i = 0;
for (tmp = priv->readers; tmp->r_next; ) {
printf("list item %d = %d\n", i++,tmp);
// printf("list item %d = %d\n", i++,tmp);
tmp = tmp->r_next;
if (i > 100) exit(1);
}
tmp->r_next = io;
printf("io->r_next = %d\n", io->r_next);
// printf("io->r_next = %d\n", io->r_next);
}
}
else exit(1);
Expand Down Expand Up @@ -731,7 +732,7 @@ iiod_responder_create(const struct iiod_responder_ops *ops, void *d)
err_free_write_task:
iio_task_destroy(priv->write_task);
err_free_io:
iiod_io_unref(priv->default_io);
// iiod_io_unref(priv->default_io);
err_free_lock:
iio_mutex_destroy(priv->lock);
err_free_priv:
Expand All @@ -751,7 +752,7 @@ void iiod_responder_destroy(struct iiod_responder *priv)

iio_task_destroy(priv->write_task);

iiod_io_unref(priv->default_io);
// iiod_io_unref(priv->default_io);
iio_mutex_destroy(priv->lock);
free(priv);
}
Expand Down Expand Up @@ -856,17 +857,22 @@ iiod_responder_get_default_io(struct iiod_responder *priv)
}
}
struct iiod_io *io;
if (idx != -1) {
printf("using existing io element for thread %u\n", pthread_self());
if (idx != -1 && priv->default_io_pool[idx] != NULL && priv->default_io_pool[idx]->refcnt != 0) {
// printf("using existing io element for thread %u\n", pthread_self());
io = priv->default_io_pool[idx];
}
else {
printf("creating new io element for thread %u\n", pthread_self());
// printf("creating new io element for thread %u\n", pthread_self());
io = iiod_responder_create_io(priv, 0);
io->timeout_ms = priv->timeout_ms;
priv->default_io_pool_thread_ids[priv->default_io_pool_size] = pthread_self();
priv->default_io_pool[priv->default_io_pool_size] = io;
priv->default_io_pool_size++;
if (priv->default_io_pool_size > MAX_DEFAULT_IO_ELEMENTS) {
printf("default_io_pool overflow!!!\n");
exit(1);
}

}
return io;
}
Expand Down
4 changes: 0 additions & 4 deletions network-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,11 @@ void do_cancel(struct iiod_client_pdata *io_ctx)
{
uint64_t event = 1;
int ret;
printf("thread = %u, cancel... cancel_fd = %d\n", pthread_self(), io_ctx->cancel_fd[CANCEL_WR_FD]);
ret = write(io_ctx->cancel_fd[CANCEL_WR_FD], &event, sizeof(event));
if (ret == -1) {
/* If this happens something went very seriously wrong */
prm_perror(io_ctx->params, -errno,
"Unable to signal cancellation event");
printf("do cancel error!\n");
}
}

Expand All @@ -118,13 +116,11 @@ int wait_cancellable(struct iiod_client_pdata *io_ctx,
pfd[0].events = POLLOUT;
pfd[1].fd = io_ctx->cancel_fd[0];
pfd[1].events = POLLIN;
printf("thread = %u, wait cancellable... cancel_fd = %d\n", pthread_self(), pfd[1].fd);

do {
do {
ret = poll(pfd, 2, timeout);
} while (ret == -1 && errno == EINTR);
printf("thread = %u, pfd[0].revents = %d, pfd[1].revents = %d, ret = %d\n",pthread_self(), pfd[0].revents,pfd[1].revents, ret);

if (ret == -1)
return -errno;
Expand Down
3 changes: 0 additions & 3 deletions network.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,10 @@ static ssize_t network_recv(struct iiod_client_pdata *io_ctx, void *data,
while (1) {
if (cancellable) {
ret = wait_cancellable(io_ctx, true, timeout_ms);
printf("thread = %u, wait cancellable ret = %d\n", pthread_self(), ret);
if (ret < 0)
return ret;
}
printf("thread = %u, recv...\n", pthread_self());
ret = recv(io_ctx->fd, data, (int) len, flags);
printf("thread = %u, recv ret = %d\n", pthread_self(), ret);
if (ret == 0)
return -EPIPE;
else if (ret > 0)
Expand Down

0 comments on commit a8313dd

Please sign in to comment.