Module Name:    othersrc
Committed By:   dholland
Date:           Sat Mar 23 21:27:23 UTC 2013

Modified Files:
        othersrc/usr.bin/dholland-make2: make.c

Log Message:
Simplify the toBeMade logic based on the fact that only one group of
non-tail insertions is done at a time, so the insertion point can be
tracked by the queue.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 othersrc/usr.bin/dholland-make2/make.c

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

Modified files:

Index: othersrc/usr.bin/dholland-make2/make.c
diff -u othersrc/usr.bin/dholland-make2/make.c:1.9 othersrc/usr.bin/dholland-make2/make.c:1.10
--- othersrc/usr.bin/dholland-make2/make.c:1.9	Sat Mar 23 21:25:31 2013
+++ othersrc/usr.bin/dholland-make2/make.c	Sat Mar 23 21:27:23 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: make.c,v 1.9 2013/03/23 21:25:31 dholland Exp $	*/
+/*	$NetBSD: make.c,v 1.10 2013/03/23 21:27:23 dholland Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -111,14 +111,12 @@
 #include    "dir.h"
 #include    "job.h"
 
-MAKE_RCSID("$NetBSD: make.c,v 1.9 2013/03/23 21:25:31 dholland Exp $");
-
-typedef struct {
-	LstNode elem;
-} QPos;
+MAKE_RCSID("$NetBSD: make.c,v 1.10 2013/03/23 21:27:23 dholland Exp $");
 
 typedef struct {
 	Lst data;
+	Boolean hasmark;
+	LstNode mark;
 } MakeQ;
 
 static unsigned int checked = 1;/* Sequence # to detect recursion */
@@ -139,8 +137,8 @@ static Boolean MakeStartJobs(void);
 static int MakePrintStatus(GNode *, int *);
 static int MakeCheckOrder(GNode *);
 static int DoMakeCheckOrder(GList *);
-static int MakeBuildChild(GNode *, QPos *);
-static void MakeBuildParent(GNode *, QPos *);
+static int MakeBuildChild(GNode *, Boolean);
+static void MakeBuildParent(GNode *, Boolean);
 
 ////////////////////////////////////////////////////////////
 // MakeQ
@@ -149,6 +147,8 @@ static void
 MakeQ_Init(MakeQ *q)
 {
     q->data = Lst_Init(FALSE);
+    q->hasmark = FALSE;
+    q->mark = NULL;
 }
 
 static Boolean
@@ -164,41 +164,46 @@ MakeQ_AddTail(MakeQ *q, GNode *gn)
 }
 
 static void
-MakeQ_Insert(MakeQ *q, QPos *before, GNode *gn)
-{ 
-	Lst_InsertBefore(q->data, before->elem, gn);
+MakeQ_AddBeforeMark(MakeQ *q, GNode *gn)
+{
+	assert(q->hasmark);
+	if (q->mark == NULL) {
+		Lst_AtEnd(q->data, gn);
+	} else {
+		Lst_InsertBefore(q->data, q->mark, gn);
+	}
 }
 
-static GNode *
-MakeQ_PopHead(MakeQ *q)
+static void
+MakeQ_SetMark(MakeQ *q)
 {
-	return (GNode *)Lst_DeQueue(q->data);
+	assert(!q->hasmark);
+	q->hasmark = TRUE;
+	if (Lst_IsEmpty(q->data)) {
+		q->mark = NULL;
+	} else {
+		q->mark = Lst_First(q->data);
+	}
 }
 
 static void
-MakeQ_ForEach(MakeQ *q, int (*func)(void *, void *), void *ptr)
+MakeQ_ClearMark(MakeQ *q)
 {
-	Lst_ForEach(q->data, func, ptr);
+	assert(q->hasmark);
+	q->hasmark = FALSE;
+	q->mark = NULL;
 }
 
-static QPos *
-QPos_Create(LstNode elem)
+static GNode *
+MakeQ_PopHead(MakeQ *q)
 {
-	QPos *ret;
-
-	ret = bmake_malloc(sizeof(*ret));
-	ret->elem = elem;
-	return ret;
+	return (GNode *)Lst_DeQueue(q->data);
 }
 
-static QPos *
-MakeQ_First(MakeQ *q)
+static void
+MakeQ_ForEach(MakeQ *q, int (*func)(void *, void *), void *ptr)
 {
-	QPos *ret;
-
-	// XXX this leaks memory
-	ret = QPos_Create(Lst_First(q->data));
-	return ret;
+	Lst_ForEach(q->data, func, ptr);
 }
 
 ////////////////////////////////////////////////////////////
@@ -797,7 +802,9 @@ Make_Update(GNode *cgn)
 
 	for (i=0; i<glist_num(&centurion->order_succ); i++) {
 	    succ = glist_get(&centurion->order_succ, i);
-	    MakeBuildParent(succ, MakeQ_First(&toBeMade));
+	    MakeQ_SetMark(&toBeMade);
+	    MakeBuildParent(succ, TRUE);
+	    MakeQ_ClearMark(&toBeMade);
 	}
     }
 
