* Silly cosmetic change to keep the wholist ordered by ascending session number
authorArt Cancro <ajc@citadel.org>
Mon, 16 Jul 2001 14:24:30 +0000 (14:24 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 16 Jul 2001 14:24:30 +0000 (14:24 +0000)
citadel/ChangeLog
citadel/sysdep.c

index edc917f58008d49c417d4d6d49c0c2d98d36bd4a..e7fa3337d438c841385431fae9b42d1257206777 100644 (file)
@@ -1,4 +1,7 @@
  $Log$
+ Revision 580.4  2001/07/16 14:24:30  ajc
+ * Silly cosmetic change to keep the wholist ordered by ascending session number
+
  Revision 580.3  2001/07/13 00:01:36  ajc
  * Shuffled around some of the housekeeping loop code
 
@@ -2571,4 +2574,3 @@ 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 b17a605b379f851a762e0e1ddde8f098e5ef6a62..5e0e649331007ffed0e618dbc43de58aa4694887 100644 (file)
@@ -408,8 +408,6 @@ struct CitContext *MyContext(void) {
  */
 struct CitContext *CreateNewContext(void) {
        struct CitContext *me, *ptr;
-       int num = 1;
-       int startover = 0;
 
        me = (struct CitContext *) mallok(sizeof(struct CitContext));
        if (me == NULL) {
@@ -424,24 +422,43 @@ struct CitContext *CreateNewContext(void) {
         */
        me->state = CON_EXECUTING;
 
+
+       /*
+        * Generate a unique session number and insert this context into
+        * the list.
+        */
        begin_critical_section(S_SESSION_TABLE);
 
-       /* obtain a unique session number */
-       do {
-               startover = 0;
+       if (ContextList == NULL) {
+               ContextList = me;
+               me->cs_pid = 1;
+               me->next = NULL;
+       }
+
+       else if (ContextList->cs_pid > 1) {
+               me->next = ContextList;
+               ContextList = me;
+               me->cs_pid = 1;
+       }
+
+       else {
                for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
-                       if (ptr->cs_pid == num) {
-                               ++num;
-                               startover = 1;
+                       if (ptr->next == NULL) {
+                               ptr->next = me;
+                               me->cs_pid = ptr->cs_pid + 1;
+                               me->next = NULL;
+                               goto DONE;
+                       }
+                       else if (ptr->next->cs_pid > (ptr->cs_pid+1)) {
+                               me->next = ptr->next;
+                               ptr->next = me;
+                               me->cs_pid = ptr->cs_pid + 1;
+                               goto DONE;
                        }
                }
-       } while (startover == 1);
-
-       me->cs_pid = num;
-       me->next = ContextList;
-       ContextList = me;
-       ++num_sessions;
+       }
 
+DONE:  ++num_sessions;
        end_critical_section(S_SESSION_TABLE);
        return(me);
 }