$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
Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
* Initial CVS import
+
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);
#include "database.h"
-int housepipe[2]; /* This is the queue for housekeeping tasks */
/*
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;
+}
#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
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 */
}
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();
}