From 0f6ef7a9ed3d75b737ba284ea7828ce26ee836a3 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Mon, 16 Jul 2001 14:24:30 +0000 Subject: [PATCH] * Silly cosmetic change to keep the wholist ordered by ascending session number --- citadel/ChangeLog | 4 +++- citadel/sysdep.c | 45 +++++++++++++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index edc917f58..e7fa3337d 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -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 Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/sysdep.c b/citadel/sysdep.c index b17a605b3..5e0e64933 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -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); } -- 2.39.2