Module Name:    src
Committed By:   rillig
Date:           Fri Oct 23 04:58:33 UTC 2020

Modified Files:
        src/usr.bin/make: lst.c lst.h make.c

Log Message:
make(1): remove Lst_ForEachUntilConcurrent

The remaining callers of that function don't modify the list
structurally and thus can use the simpler Lst_ForEachUntil instead.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/usr.bin/make/lst.c
cvs rdiff -u -r1.77 -r1.78 src/usr.bin/make/lst.h
cvs rdiff -u -r1.175 -r1.176 src/usr.bin/make/make.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/make/lst.c
diff -u src/usr.bin/make/lst.c:1.82 src/usr.bin/make/lst.c:1.83
--- src/usr.bin/make/lst.c:1.82	Thu Oct 22 21:27:24 2020
+++ src/usr.bin/make/lst.c	Fri Oct 23 04:58:33 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.82 2020/10/22 21:27:24 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.83 2020/10/23 04:58:33 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -34,7 +34,7 @@
 
 #include "make.h"
 
-MAKE_RCSID("$NetBSD: lst.c,v 1.82 2020/10/22 21:27:24 rillig Exp $");
+MAKE_RCSID("$NetBSD: lst.c,v 1.83 2020/10/23 04:58:33 rillig Exp $");
 
 /* Allocate and initialize a list node.
  *
@@ -44,8 +44,6 @@ static ListNode *
 LstNodeNew(void *datum)
 {
     ListNode *node = bmake_malloc(sizeof *node);
-    node->priv_useCount = 0;
-    node->priv_deleted = FALSE;
     node->datum = datum;
     return node;
 }
@@ -214,16 +212,6 @@ Lst_Remove(List *list, ListNode *node)
     if (list->last == node) {
 	list->last = node->prev;
     }
-
-    /*
-     * note that the datum is unmolested. The caller must free it as
-     * necessary and as expected.
-     */
-    if (node->priv_useCount == 0) {
-	free(node);
-    } else {
-	node->priv_deleted = TRUE;
-    }
 }
 
 /* Replace the datum in the given node with the new datum. */
@@ -293,9 +281,6 @@ Lst_FindDatum(List *list, const void *da
     return NULL;
 }
 
-/* Apply the given function to each element of the given list, until the
- * function returns non-zero. During this iteration, the list must not be
- * modified structurally. */
 int
 Lst_ForEachUntil(List *list, LstActionUntilProc proc, void *procData)
 {
@@ -310,54 +295,6 @@ Lst_ForEachUntil(List *list, LstActionUn
     return result;
 }
 
-/* Apply the given function to each element of the given list. The function
- * should return 0 if traversal should continue and non-zero if it should
- * abort. */
-int
-Lst_ForEachUntilConcurrent(List *list, LstActionUntilProc proc, void *procData)
-{
-    ListNode *tln = list->first;
-    int result = 0;
-
-    while (tln != NULL) {
-	/*
-	 * Take care of having the current element deleted out from under
-	 * us.
-	 */
-	ListNode *next = tln->next;
-
-	/*
-	 * We're done with the traversal if
-	 *  - the next node to examine doesn't exist and
-	 *  - nothing's been added after the current node (check this
-	 *    after proc() has been called).
-	 */
-	Boolean done = next == NULL;
-
-	tln->priv_useCount++;
-	result = proc(tln->datum, procData);
-	tln->priv_useCount--;
-
-	/*
-	 * Now check whether a node has been added.
-	 * Note: this doesn't work if this node was deleted before
-	 *       the new node was added.
-	 */
-	if (next != tln->next) {
-	    next = tln->next;
-	    done = FALSE;
-	}
-
-	if (tln->priv_deleted)
-	    free(tln);
-	tln = next;
-	if (result || LstIsEmpty(list) || done)
-	    break;
-    }
-
-    return result;
-}
-
 /* Move all nodes from list2 to the end of list1.
  * List2 is destroyed and freed. */
 void

Index: src/usr.bin/make/lst.h
diff -u src/usr.bin/make/lst.h:1.77 src/usr.bin/make/lst.h:1.78
--- src/usr.bin/make/lst.h:1.77	Thu Oct 22 21:27:24 2020
+++ src/usr.bin/make/lst.h	Fri Oct 23 04:58:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: lst.h,v 1.77 2020/10/22 21:27:24 rillig Exp $	*/
+/*	$NetBSD: lst.h,v 1.78 2020/10/23 04:58:33 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -90,10 +90,6 @@ typedef	struct ListNode	ListNode;
 struct ListNode {
     ListNode *prev;		/* previous node in list, or NULL */
     ListNode *next;		/* next node in list, or NULL */
-    uint8_t priv_useCount;	/* Count of functions using the node.
-				 * node may not be deleted until count
-				 * goes to 0 */
-    Boolean priv_deleted;	/* List node should be removed when done */
     union {
 	void *datum;		/* datum associated with this element */
 	const struct GNode *priv_gnode; /* alias, just for debugging */
@@ -164,10 +160,11 @@ void LstNode_SetNull(ListNode *);
 
 /* Iterating over a list, using a callback function */
 
-/* Apply a function to each datum of the list, until the callback function
- * returns non-zero. */
+/* Run the action for each datum of the list, until the action returns
+ * non-zero.
+ *
+ * During this iteration, the list must not be modified structurally. */
 int Lst_ForEachUntil(List *, LstActionUntilProc, void *);
-int Lst_ForEachUntilConcurrent(List *, LstActionUntilProc, void *);
 
 /* Iterating over a list while keeping track of the current node and possible
  * concurrent modifications */

Index: src/usr.bin/make/make.c
diff -u src/usr.bin/make/make.c:1.175 src/usr.bin/make/make.c:1.176
--- src/usr.bin/make/make.c:1.175	Thu Oct 22 21:53:01 2020
+++ src/usr.bin/make/make.c	Fri Oct 23 04:58:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.c,v 1.175 2020/10/22 21:53:01 rillig Exp $	*/
+/*	$NetBSD: make.c,v 1.176 2020/10/23 04:58:33 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -107,7 +107,7 @@
 #include    "job.h"
 
 /*	"@(#)make.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: make.c,v 1.175 2020/10/22 21:53:01 rillig Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.176 2020/10/23 04:58:33 rillig Exp $");
 
 /* Sequence # to detect recursion. */
 static unsigned int checked = 1;
@@ -645,8 +645,7 @@ Make_Update(GNode *cgn)
     parents = centurion->parents;
 
     /* If this was a .ORDER node, schedule the RHS */
-    Lst_ForEachUntilConcurrent(centurion->order_succ,
-			       MakeBuildParent, toBeMade->first);
+    Lst_ForEachUntil(centurion->order_succ, MakeBuildParent, toBeMade->first);
 
     /* Now mark all the parents as having one less unmade child */
     for (ln = parents->first; ln != NULL; ln = ln->next) {
@@ -901,7 +900,7 @@ MakeBuildChild(void *v_cn, void *toBeMad
 	Lst_InsertBefore(toBeMade, toBeMade_next, cn);
 
     if (cn->unmade_cohorts != 0)
-	Lst_ForEachUntilConcurrent(cn->cohorts, MakeBuildChild, toBeMade_next);
+	Lst_ForEachUntil(cn->cohorts, MakeBuildChild, toBeMade_next);
 
     /*
      * If this node is a .WAIT node with unmade children
@@ -968,8 +967,7 @@ MakeStartJobs(void)
 	     * just before the current first element.
 	     */
 	    gn->made = DEFERRED;
-	    Lst_ForEachUntilConcurrent(gn->children,
-				       MakeBuildChild, toBeMade->first);
+	    Lst_ForEachUntil(gn->children, MakeBuildChild, toBeMade->first);
 	    /* and drop this node on the floor */
 	    DEBUG2(MAKE, "dropped %s%s\n", gn->name, gn->cohort_num);
 	    continue;
@@ -1177,7 +1175,7 @@ Make_ExpandUse(GNodeList *targs)
 	    Suff_FindDeps(gn);
 	else {
 	    /* Pretend we made all this node's children */
-	    Lst_ForEachUntilConcurrent(gn->children, MakeFindChild, gn);
+	    Lst_ForEachUntil(gn->children, MakeFindChild, gn);
 	    if (gn->unmade != 0)
 		    printf("Warning: %s%s still has %d unmade children\n",
 			    gn->name, gn->cohort_num, gn->unmade);

Reply via email to