* Shuffled around the order of events when a thread is terminating. All
authorArt Cancro <ajc@citadel.org>
Tue, 26 Oct 1999 03:48:40 +0000 (03:48 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 26 Oct 1999 03:48:40 +0000 (03:48 +0000)
  mutex operations now happen prior to the freeing of the CitContext structure,
  otherwise begin_critical_section() and end_critical_section() try to
  manipulate the context's mutex count when there isn't any context.

citadel/ChangeLog
citadel/citserver.c
citadel/housekeeping.c
citadel/sysdep.c

index 18a4babd3d97581efcb2e1d5ec9297a860a3217b..7b0ce4ea9ac518ab8de13d6fb9a29e9c59982fcb 100644 (file)
@@ -1,10 +1,13 @@
 $Log$
+Revision 1.395  1999/10/26 03:48:39  ajc
+* Shuffled around the order of events when a thread is terminating.  All
+  mutex operations now happen prior to the freeing of the CitContext structure,
+  otherwise begin_critical_section() and end_critical_section() try to
+  manipulate the context's mutex count when there isn't any context.
+
 Revision 1.394  1999/10/26 03:21:16  ajc
 * Changed a lot of strncpy() calls to safestrncpy() and replaced most of their
   hardcoded size arguments with 'sizeof' based arguments.
-* Moved the CitContext destruction into the housekeeper thread and out of the
-  thread being cancelled.  Didn't fix it, though (to see what happens, link
-  the server against ElectricFence and watch what happens when a session ends).
 
 Revision 1.393  1999/10/24 19:22:51  nbryant
        * Makefile.in, configure.in: added --enable-icq flag; made checks for
index 7343e230d0fe124ee3839ad7e4c58663937608aa..8a9f9b9ec9454de08cc30b104e79c8c4cc8a2fe0 100644 (file)
@@ -124,8 +124,6 @@ void deallocate_user_data(struct CitContext *con)
  */
 void cleanup_stuff(void *arg)
 {
-       char buf[256];
-
        lprintf(9, "cleanup_stuff() called\n");
 
        lprintf(7, "Calling logout(%d)\n", CC->cs_pid);
@@ -148,14 +146,8 @@ void cleanup_stuff(void *arg)
         * halfway through, and the context being destroyed can't be the one
         * doing the work.
         */
-       lprintf(7, "Scheduling housekeeper REMOVE_CONTEXT(%d)\n", CC->cs_pid);
-       sprintf(buf, "REMOVE_CONTEXT|%d", CC->cs_pid);
-       enter_housekeeping_cmd(buf);
-
-       /* Tell the housekeeping thread to check to see if this is the time
-        * to initiate a scheduled shutdown event.
-        */
-       enter_housekeeping_cmd("SCHED_SHUTDOWN");
+       lprintf(7, "Calling RemoveContext(%d)\n", CC->cs_pid);
+       RemoveContext(CC->cs_pid);
        }
 
 
index fef2f694c70f92fafd84bc548ede104f74790411..726c928158e213e09ce0dc51c0a02f8033eeb9b6 100644 (file)
@@ -134,11 +134,6 @@ void housekeeping_loop(void) {
                                check_sched_shutdown();
                        }
 
-                       /* Remove a context (session ending) */
-                       else if (!strcmp(cmd, "REMOVE_CONTEXT")) {
-                               RemoveContext( extract_int(house_cmd, 1) );
-                       }
-
                        /* Unknown */
                        else {
                                lprintf(7, "Unknown housekeeping command\n");
@@ -156,10 +151,12 @@ void housekeeping_loop(void) {
 void enter_housekeeping_cmd(char *cmd) {
        char cmdbuf[256];
 
+       lprintf(9, "enter_housekeeping_cmd(%s)\n", cmd);
        safestrncpy(cmdbuf, cmd, 256);
        begin_critical_section(S_HOUSEKEEPING);
        write(housepipe[1], cmdbuf, 256);
        end_critical_section(S_HOUSEKEEPING);
+       lprintf(9, "leaving enter_housekeeping_cmd()\n");
 }
        
 
index 26d132b5fe9270e6d2618204a723495a98281be5..32fb846e937f85b86a0c769be56b9a3e0cfff117 100644 (file)
@@ -256,7 +256,7 @@ void begin_critical_section(int which_one)
                /* Keep a count of how many critical sections this thread has
                 * open, so that end_critical_section() doesn't enable
                 * cancellation prematurely. */
-               CC->n_crit++;
+               if (CC != NULL) CC->n_crit++;
 #ifdef HAVE_PTHREAD_CANCEL
                /* Don't get interrupted during the critical section */
                pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, &oldval);
@@ -291,6 +291,7 @@ void end_critical_section(int which_one)
        pthread_mutex_unlock(&Critters[which_one]);
 
        if (!pthread_equal(pthread_self(), main_thread_id))
+       if (CC != NULL)
        if (!--CC->n_crit) {
 #ifdef HAVE_PTHREAD_CANCEL
                /* If a cancel was sent during the critical section, do it now.
@@ -464,11 +465,19 @@ void RemoveContext(int con)
                }
 
 
+       end_critical_section(S_SESSION_TABLE);
+
        lprintf(7, "Closing socket %d\n", ToFree->client_socket);
        close(ToFree->client_socket);
+
+        /* Tell the housekeeping thread to check to see if this is the time
+         * to initiate a scheduled shutdown event.
+         */
+        enter_housekeeping_cmd("SCHED_SHUTDOWN");
+
+       /* Free up the memory used by this context */
        phree(ToFree);
 
-       end_critical_section(S_SESSION_TABLE);
        lprintf(7, "Done with RemoveContext\n");
        }