summaryrefslogtreecommitdiff
path: root/lib/thread.c
diff options
context:
space:
mode:
authorpaul <paul>2004-07-22 19:14:27 +0000
committerpaul <paul>2004-07-22 19:14:27 +0000
commit05c447dd2e3aab0d045889845da0be5c8d974d4b (patch)
tree062ca42a848dc0377d7a814d8570e77bc59a2eff /lib/thread.c
parent27eebb3e5713559379ac072d5f36e26044465ab0 (diff)
2004-07-14 Paul Jakma <paul@dishone.st>
* sigevent.c: (quagga_signal_handler) add a global caught flag, set the flags to a constant rather increment to be kinder. (quagga_sigevent_process) new function, to do core of what quagga_signal_timer did. dont block signals at all as sig->caught is volatile sig_atomic_t and should be safe to access from signal and normal contexts. The signal blocking is unneeded paranoia, but is left intact under an ifdef, should some platform require it. Check global caught flag before iterating through array. (quagga_signal_timer) nearly everything moved to quagga_sigevent_process. Left in under ifdef, in case some platform could use a regular timer check for signals. * sigevent.h: quagga_sigevent_process declaration. * thread.c: (thread_fetch) check for signals at beginning of scheduler loop, check for signals if select returns EINTR.
Diffstat (limited to 'lib/thread.c')
-rw-r--r--lib/thread.c42
1 files changed, 25 insertions, 17 deletions
diff --git a/lib/thread.c b/lib/thread.c
index 93809f2f..2e953c55 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -28,6 +28,7 @@
#include "log.h"
#include "hash.h"
#include "command.h"
+#include "sigevent.h"
static struct hash *cpu_record = NULL;
@@ -748,23 +749,26 @@ thread_fetch (struct thread_master *m, struct thread *fetch)
while (1)
{
- /* Normal event is the highest priority. */
+ /* Signals are highest priority */
+ quagga_sigevent_process ();
+
+ /* Normal event are the next highest priority. */
if ((thread = thread_trim_head (&m->event)) != NULL)
- return thread_run (m, thread, fetch);
+ return thread_run (m, thread, fetch);
/* Execute timer. */
gettimeofday (&timer_now, NULL);
for (thread = m->timer.head; thread; thread = thread->next)
- if (timeval_cmp (timer_now, thread->u.sands) >= 0)
- {
- thread_list_delete (&m->timer, thread);
- return thread_run (m, thread, fetch);
- }
+ if (timeval_cmp (timer_now, thread->u.sands) >= 0)
+ {
+ thread_list_delete (&m->timer, thread);
+ return thread_run (m, thread, fetch);
+ }
/* If there are any ready threads, process top of them. */
if ((thread = thread_trim_head (&m->ready)) != NULL)
- return thread_run (m, thread, fetch);
+ return thread_run (m, thread, fetch);
/* Structure copy. */
readfd = m->readfd;
@@ -777,16 +781,20 @@ thread_fetch (struct thread_master *m, struct thread *fetch)
num = select (FD_SETSIZE, &readfd, &writefd, &exceptfd, timer_wait);
if (num == 0)
- continue;
+ continue;
if (num < 0)
- {
- if (errno == EINTR)
- continue;
-
- zlog_warn ("select() error: %s", strerror (errno));
- return NULL;
- }
+ {
+ if (errno == EINTR)
+ {
+ /* signal received */
+ quagga_sigevent_process ();
+ continue;
+ }
+
+ zlog_warn ("select() error: %s", strerror (errno));
+ return NULL;
+ }
/* Normal priority read thead. */
ready = thread_process_fd (m, &m->read, &readfd, &m->readfd);
@@ -795,7 +803,7 @@ thread_fetch (struct thread_master *m, struct thread *fetch)
ready = thread_process_fd (m, &m->write, &writefd, &m->writefd);
if ((thread = thread_trim_head (&m->ready)) != NULL)
- return thread_run (m, thread, fetch);
+ return thread_run (m, thread, fetch);
}
}