From 96a22a8c6fa657c48069fb488db060caf9d2d452 Mon Sep 17 00:00:00 2001 From: Alexey Andriyanov Date: Wed, 27 May 2015 15:52:00 +0400 Subject: scheduler: reduce CPU usage Since threads are sorted by t->sands, we could break the cycle when not expired thread found. (cherry picked from commit 084bbea7f9320d69e39250f078ce2255e9d73861) --- lib/scheduler.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/scheduler.c b/lib/scheduler.c index f14c3c1..ce35d4b 100644 --- a/lib/scheduler.c +++ b/lib/scheduler.c @@ -618,7 +618,8 @@ retry: /* When thread can't fetch try to find next thread again. */ thread_list_delete(&m->child, t); thread_list_add(&m->ready, t); t->type = THREAD_CHILD_TIMEOUT; - } + } else + break; } /* Read thead. */ @@ -683,7 +684,8 @@ retry: /* When thread can't fetch try to find next thread again. */ thread_list_delete(&m->timer, t); thread_list_add(&m->ready, t); t->type = THREAD_READY; - } + } else + break; } /* Return one event. */ -- 1.7.12.1