diff options
author | paulo <paul@bayleaf.org.uk> | 2010-01-18 18:00:34 +0000 |
---|---|---|
committer | paulo <paul@bayleaf.org.uk> | 2010-01-18 18:00:34 +0000 |
commit | 8f62c98f904833033bd4684fa3ae6b516470da75 (patch) | |
tree | 75f698ea0fc9ccc0624434e3b25df3d4a0091acf /lib/thread.c | |
parent | ea3df74b49782790ba198b744cbe22330377fba4 (diff) | |
download | quagga-8f62c98f904833033bd4684fa3ae6b516470da75.tar.bz2 quagga-8f62c98f904833033bd4684fa3ae6b516470da75.tar.xz |
Nexus to handle old threads and process the bgp local events. Deals
with having 1 or multiple nexus (and pthreads).
Diffstat (limited to 'lib/thread.c')
-rw-r--r-- | lib/thread.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/thread.c b/lib/thread.c index 773e9338..62f9669f 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -1028,6 +1028,61 @@ thread_fetch (struct thread_master *m, struct thread *fetch) } } + +/* Fetch next ready thread. Events and timeouts only. No I/O. + * If nothing to do returns NULL and sets event_wait to recommended time + * to be called again. */ +struct thread * +thread_fetch_event (struct thread_master *m, struct thread *fetch, + qtime_mono_t *event_wait) +{ + struct thread *thread; + struct timeval timer_val; + struct timeval timer_val_bg; + struct timeval *timer_wait; + struct timeval *timer_wait_bg; + + /* Normal event are the next highest priority. */ + if ((thread = thread_trim_head (&m->event)) != NULL) + return thread_run (m, thread, fetch); + + /* If there are any ready threads from previous scheduler runs, + * process top of them. + */ + if ((thread = thread_trim_head (&m->ready)) != NULL) + return thread_run (m, thread, fetch); + + /* Calculate select wait timer if nothing else to do */ + quagga_get_relative (NULL); + timer_wait = thread_timer_wait (&m->timer, &timer_val); + timer_wait_bg = thread_timer_wait (&m->background, &timer_val_bg); + + if (timer_wait_bg && + (!timer_wait || (timeval_cmp (*timer_wait, *timer_wait_bg) > 0))) + timer_wait = timer_wait_bg; + + /* When is the next timer due ? */ + if (timer_wait) + { + *event_wait = timeval2qtime(timer_wait); + return NULL; + } + + /* Check foreground timers. Historically, they have had higher + priority than I/O threads, so let's push them onto the ready + list in front of the I/O threads. */ + quagga_get_relative (NULL); + thread_timer_process (&m->timer, &relative_time); + + /* Background timer/events, lowest priority */ + thread_timer_process (&m->background, &relative_time); + + if ((thread = thread_trim_head (&m->ready)) != NULL) + return thread_run (m, thread, fetch); + + return NULL; +} + unsigned long thread_consumed_time (RUSAGE_T *now, RUSAGE_T *start, unsigned long *cputime) { |