From: W.C.A. Wijngaards Date: Thu, 23 Jan 2020 09:34:38 +0000 (+0100) Subject: dtio_find_msg loop roundrobin instead of first queue only, with X-Git-Tag: 1.11.0rc1~120^2~96 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=14d76588973715f63753cd884b5f5791f52a42ca;p=thirdparty%2Funbound.git dtio_find_msg loop roundrobin instead of first queue only, with state in the dtio struct for loop iterator. --- diff --git a/dnstap/dtstream.c b/dnstap/dtstream.c index e414d5d02..c3270a008 100644 --- a/dnstap/dtstream.c +++ b/dnstap/dtstream.c @@ -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; diff --git a/dnstap/dtstream.h b/dnstap/dtstream.h index 7641ffbd6..3c5bd9a4e 100644 --- a/dnstap/dtstream.h +++ b/dnstap/dtstream.h @@ -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 */