@@ -1114,7 +1121,7 @@ DoMakeCheckOrder(GList *order_pred)
 }
 
 static int
-MakeBuildChild(GNode *cn, QPos *toBeMade_next)
+MakeBuildChild(GNode *cn, Boolean usemark)
 {
     if (DEBUG(MAKE))
 	fprintf(debug_file, "MakeBuildChild: inspect %s%s, made %d, type %x\n",
@@ -1134,16 +1141,16 @@ MakeBuildChild(GNode *cn, QPos *toBeMade
 		cn->name, cn->cohort_num);
 
     cn->made = REQUESTED;
-    if (toBeMade_next == NULL)
+    if (usemark == FALSE)
 	MakeQ_AddTail(&toBeMade, cn);
     else
-	MakeQ_Insert(&toBeMade, toBeMade_next, cn);
+	MakeQ_AddBeforeMark(&toBeMade, cn);
 
     if (cn->unmade_cohorts != 0) {
 	unsigned i;
 
 	for (i=0; i<glist_num(&cn->cohorts); i++) {
-	    if (MakeBuildChild(glist_get(&cn->cohorts, i), toBeMade_next)) {
+	    if (MakeBuildChild(glist_get(&cn->cohorts, i), usemark)) {
 		break;
 	    }
 	}
@@ -1158,12 +1165,12 @@ MakeBuildChild(GNode *cn, QPos *toBeMade
 
 /* When a .ORDER LHS node completes we do this on each RHS */
 static void
-MakeBuildParent(GNode *pn, QPos *toBeMade_next)
+MakeBuildParent(GNode *pn, Boolean usemark)
 {
     if (pn->made != DEFERRED)
 	return;
 
-    if (MakeBuildChild(pn, toBeMade_next) == 0) {
+    if (MakeBuildChild(pn, usemark) == 0) {
 	/* Mark so that when this node is built we reschedule its parents */
 	pn->flags |= DONE_ORDER;
     }
@@ -1211,9 +1218,12 @@ MakeStartJobs(void)
 	     */
 	    gn->made = DEFERRED;
 	    for (i=0; i<glist_num(&gn->children); i++) {
-		if (MakeBuildChild(glist_get(&gn->children, i), MakeQ_First(&toBeMade))) {
+		MakeQ_SetMark(&toBeMade);
+		if (MakeBuildChild(glist_get(&gn->children, i), TRUE)) {
+		    MakeQ_ClearMark(&toBeMade);
 		    break;
 		}
+		MakeQ_ClearMark(&toBeMade);
 	    }
 	    /* and drop this node on the floor */
 	    if (DEBUG(MAKE))
@@ -1563,7 +1573,7 @@ Make_ProcessWait(GList *targs)
     }
 
     /* Start building with the 'dummy' .MAIN' node */
-    MakeBuildChild(pgn, NULL);
+    MakeBuildChild(pgn, FALSE);
 
     glist_init(&examine);
     glist_add(&examine, pgn, NULL);

Reply via email to