From 4bc670218253446143ae5ac1419c83c629f9c0f1 Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sun, 5 Feb 2006 15:34:13 +0000 Subject: [PATCH] The main scheduler doesn't run in a thread anymore --- ChangeLog | 1 + mbtask/mbtask.c | 30 +++++++++--------------------- mbtask/mbtask.h | 2 +- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index a670f5fa..6cc4207f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ v0.83.11 28-Jan-2006 will completly restart the connection with that remote. Made several functions multithread aware (still not Ok). Finished tasks now report using a signal call. + The main scheduler doesn't run in a thread anymore. mbcico: Assume EXTCMD is set when GZ or BZ2 is active. diff --git a/mbtask/mbtask.c b/mbtask/mbtask.c index b6f722e3..a318d32f 100644 --- a/mbtask/mbtask.c +++ b/mbtask/mbtask.c @@ -113,7 +113,6 @@ int T_Shutdown = FALSE; /* Shutdown threads */ int nodaemon = FALSE; /* Run in foreground */ extern int cmd_run; /* Cmd running */ extern int ping_run; /* Ping running */ -int sched_run = FALSE; /* Scheduler running */ extern int disk_run; /* Disk watch running */ extern int ibc_run; /* IBC thread running */ @@ -809,17 +808,15 @@ void die(int onsig) * build to stop within a second. */ now = time(NULL) + 2; - while ((cmd_run || ping_run || sched_run || disk_run || ibc_run) && (time(NULL) < now)) { + while ((cmd_run || ping_run || disk_run || ibc_run) && (time(NULL) < now)) { sleep(1); } - if (cmd_run || ping_run || sched_run || disk_run || ibc_run) + if (cmd_run || ping_run || disk_run || ibc_run) Syslog('+', "Not all threads stopped! Forced shutdown"); if (cmd_run) Syslog('+', "Thread cmd_run not responding"); if (ping_run) Syslog('+', "Thread ping_run not responding"); - if (sched_run) - Syslog('+', "Thread sched_run not responding"); if (disk_run) Syslog('+', "Thread disk_run not responding"); if (ibc_run) @@ -1111,9 +1108,6 @@ void start_scheduler(void) } else if ((rc = pthread_create(&pt_disk, NULL, (void (*))disk_thread, NULL))) { WriteError("$pthread_create disk_thread rc=%d", rc); die(SIGTERM); - } else if ((rc = pthread_create(&pt_scheduler, NULL, (void (*))scheduler, NULL))) { - WriteError("$pthread_create scheduler rc=%d", rc); - die(SIGTERM); } else if ((rc = pthread_create(&pt_ibc, NULL, (void (*))ibc_thread, NULL))) { WriteError("$pthread_create ibc rc=%d", rc); die(SIGTERM); @@ -1124,20 +1118,18 @@ void start_scheduler(void) printf("threads installed\n"); /* - * Sleep until we die + * Run the scheduler */ - while (! G_Shutdown) { - sleep(1); - } + scheduler(); die(SIGTERM); } /* - * Scheduler thread + * Scheduler loop */ -void *scheduler(void) +void scheduler(void) { struct passwd *pw; int running = 0, i, found; @@ -1155,7 +1147,6 @@ void *scheduler(void) pp_list *tpl; Syslog('+', "Starting scheduler thread"); - sched_run = TRUE; pw = getpwuid(getuid()); /* @@ -1163,7 +1154,7 @@ void *scheduler(void) */ do { sleep(1); - if (T_Shutdown) + if (G_Shutdown) break; /* @@ -1521,11 +1512,9 @@ void *scheduler(void) } /* if (Processing) */ } /* if ((tm->tm_sec / SLOWRUN) != oldmin) */ - } while (! T_Shutdown); + } while (! G_Shutdown); - sched_run = FALSE; - Syslog('+', "Scheduler thread stopped"); - pthread_exit(NULL); + Syslog('+', "Scheduler stopped"); } @@ -1554,7 +1543,6 @@ int main(int argc, char **argv) else if ((i == SIGINT) || (i == SIGTERM)) signal(i, (void (*))start_shutdown); else if (i == SIGCHLD) -// signal(i, SIG_DFL); signal(i, (void (*))taskdie); } diff --git a/mbtask/mbtask.h b/mbtask/mbtask.h index 578aca75..e468793d 100644 --- a/mbtask/mbtask.h +++ b/mbtask/mbtask.h @@ -48,7 +48,7 @@ int runtasktype(int); int checktasks(int); void die(int); void start_scheduler(void); -void *scheduler(void); +void scheduler(void); int locktask(char *); void ulocktask(void);