* Shuffled around some of the housekeeping loop code
authorArt Cancro <ajc@citadel.org>
Fri, 13 Jul 2001 00:01:37 +0000 (00:01 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 13 Jul 2001 00:01:37 +0000 (00:01 +0000)
citadel/ChangeLog
citadel/citserver.h
citadel/housekeeping.c
citadel/housekeeping.h
citadel/server.h
citadel/sysconfig.h
citadel/sysdep.c

index cfa621368f92f9cfcd0e2ee019b4acbd172008f4..edc917f58008d49c417d4d6d49c0c2d98d36bd4a 100644 (file)
@@ -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 <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
+
index 1e6543f4269830ebb2a77045316b5693bc91e098..391e9d4f4421dce6bee4234412ba8d0e63b33109 100644 (file)
@@ -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);
index 2746b68de55126a7e4551c8f5f7e2e8bdd1c7b5a..34ca22092ed3f672bd290fba136420474d09b326 100644 (file)
@@ -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;
+}
index f7b99bc5f0d50318ac5def0cbb93a977ecebf053..e7048dc5bdd3e5271b2d28d7d51d3b7db98d29f2 100644 (file)
@@ -2,3 +2,4 @@
 void terminate_idle_sessions(void);
 void check_sched_shutdown(void);
 void check_ref_counts(void);
+void do_housekeeping(void);
index 69d4b25b79fc294aeabc55b3a571e44a4b8e31f9..103d5a543e220795aae35f8c9a7b88ac81b64d17 100644 (file)
@@ -171,6 +171,7 @@ enum {
        S_I_WANNA_SELECT,
        S_CONFIG,
        S_WORKER_LIST,
+       S_HOUSEKEEPING,
        MAX_SEMAPHORES
 };
 
index 378a3b639e0962e1e8d92b8ea3c8e8871b9beb3a..4bbf9faa7881c1ca3258f7a56252cd099ab2d826 100644 (file)
 #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 <W>ho's online listing for sessions
index ee995dd2198e1403221bc917af52a8a9ae09f210..b17a605b379f851a762e0e1ddde8f098e5ef6a62 100644 (file)
@@ -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();
        }