Commit 200ccb31 authored by Mark Andrews's avatar Mark Andrews

keep work in timeout order

parent e8d26b28
Pipeline #14404 passed with stages
in 1 minute and 12 seconds
......@@ -187,6 +187,19 @@ int ident = 0;
} \
} while (0)
#define INSERTAFTER(list, after, item, link) do { \
assert(LINKED(after, link)); \
if ((after)->link.next == NULL) \
APPEND(list, item, link); \
else { \
(item)->link.next = (after)->link.next; \
(after)->link.next = (item); \
(item)->link.next->link.prev = (item); \
(item)->link.prev = (after); \
(item)->link.linked = 1; \
} \
} while (0)
#define UNLINK(list, item, link) do { \
if ((item)->link.next) \
(item)->link.next->link.prev = (item)->link.prev; \
......@@ -703,6 +716,24 @@ connecttoserver(struct workitem *item);
static void
report(struct summary *summary);
static void
appendtowork(struct workitem *item) {
struct workitem *last = TAIL(work);
if (LINKED(item, link))
UNLINK(work, item, link);
while (last &&
(item->when.tv_sec < last->when.tv_sec ||
(item->when.tv_sec == last->when.tv_sec &&
item->when.tv_usec < last->when.tv_usec)))
last = PREV(last, link);
if (last)
INSERTAFTER(work, last, item, link);
else
APPEND(work, item, link);
}
void
jsonsafe(const char *str, char *safe, size_t len) {
char c;
......@@ -1455,9 +1486,7 @@ resend(struct workitem *item) {
gettimeofday(&item->when, NULL);
item->when.tv_sec += item->type ? (item->sends ? 1 : 2) : 1;
item->sends++;
if (LINKED(item, link))
UNLINK(work, item, link);
APPEND(work, item, link);
appendtowork(item);
} else if (item->summary->type) {
perror("resend: sendto");
nextserver(item);
......@@ -1533,7 +1562,7 @@ send_icmp4(struct workitem *item) {
gettimeofday(&item->when, NULL);
item->when.tv_sec += 1;
APPEND(work, item, link);
appendtowork(item);
APPEND(seq[item->id], item, seqlink);
n = sendto(icmp4, &icmp, sizeof(icmp), 0,
......@@ -1587,7 +1616,7 @@ send_icmp6(struct workitem *item) {
gettimeofday(&item->when, NULL);
item->when.tv_sec += 1;
APPEND(work, item, link);
appendtowork(item);
APPEND(seq[item->id], item, seqlink);
n = sendto(icmp6, &icmp, sizeof(icmp), 0,
......@@ -1879,7 +1908,7 @@ dotest(struct workitem *item, int usec) {
gettimeofday(&item->when, NULL);
item->when.tv_sec += 1;
item->sends = 1;
APPEND(work, item, link);
appendtowork(item);
APPEND(ids[item->id], item, idlink);
} else {
perror("dotest: sendto");
......@@ -2142,7 +2171,7 @@ dolookup(struct workitem *item, int type) {
gettimeofday(&item->when, NULL);
item->when.tv_sec += 1;
item->sends++;
APPEND(work, item, link);
appendtowork(item);
APPEND(ids[item->id], item, idlink);
} else {
perror("dolookup: sendto");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment