Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): remove Lst_ForEachUntilConcurrent



details:   https://anonhg.NetBSD.org/src/rev/f07d442172c7
branches:  trunk
changeset: 977373:f07d442172c7
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Oct 23 04:58:33 2020 +0000

description:
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.

diffstat:

 usr.bin/make/lst.c  |  67 +---------------------------------------------------
 usr.bin/make/lst.h  |  13 +++------
 usr.bin/make/make.c |  14 ++++------
 3 files changed, 13 insertions(+), 81 deletions(-)

diffs (200 lines):

diff -r bab7f1ac8719 -r f07d442172c7 usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Fri Oct 23 00:25:45 2020 +0000
+++ b/usr.bin/make/lst.c        Fri Oct 23 04:58:33 2020 +0000
@@ -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 @@
 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 @@
     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 @@
     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 @@
     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
diff -r bab7f1ac8719 -r f07d442172c7 usr.bin/make/lst.h
--- a/usr.bin/make/lst.h        Fri Oct 23 00:25:45 2020 +0000
+++ b/usr.bin/make/lst.h        Fri Oct 23 04:58:33 2020 +0000
@@ -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 @@
 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 @@
 
 /* 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 */
diff -r bab7f1ac8719 -r f07d442172c7 usr.bin/make/make.c
--- a/usr.bin/make/make.c       Fri Oct 23 00:25:45 2020 +0000
+++ b/usr.bin/make/make.c       Fri Oct 23 04:58:33 2020 +0000
@@ -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 @@
     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 @@
        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 @@
             * 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 @@
            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);



Home | Main Index | Thread Index | Old Index