--- ray/src/hd/rholo2l.c 1997/12/11 11:51:20 3.8 +++ ray/src/hd/rholo2l.c 2004/01/01 11:21:55 3.16 @@ -1,19 +1,19 @@ -/* Copyright (c) 1997 Silicon Graphics, Inc. */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: rholo2l.c,v 3.16 2004/01/01 11:21:55 schorsch Exp $"; #endif - /* * Routines for local rtrace execution */ +#include +#include +#include + #include "rholo.h" #include "random.h" #include "paths.h" #include "selcall.h" -#include -#include +#include "rtprocess.h" #ifndef MAXPROC #define MAXPROC 64 @@ -23,51 +23,59 @@ int nprocs = 0; /* running process count */ static char pfile[] = TEMPLATE; /* persist file name */ -static int rtpd[MAXPROC][3]; /* process descriptors */ +static SUBPROC rtpd[MAXPROC]; /* process descriptors */ static float *rtbuf = NULL; /* allocated i/o buffer */ static int maxqlen = 0; /* maximum packets per queue */ static PACKET *pqueue[MAXPROC]; /* packet queues */ static int pqlen[MAXPROC]; /* packet queue lengths */ +static int bestout(void); +static int slots_avail(void); +static void queue_packet(PACKET *p); +static PACKET * get_packets(int poll); +static void killpersist(void); -int -start_rtrace() /* start rtrace process */ + +extern int +start_rtrace(void) /* start rtrace process */ { static char buf1[8]; int rmaxpack = 0; - int psiz, npt, n; + int psiz, n; /* get number of processes */ - if ((npt = ncprocs) <= 0) + if (ncprocs <= 0 || nprocs > 0) return(0); - if (npt > MAXPROC) { + if (ncprocs > MAXPROC) { sprintf(errmsg, "number of rtrace processes reduced from %d to %d", - npt, MAXPROC); + ncprocs, MAXPROC); error(WARNING, errmsg); - npt = MAXPROC; + ncprocs = MAXPROC; } - /* add compulsory options */ - rtargv[rtargc++] = "-i-"; - rtargv[rtargc++] = "-I-"; - rtargv[rtargc++] = "-h-"; - rtargv[rtargc++] = "-ld-"; - sprintf(buf1, "%d", RPACKSIZ); - rtargv[rtargc++] = "-x"; rtargv[rtargc++] = buf1; - rtargv[rtargc++] = "-y"; rtargv[rtargc++] = "0"; - rtargv[rtargc++] = "-fff"; - rtargv[rtargc++] = vbool(VDIST) ? "-ovl" : "-ovL"; - if (nowarn) - rtargv[rtargc++] = "-w-"; - if (npt > 1) { - mktemp(pfile); - rtargv[rtargc++] = "-PP"; rtargv[rtargc++] = pfile; + if (rtargv[rtargc-1] != vval(OCTREE)) { + /* add compulsory options */ + rtargv[rtargc++] = "-i-"; + rtargv[rtargc++] = "-I-"; + rtargv[rtargc++] = "-h-"; + rtargv[rtargc++] = "-ld-"; + sprintf(buf1, "%d", RPACKSIZ); + rtargv[rtargc++] = "-x"; rtargv[rtargc++] = buf1; + rtargv[rtargc++] = "-y"; rtargv[rtargc++] = "0"; + rtargv[rtargc++] = "-fff"; + rtargv[rtargc++] = vbool(VDIST) ? "-ovl" : "-ovL"; + if (nowarn) + rtargv[rtargc++] = "-w-"; + if (ncprocs > 1) { + mktemp(pfile); + rtargv[rtargc++] = "-PP"; rtargv[rtargc++] = pfile; + } + rtargv[rtargc++] = vval(OCTREE); + rtargv[rtargc] = NULL; } - rtargv[rtargc++] = vval(OCTREE); - rtargv[rtargc] = NULL; maxqlen = 0; - for (nprocs = 0; nprocs < npt; nprocs++) { /* spawn children */ - psiz = open_process(rtpd[nprocs], rtargv); + for (nprocs = 0; nprocs < ncprocs; nprocs++) { /* spawn children */ + psiz = open_process(&rtpd[nprocs], rtargv); if (psiz <= 0) error(SYSTEM, "cannot start rtrace process"); n = psiz/(RPACKSIZ*6*sizeof(float)); @@ -75,6 +83,7 @@ start_rtrace() /* start rtrace process */ if (!(maxqlen = n)) error(INTERNAL, "bad pipe buffer size assumption"); + sleep(2); } else if (n != maxqlen) error(INTERNAL, "varying pipe buffer size!"); rmaxpack += n; @@ -87,7 +96,7 @@ start_rtrace() /* start rtrace process */ static int -bestout() /* get best process to process packet */ +bestout(void) /* get best process to process packet */ { int cnt; register int pn, i; @@ -112,8 +121,8 @@ bestout() /* get best process to process packet */ } -int -slots_avail() /* count packet slots available */ +static int +slots_avail(void) /* count packet slots available */ { register int nslots = 0; register int i; @@ -124,8 +133,10 @@ slots_avail() /* count packet slots available */ } -queue_packet(p) /* queue up a beam packet */ -register PACKET *p; +static void +queue_packet( /* queue up a beam packet */ + register PACKET *p +) { int pn, n; /* determine process to write to */ @@ -134,8 +145,8 @@ register PACKET *p; /* write out the packet */ packrays(rtbuf, p); if ((n = p->nr) < RPACKSIZ) /* add flush block? */ - bzero((char *)(rtbuf+6*n++), 6*sizeof(float)); - if (writebuf(rtpd[pn][1], (char *)rtbuf, 6*sizeof(float)*n) < 0) + memset((char *)(rtbuf+6*n++), '\0', 6*sizeof(float)); + if (writebuf(rtpd[pn].w, (char *)rtbuf, 6*sizeof(float)*n) < 0) error(SYSTEM, "write error in queue_packet"); p->next = NULL; if (!pqlen[pn]++) /* add it to the end of the queue */ @@ -149,9 +160,10 @@ register PACKET *p; } -PACKET * -get_packets(poll) /* read packets from rtrace processes */ -int poll; +static PACKET * +get_packets( /* read packets from rtrace processes */ + int poll +) { static struct timeval tpoll; /* zero timeval struct */ fd_set readset, errset; @@ -164,10 +176,10 @@ int poll; FD_ZERO(&readset); FD_ZERO(&errset); n = 0; for (pn = nprocs; pn--; ) { if (pqlen[pn]) - FD_SET(rtpd[pn][0], &readset); - FD_SET(rtpd[pn][0], &errset); - if (rtpd[pn][0] >= n) - n = rtpd[pn][0] + 1; + FD_SET(rtpd[pn].r, &readset); + FD_SET(rtpd[pn].r, &errset); + if (rtpd[pn].r >= n) + n = rtpd[pn].r + 1; } /* make the call */ n = select(n, &readset, (fd_set *)NULL, &errset, @@ -181,14 +193,14 @@ int poll; return(NULL); /* make read call(s) */ for (pn = 0; pn < nprocs; pn++) { - if (!FD_ISSET(rtpd[pn][0], &readset) && - !FD_ISSET(rtpd[pn][0], &errset)) + if (!FD_ISSET(rtpd[pn].r, &readset) && + !FD_ISSET(rtpd[pn].r, &errset)) continue; reread: - n = read(rtpd[pn][0], (char *)rtbuf, + n = read(rtpd[pn].r, (char *)rtbuf, 4*sizeof(float)*RPACKSIZ*pqlen[pn]); if (n < 0) { - if (errno == EINTR | errno == EAGAIN) + if ((errno == EINTR) | (errno == EAGAIN)) goto reread; error(SYSTEM, "read error in get_packets"); } @@ -200,7 +212,7 @@ int poll; nr++; /* add flush block */ n -= 4*sizeof(float)*nr; if (n < 0) { /* get remainder */ - n += readbuf(rtpd[pn][0], + n += readbuf(rtpd[pn].r, (char *)(bp+4*nr)+n, -n); if (n) goto eoferr; @@ -224,12 +236,14 @@ int poll; return(pldone); /* return finished packets */ eoferr: error(USER, "rtrace process died"); + return NULL; /* pro forma return */ } -PACKET * -do_packets(pl) /* queue a packet list, return finished */ -register PACKET *pl; +extern PACKET * +do_packets( /* queue a packet list, return finished */ + register PACKET *pl +) { register PACKET *p; /* consistency check */ @@ -244,11 +258,11 @@ register PACKET *pl; } -PACKET * -flush_queue() /* empty all rtrace queues */ +extern PACKET * +flush_queue(void) /* empty all rtrace queues */ { PACKET *rpdone = NULL; - register PACKET *rpl; + register PACKET *rpl = NULL; float *bp; register PACKET *p; int i, n, nr; @@ -267,7 +281,7 @@ flush_queue() /* empty all rtrace queues */ if (rpl->nr < RPACKSIZ) nr++; /* add flush block */ } - n = readbuf(rtpd[i][0], (char *)rtbuf, + n = readbuf(rtpd[i].r, (char *)rtbuf, 4*sizeof(float)*nr); if (n < 0) error(SYSTEM, "read failure in flush_queue"); @@ -289,8 +303,8 @@ flush_queue() /* empty all rtrace queues */ } -static -killpersist() /* kill persistent process */ +static void +killpersist(void) /* kill persistent process */ { FILE *fp; int pid; @@ -303,19 +317,19 @@ killpersist() /* kill persistent process */ } -int -end_rtrace() /* close rtrace process(es) */ +extern int +end_rtrace(void) /* close rtrace process(es) */ { int status = 0, rv; if (nprocs > 1) killpersist(); while (nprocs > 0) { - rv = close_process(rtpd[--nprocs]); + rv = close_process(&rtpd[--nprocs]); if (rv > 0) status = rv; } - free((char *)rtbuf); + free((void *)rtbuf); rtbuf = NULL; maxqlen = 0; return(status);