Module Name: othersrc
Committed By: dholland
Date: Sat Mar 23 21:25:31 UTC 2013
Modified Files:
othersrc/usr.bin/dholland-make2: make.c
Log Message:
Wrap the toBeMade list code in a queue abstraction. Use the same list
code on the inside for now.
To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 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.8 othersrc/usr.bin/dholland-make2/make.c:1.9
--- othersrc/usr.bin/dholland-make2/make.c:1.8 Tue Mar 5 04:27:27 2013
+++ othersrc/usr.bin/dholland-make2/make.c Sat Mar 23 21:25:31 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: make.c,v 1.8 2013/03/05 04:27:27 dholland Exp $ */
+/* $NetBSD: make.c,v 1.9 2013/03/23 21:25:31 dholland Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@@ -111,14 +111,24 @@
#include "dir.h"
#include "job.h"
-MAKE_RCSID("$NetBSD: make.c,v 1.8 2013/03/05 04:27:27 dholland Exp $");
+MAKE_RCSID("$NetBSD: make.c,v 1.9 2013/03/23 21:25:31 dholland Exp $");
+
+typedef struct {
+ LstNode elem;
+} QPos;
+
+typedef struct {
+ Lst data;
+} MakeQ;
static unsigned int checked = 1;/* Sequence # to detect recursion */
-static Lst toBeMade; /* The current fringe of the graph. These
- * are nodes which await examination by
- * MakeOODate. It is added to by
- * Make_Update and subtracted from by
- * MakeStartJobs */
+
+/*
+ * The current fringe of the graph. These are nodes which await
+ * examination by MakeOODate. It is added to by Make_Update and
+ * subtracted from by MakeStartJobs.
+ */
+static MakeQ toBeMade;
static void MakeAddChild(GNode *, GList *);
static void MakeFindChild(GNode *, GNode *);
@@ -129,8 +139,70 @@ static Boolean MakeStartJobs(void);
static int MakePrintStatus(GNode *, int *);
static int MakeCheckOrder(GNode *);
static int DoMakeCheckOrder(GList *);
-static int MakeBuildChild(GNode *, LstNode);
-static void MakeBuildParent(GNode *, LstNode);
+static int MakeBuildChild(GNode *, QPos *);
+static void MakeBuildParent(GNode *, QPos *);
+
+////////////////////////////////////////////////////////////
+// MakeQ
+
+static void
+MakeQ_Init(MakeQ *q)
+{
+ q->data = Lst_Init(FALSE);
+}
+
+static Boolean
+MakeQ_IsEmpty(MakeQ *q)
+{
+ return Lst_IsEmpty(q->data);
+}
+
+static void
+MakeQ_AddTail(MakeQ *q, GNode *gn)
+{
+ (void)Lst_EnQueue(q->data, gn);
+}
+
+static void
+MakeQ_Insert(MakeQ *q, QPos *before, GNode *gn)
+{
+ Lst_InsertBefore(q->data, before->elem, gn);
+}
+
+static GNode *
+MakeQ_PopHead(MakeQ *q)
+{
+ return (GNode *)Lst_DeQueue(q->data);
+}
+
+static void
+MakeQ_ForEach(MakeQ *q, int (*func)(void *, void *), void *ptr)
+{
+ Lst_ForEach(q->data, func, ptr);
+}
+
+static QPos *
+QPos_Create(LstNode elem)
+{
+ QPos *ret;
+
+ ret = bmake_malloc(sizeof(*ret));
+ ret->elem = elem;
+ return ret;
+}
+
+static QPos *
+MakeQ_First(MakeQ *q)
+{
+ QPos *ret;
+
+ // XXX this leaks memory
+ ret = QPos_Create(Lst_First(q->data));
+ return ret;
+}
+
+////////////////////////////////////////////////////////////
+// unsorted code
/* XXX: non-typesafe wrapper for list code; remove when possible */
static int
@@ -147,7 +219,7 @@ make_abort(GNode *gn, int line)
fprintf(debug_file, "make_abort from line %d\n", line);
Targ_PrintNode(gn, &two);
- Lst_ForEach(toBeMade, doTarg_PrintNode, &two);
+ MakeQ_ForEach(&toBeMade, doTarg_PrintNode, &two);
Targ_PrintGraph(3);
abort();
}
@@ -725,7 +797,7 @@ Make_Update(GNode *cgn)
for (i=0; i<glist_num(¢urion->order_succ); i++) {
succ = glist_get(¢urion->order_succ, i);
- MakeBuildParent(succ, Lst_First(toBeMade));
+ MakeBuildParent(succ, MakeQ_First(&toBeMade));
}
}
@@ -823,7 +895,7 @@ Make_Update(GNode *cgn)
}
/* Ok, we can schedule the parent again */
pgn->made = REQUESTED;
- (void)Lst_EnQueue(toBeMade, pgn);
+ MakeQ_AddTail(&toBeMade, pgn);
}
}
@@ -1042,7 +1114,7 @@ DoMakeCheckOrder(GList *order_pred)
}
static int
-MakeBuildChild(GNode *cn, LstNode toBeMade_next)
+MakeBuildChild(GNode *cn, QPos *toBeMade_next)
{
if (DEBUG(MAKE))
fprintf(debug_file, "MakeBuildChild: inspect %s%s, made %d, type %x\n",
@@ -1063,9 +1135,9 @@ MakeBuildChild(GNode *cn, LstNode toBeMa
cn->made = REQUESTED;
if (toBeMade_next == NULL)
- Lst_AtEnd(toBeMade, cn);
+ MakeQ_AddTail(&toBeMade, cn);
else
- Lst_InsertBefore(toBeMade, toBeMade_next, cn);
+ MakeQ_Insert(&toBeMade, toBeMade_next, cn);
if (cn->unmade_cohorts != 0) {
unsigned i;
@@ -1086,7 +1158,7 @@ MakeBuildChild(GNode *cn, LstNode toBeMa
/* When a .ORDER LHS node completes we do this on each RHS */
static void
-MakeBuildParent(GNode *pn, LstNode toBeMade_next)
+MakeBuildParent(GNode *pn, QPos *toBeMade_next)
{
if (pn->made != DEFERRED)
return;
@@ -1104,13 +1176,13 @@ MakeStartJobs(void)
int have_token = 0;
unsigned i;
- while (!Lst_IsEmpty (toBeMade)) {
+ while (!MakeQ_IsEmpty(&toBeMade)) {
/* Get token now to avoid cycling job-list when we only have 1 token */
if (!have_token && !Job_TokenWithdraw())
break;
have_token = 1;
- gn = (GNode *)Lst_DeQueue(toBeMade);
+ gn = MakeQ_PopHead(&toBeMade);
if (DEBUG(MAKE))
fprintf(debug_file, "Examining %s%s...\n",
gn->name, gn->cohort_num);
@@ -1139,7 +1211,7 @@ MakeStartJobs(void)
*/
gn->made = DEFERRED;
for (i=0; i<glist_num(&gn->children); i++) {
- if (MakeBuildChild(glist_get(&gn->children, i), Lst_First(toBeMade))) {
+ if (MakeBuildChild(glist_get(&gn->children, i), MakeQ_First(&toBeMade))) {
break;
}
}
@@ -1575,7 +1647,7 @@ Make_Run(GList *targs)
unsigned i, num;
/* Start trying to make the current targets... */
- toBeMade = Lst_Init(FALSE);
+ MakeQ_Init(&toBeMade);
Make_ExpandUse(targs);
Make_ProcessWait(targs);
@@ -1612,7 +1684,7 @@ Make_Run(GList *targs)
* Note that the Job module will exit if there were any errors unless the
* keepgoing flag was given.
*/
- while (!Lst_IsEmpty(toBeMade) || jobTokensRunning > 0) {
+ while (!MakeQ_IsEmpty(&toBeMade) || jobTokensRunning > 0) {
Job_CatchOutput();
(void)MakeStartJobs();
}