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.
This commit is contained in:
parent
96be28584f
commit
76a498de62
|
@ -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
|
* Copyright (c) 1988, 1989, 1990, 1993
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
|
|
||||||
#include "make.h"
|
#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.
|
/* Allocate and initialize a list node.
|
||||||
*
|
*
|
||||||
|
@ -44,8 +44,6 @@ static ListNode *
|
||||||
LstNodeNew(void *datum)
|
LstNodeNew(void *datum)
|
||||||
{
|
{
|
||||||
ListNode *node = bmake_malloc(sizeof *node);
|
ListNode *node = bmake_malloc(sizeof *node);
|
||||||
node->priv_useCount = 0;
|
|
||||||
node->priv_deleted = FALSE;
|
|
||||||
node->datum = datum;
|
node->datum = datum;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@ -214,16 +212,6 @@ Lst_Remove(List *list, ListNode *node)
|
||||||
if (list->last == node) {
|
if (list->last == node) {
|
||||||
list->last = node->prev;
|
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. */
|
/* Replace the datum in the given node with the new datum. */
|
||||||
|
@ -293,9 +281,6 @@ Lst_FindDatum(List *list, const void *datum)
|
||||||
return NULL;
|
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
|
int
|
||||||
Lst_ForEachUntil(List *list, LstActionUntilProc proc, void *procData)
|
Lst_ForEachUntil(List *list, LstActionUntilProc proc, void *procData)
|
||||||
{
|
{
|
||||||
|
@ -310,54 +295,6 @@ Lst_ForEachUntil(List *list, LstActionUntilProc proc, void *procData)
|
||||||
return result;
|
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.
|
/* Move all nodes from list2 to the end of list1.
|
||||||
* List2 is destroyed and freed. */
|
* List2 is destroyed and freed. */
|
||||||
void
|
void
|
||||||
|
|
|
@ -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.
|
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
|
||||||
|
@ -90,10 +90,6 @@ typedef struct ListNode ListNode;
|
||||||
struct ListNode {
|
struct ListNode {
|
||||||
ListNode *prev; /* previous node in list, or NULL */
|
ListNode *prev; /* previous node in list, or NULL */
|
||||||
ListNode *next; /* next 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 {
|
union {
|
||||||
void *datum; /* datum associated with this element */
|
void *datum; /* datum associated with this element */
|
||||||
const struct GNode *priv_gnode; /* alias, just for debugging */
|
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 */
|
/* Iterating over a list, using a callback function */
|
||||||
|
|
||||||
/* Apply a function to each datum of the list, until the callback function
|
/* Run the action for each datum of the list, until the action returns
|
||||||
* returns non-zero. */
|
* non-zero.
|
||||||
|
*
|
||||||
|
* During this iteration, the list must not be modified structurally. */
|
||||||
int Lst_ForEachUntil(List *, LstActionUntilProc, void *);
|
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
|
/* Iterating over a list while keeping track of the current node and possible
|
||||||
* concurrent modifications */
|
* concurrent modifications */
|
||||||
|
|
|
@ -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
|
* Copyright (c) 1988, 1989, 1990, 1993
|
||||||
|
@ -107,7 +107,7 @@
|
||||||
#include "job.h"
|
#include "job.h"
|
||||||
|
|
||||||
/* "@(#)make.c 8.1 (Berkeley) 6/6/93" */
|
/* "@(#)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. */
|
/* Sequence # to detect recursion. */
|
||||||
static unsigned int checked = 1;
|
static unsigned int checked = 1;
|
||||||
|
@ -645,8 +645,7 @@ Make_Update(GNode *cgn)
|
||||||
parents = centurion->parents;
|
parents = centurion->parents;
|
||||||
|
|
||||||
/* If this was a .ORDER node, schedule the RHS */
|
/* If this was a .ORDER node, schedule the RHS */
|
||||||
Lst_ForEachUntilConcurrent(centurion->order_succ,
|
Lst_ForEachUntil(centurion->order_succ, MakeBuildParent, toBeMade->first);
|
||||||
MakeBuildParent, toBeMade->first);
|
|
||||||
|
|
||||||
/* Now mark all the parents as having one less unmade child */
|
/* Now mark all the parents as having one less unmade child */
|
||||||
for (ln = parents->first; ln != NULL; ln = ln->next) {
|
for (ln = parents->first; ln != NULL; ln = ln->next) {
|
||||||
|
@ -901,7 +900,7 @@ MakeBuildChild(void *v_cn, void *toBeMade_next)
|
||||||
Lst_InsertBefore(toBeMade, toBeMade_next, cn);
|
Lst_InsertBefore(toBeMade, toBeMade_next, cn);
|
||||||
|
|
||||||
if (cn->unmade_cohorts != 0)
|
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
|
* If this node is a .WAIT node with unmade children
|
||||||
|
@ -968,8 +967,7 @@ MakeStartJobs(void)
|
||||||
* just before the current first element.
|
* just before the current first element.
|
||||||
*/
|
*/
|
||||||
gn->made = DEFERRED;
|
gn->made = DEFERRED;
|
||||||
Lst_ForEachUntilConcurrent(gn->children,
|
Lst_ForEachUntil(gn->children, MakeBuildChild, toBeMade->first);
|
||||||
MakeBuildChild, toBeMade->first);
|
|
||||||
/* and drop this node on the floor */
|
/* and drop this node on the floor */
|
||||||
DEBUG2(MAKE, "dropped %s%s\n", gn->name, gn->cohort_num);
|
DEBUG2(MAKE, "dropped %s%s\n", gn->name, gn->cohort_num);
|
||||||
continue;
|
continue;
|
||||||
|
@ -1177,7 +1175,7 @@ Make_ExpandUse(GNodeList *targs)
|
||||||
Suff_FindDeps(gn);
|
Suff_FindDeps(gn);
|
||||||
else {
|
else {
|
||||||
/* Pretend we made all this node's children */
|
/* Pretend we made all this node's children */
|
||||||
Lst_ForEachUntilConcurrent(gn->children, MakeFindChild, gn);
|
Lst_ForEachUntil(gn->children, MakeFindChild, gn);
|
||||||
if (gn->unmade != 0)
|
if (gn->unmade != 0)
|
||||||
printf("Warning: %s%s still has %d unmade children\n",
|
printf("Warning: %s%s still has %d unmade children\n",
|
||||||
gn->name, gn->cohort_num, gn->unmade);
|
gn->name, gn->cohort_num, gn->unmade);
|
||||||
|
|
Loading…
Reference in New Issue