From 7cbe288b84219405fa60e0075eee1cf2fe68b9ab Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 13 Jul 2001 00:01:37 +0000 Subject: [PATCH] * Shuffled around some of the housekeeping loop code --- citadel/ChangeLog | 4 ++++ citadel/citserver.h | 1 - citadel/housekeeping.c | 40 +++++++++++++++++++++++++++++++++++++++- citadel/housekeeping.h | 1 + citadel/server.h | 1 + citadel/sysconfig.h | 7 ------- citadel/sysdep.c | 9 +-------- 7 files changed, 46 insertions(+), 17 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index cfa621368..edc917f58 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,7 @@ $Log$ + Revision 580.3 2001/07/13 00:01:36 ajc + * Shuffled around some of the housekeeping loop code + Revision 580.2 2001/07/11 17:01:10 ajc * database_sleepycat.c: small changes to log messages @@ -2568,3 +2571,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import + diff --git a/citadel/citserver.h b/citadel/citserver.h index 1e6543f42..391e9d4f4 100644 --- a/citadel/citserver.h +++ b/citadel/citserver.h @@ -22,7 +22,6 @@ void *CtdlGetUserData(unsigned long requested_sym); void CtdlAllocUserData(unsigned long requested_sym, size_t num_bytes); void CtdlReallocUserData(unsigned long requested_sym, size_t num_bytes); int CtdlGetDynamicSymbol(void); -void enter_housekeeping_cmd(char *); void do_command_loop(void); void begin_session(struct CitContext *con); void citproto_begin_session(void); diff --git a/citadel/housekeeping.c b/citadel/housekeeping.c index 2746b68de..34ca22092 100644 --- a/citadel/housekeeping.c +++ b/citadel/housekeeping.c @@ -41,7 +41,6 @@ #include "database.h" -int housepipe[2]; /* This is the queue for housekeeping tasks */ /* @@ -112,3 +111,42 @@ void check_ref_counts(void) { ForEachRoom(check_ref_counts_backend, NULL); } +/* + * This is the housekeeping loop. Worker threads come through here after + * processing client requests but before jumping back into the pool. We + * only allow housekeeping to execute once per minute, and we only allow one + * instance to run at a time. + */ +void do_housekeeping(void) { + static int housekeeping_in_progress = 0; + time_t last_timer = 0L; + int do_housekeeping_now = 0; + + /* + * We do it this way instead of wrapping the whole loop in an + * S_HOUSEKEEPING critical section because it eliminates the need to + * potentially have multiple concurrent mutexes in progress. + */ + begin_critical_section(S_HOUSEKEEPING); + if ( ((time(NULL) - last_timer) > 60L) + && (housekeeping_in_progress == 0) ) { + do_housekeeping_now = 1; + housekeeping_in_progress = 1; + last_timer = time(NULL); + } + end_critical_section(S_HOUSEKEEPING); + if (do_housekeeping_now == 0) return; + + /* + * Ok, at this point we've made the decision to run the housekeeping + * loop. Everything below this point is real work. + */ + + cdb_check_handles(); /* suggested by Justin Case */ + PerformSessionHooks(EVT_TIMER); /* Run any timer hooks */ + + /* + * All done. + */ + housekeeping_in_progress = 0; +} diff --git a/citadel/housekeeping.h b/citadel/housekeeping.h index f7b99bc5f..e7048dc5b 100644 --- a/citadel/housekeeping.h +++ b/citadel/housekeeping.h @@ -2,3 +2,4 @@ void terminate_idle_sessions(void); void check_sched_shutdown(void); void check_ref_counts(void); +void do_housekeeping(void); diff --git a/citadel/server.h b/citadel/server.h index 69d4b25b7..103d5a543 100644 --- a/citadel/server.h +++ b/citadel/server.h @@ -171,6 +171,7 @@ enum { S_I_WANNA_SELECT, S_CONFIG, S_WORKER_LIST, + S_HOUSEKEEPING, MAX_SEMAPHORES }; diff --git a/citadel/sysconfig.h b/citadel/sysconfig.h index 378a3b639..4bbf9faa7 100644 --- a/citadel/sysconfig.h +++ b/citadel/sysconfig.h @@ -65,13 +65,6 @@ #define DEFAULT_VERBOSITY 9 -/* - * HOUSEKEEPING_WAKEUP is the number of seconds which pass between each pass - * of the housekeeping thread. This normally happens once per minute and there - * isn't any good reason to change it. - */ -#define HOUSEKEEPING_WAKEUP 60 - /* * NLI is the string that shows up in a ho's online listing for sessions diff --git a/citadel/sysdep.c b/citadel/sysdep.c index ee995dd21..b17a605b3 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -89,8 +89,6 @@ int num_sessions = 0; /* Current number of sessions */ fd_set masterfds; /* Master sockets etc. */ int masterhighest; -time_t last_timer = 0L; /* Last timer hook processing */ - static pthread_t initial_thread; /* tid for main() thread */ @@ -1295,12 +1293,7 @@ SETUP_FD: memcpy(&readfds, &masterfds, sizeof masterfds); } dead_session_purge(); - if ((time(NULL) - last_timer) > 60L) { - last_timer = time(NULL); - cdb_check_handles(); /* suggested by Justin Case */ - PerformSessionHooks(EVT_TIMER); - } - + do_housekeeping(); check_sched_shutdown(); } -- 2.30.2