Make the fds[] realloc O(n). Also make the rethreading a lot simpler.

This commit is contained in:
mycroft 2000-12-05 21:57:20 +00:00
parent ac80517816
commit b91d3efb9a

View File

@ -1,4 +1,4 @@
/* $NetBSD: job.c,v 1.38 2000/12/05 15:28:55 sommerfeld Exp $ */ /* $NetBSD: job.c,v 1.39 2000/12/05 21:57:20 mycroft 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.
@ -39,14 +39,14 @@
*/ */
#ifdef MAKE_BOOTSTRAP #ifdef MAKE_BOOTSTRAP
static char rcsid[] = "$NetBSD: job.c,v 1.38 2000/12/05 15:28:55 sommerfeld Exp $"; static char rcsid[] = "$NetBSD: job.c,v 1.39 2000/12/05 21:57:20 mycroft Exp $";
#else #else
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
#if 0 #if 0
static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94"; static char sccsid[] = "@(#)job.c 8.2 (Berkeley) 3/19/94";
#else #else
__RCSID("$NetBSD: job.c,v 1.38 2000/12/05 15:28:55 sommerfeld Exp $"); __RCSID("$NetBSD: job.c,v 1.39 2000/12/05 21:57:20 mycroft Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
#endif #endif
@ -253,7 +253,7 @@ static void watchfd __P((Job *));
static void clearfd __P((Job *)); static void clearfd __P((Job *));
static int readyfd __P((Job *)); static int readyfd __P((Job *));
#define JBSTART 256 #define JBSTART 256
#define JBINCR 256 #define JBFACTOR 2
#endif #endif
#endif #endif
@ -3245,6 +3245,7 @@ static void
watchfd(job) watchfd(job)
Job *job; Job *job;
{ {
int i;
if (job->inPollfd != NULL) if (job->inPollfd != NULL)
Punt("Watching watched job"); Punt("Watching watched job");
if (fds == NULL) { if (fds == NULL) {
@ -3252,31 +3253,18 @@ watchfd(job)
fds = emalloc(sizeof(struct pollfd) * maxfds); fds = emalloc(sizeof(struct pollfd) * maxfds);
jobfds = emalloc(sizeof(Job **) * maxfds); jobfds = emalloc(sizeof(Job **) * maxfds);
} else if (nfds == maxfds) { } else if (nfds == maxfds) {
struct pollfd *newfds; maxfds *= JBFACTOR;
maxfds += JBINCR; fds = erealloc(fds, sizeof(struct pollfd) * maxfds);
newfds = erealloc(fds, sizeof(struct pollfd) * maxfds);
jobfds = erealloc(jobfds, sizeof(Job **) * maxfds); jobfds = erealloc(jobfds, sizeof(Job **) * maxfds);
if (newfds != fds) { for (i = 0; i < nfds; i++)
/* Re-thread for the new allocated pointer */ jobfds[i]->inPollfd = &fds[i];
LstNode ln;
if (Lst_Open(jobs) == FAILURE) {
Punt("Cannot open job table");
}
while ((ln = Lst_Next(jobs)) != NILLNODE) {
Job *jb = (Job *) Lst_Datum(ln);
int i = jb->inPollfd - fds;
jb->inPollfd = &newfds[i];
jobfds[i] = jb;
}
Lst_Close(jobs);
}
fds = newfds;
} }
fds[nfds].fd = job->inPipe; fds[nfds].fd = job->inPipe;
job->inPollfd = &fds[nfds]; fds[nfds].events = POLLIN;
jobfds[nfds] = job; jobfds[nfds] = job;
fds[nfds++].events = POLLIN; job->inPollfd = &fds[nfds];
nfds++;
} }
static void static void