--- ray/src/rt/rc3.c 2012/06/16 17:09:49 2.10 +++ ray/src/rt/rc3.c 2012/11/15 15:26:52 2.17 @@ -1,14 +1,13 @@ #ifndef lint -static const char RCSid[] = "$Id: rc3.c,v 2.10 2012/06/16 17:09:49 greg Exp $"; +static const char RCSid[] = "$Id: rc3.c,v 2.17 2012/11/15 15:26:52 greg Exp $"; #endif /* * Accumulate ray contributions for a set of materials * Controlling process for multiple children */ +#include #include "rcontrib.h" -#include "platform.h" -#include "rtprocess.h" #include "selcall.h" #define MAXIQ (int)(PIPE_BUF/(sizeof(FVECT)*2)) @@ -315,13 +314,17 @@ in_rchild() /* Close child processes */ void -end_children() +end_children(int immed) { int status; while (nchild > 0) { nchild--; - if ((status = close_process(&kida[nchild].pr)) > 0) { +#ifdef SIGKILL + if (immed) /* error mode -- quick exit */ + kill(kida[nchild].pr.pid, SIGKILL); +#endif + if ((status = close_process(&kida[nchild].pr)) > 0 && !immed) { sprintf(errmsg, "rendering process returned bad status (%d)", status); @@ -397,8 +400,7 @@ tryagain: /* catch up with output? */ void parental_loop() { - static int ignore_warning_given = 0; - int qlimit = (accumulate == 1) ? 1 : MAXIQ-1; + const int qlimit = (accumulate == 1) ? 1 : MAXIQ-1; int ninq = 0; FVECT orgdir[2*MAXIQ]; int i, n; @@ -410,17 +412,24 @@ parental_loop() if (orgdir[2*ninq+1][0] == 0.0 && /* asking for flush? */ (orgdir[2*ninq+1][1] == 0.0) & (orgdir[2*ninq+1][2] == 0.0)) { - if (accumulate != 1) { - if (!ignore_warning_given++) - error(WARNING, - "dummy ray(s) ignored during accumulation\n"); - continue; + if (ninq) { /* preempt our queue */ + i = next_child_nq(0); + n = ninq; + memset(orgdir[2*n++], 0, sizeof(FVECT)*2); + n *= sizeof(FVECT)*2; + if (writebuf(kida[i].pr.w, (char *)orgdir, n) != n) + error(SYSTEM, "pipe write error"); + kida[i].r1 = lastray+1; + lastray += kida[i].nr = ninq; + ninq = 0; } - while (next_child_nq(1) >= 0) - ; /* clear the queue */ - lastdone = lastray = 0; - if ((yres <= 0) | (xres <= 0)) + if ((yres <= 0) | (xres <= 0) && + (lastray+1) % accumulate == 0) { + while (next_child_nq(1) >= 0) + ; /* clear the queue */ + lastdone = lastray %= accumulate; waitflush = 1; /* flush next */ + } put_zero_record(++lastray); } else if (++ninq >= qlimit || lastray/accumulate != (lastray+ninq)/accumulate) { @@ -433,12 +442,13 @@ parental_loop() error(SYSTEM, "pipe write error"); kida[i].r1 = lastray+1; lastray += kida[i].nr = ninq; /* mark as busy */ - ninq = 0; if (lastray < lastdone) { /* RNUMBER wrapped? */ while (next_child_nq(1) >= 0) ; - lastdone = lastray = 0; + lastray -= ninq; + lastdone = lastray %= accumulate; } + ninq = 0; } if (raysleft && !--raysleft) break; /* preemptive EOI */ @@ -462,7 +472,7 @@ static int next_child_ready() { fd_set writeset, errset; - int i, n, nqr; + int i, n; for (i = nchild; i--; ) /* see if there's one free first */ if (!kida[i].nr) @@ -537,13 +547,14 @@ feeder_loop() lastray += kida[i].nr = ninq; ninq = 0; } - for (i = nchild; i--; ) { /* get results */ - close(kida[i].pr.w); + memset(orgdir, 0, sizeof(FVECT)*2); /* get results */ + for (i = nchild; i--; ) { + writebuf(kida[i].pr.w, (char *)orgdir, sizeof(FVECT)*2); queue_results(i); } if (recover) /* and from before? */ queue_modifiers(); - end_children(); /* free up file descriptors */ + end_children(0); /* free up file descriptors */ for (i = 0; i < nmods; i++) mod_output(out_bq->mca[i]); /* output accumulated record */ end_record();