dtio_find_msg loop roundrobin instead of first queue only, with

state in the dtio struct for loop iterator.
This commit is contained in:
W.C.A. Wijngaards 2020-01-23 10:34:38 +01:00
parent e9772b609e
commit 14d7658897
2 changed files with 16 additions and 1 deletions

View file

@ -221,6 +221,7 @@ int dt_io_thread_register_queue(struct dt_io_thread* dtio,
item->queue = mq;
item->next = dtio->io_list;
dtio->io_list = item;
dtio->io_list_iter = NULL;
return 1;
}
@ -235,6 +236,7 @@ void dt_io_thread_unregister_queue(struct dt_io_thread* dtio,
else dtio->io_list = item->next;
/* the queue itself only registered, not deleted */
free(item);
dtio->io_list_iter = NULL;
return;
}
prev = item;
@ -283,7 +285,16 @@ static int dtio_find_in_queue(struct dt_io_thread* dtio,
/** find a new message to write, search message queues, false if none */
static int dtio_find_msg(struct dt_io_thread* dtio)
{
struct dt_io_list_item* item = dtio->io_list;
struct dt_io_list_item* item;
if(dtio->io_list_iter)
item = dtio->io_list_iter;
else item = dtio->io_list;
/* use the next queue for the next message lookup,
* if we hit the end(NULL) the NULL restarts the iter at start. */
if(item)
dtio->io_list_iter = item->next;
while(item) {
if(dtio_find_in_queue(dtio, item->queue))
return 1;

View file

@ -93,6 +93,10 @@ struct dt_io_thread {
void* event_base;
/** list of queues that is registered to get written */
struct dt_io_list_item* io_list;
/** iterator point in the io_list, to pick from them in a
* round-robin fashion, instead of only from the first when busy.
* if NULL it means start at the start of the list. */
struct dt_io_list_item* io_list_iter;
/** thread id, of the io thread */
ub_thread_type tid;
/** file descriptor that the thread writes to */