ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/rc3.c
(Generate patch)

Comparing ray/src/rt/rc3.c (file contents):
Revision 2.4 by greg, Mon Jun 11 05:07:55 2012 UTC vs.
Revision 2.5 by greg, Tue Jun 12 01:06:59 2012 UTC

# Line 106 | Line 106 | queue_modifiers()
106                          addcolor(mpout->cbin[j], mpin->cbin[j]);
107                  memset(mpin->cbin, 0, sizeof(DCOLOR)*mpin->nbins);
108          }
109 +        out_bq->nadded++;
110   }
111  
112  
# Line 266 | Line 267 | in_rchild()
267                          close(p0[1]); close(p1[0]);
268                          lu_doall(&modconttab, set_stdout, NULL);
269                          lu_done(&ofiletab);
270 <                        while (nchild--) {
270 >                        while (nchild--) {      /* don't share other pipes */
271                                  close(kida[nchild].w);
272                                  fclose(inq_fp[nchild]);
273                          }
# Line 308 | Line 309 | end_children()
309   {
310          int     status;
311          
312 <        while (nchild-- > 0) {
312 >        while (nchild > 0) {
313 >                nchild--;
314                  kida[nchild].r = -1;    /* close(-1) error is ignored */
315                  if ((status = close_process(&kida[nchild])) > 0) {
316                          sprintf(errmsg,
# Line 321 | Line 323 | end_children()
323   }
324  
325  
326 < /* Wait for the next available child, managing output queue as well */
326 > /* Wait for the next available child, managing output queue simultaneously */
327   static int
328 < next_child_nq(int force_wait)
328 > next_child_nq(int flushing)
329   {
330          static struct timeval   polling;
331          struct timeval          *pmode;
332          fd_set                  readset, errset;
333          int                     i, j, n, nr, nqr;
334  
335 <        if (!force_wait)                /* see if there's one free */
335 >        if (!flushing)                  /* see if there's one free */
336                  for (i = nchild; i--; )
337                          if (kida[i].running < 0)
338                                  return(i);
339  
340 <        nqr = queue_ready();            /* wait mode or polling? */
341 <        if (!nqr | force_wait | (accumulate <= 0))
340 <                pmode = NULL;
341 <        else
340 >        nqr = queue_ready();            /* choose blocking mode or polling */
341 >        if ((nqr > 0) & !flushing)
342                  pmode = &polling;
343 < tryagain:
344 <        n = 0;                          /* catch up with output? */
345 <        if ((pmode == &polling) & (nqr > nchild))
346 <                n = nqr - nchild;
347 <        if ((pmode == NULL) & (nqr > 0) | (n > 0))
348 <                nqr -= output_catchup(n);
343 >        else
344 >                pmode = NULL;
345 > tryagain:                               /* catch up with output? */
346 >        if (pmode == &polling) {
347 >                if (nqr > nchild)       /* don't get too far behind */
348 >                        nqr -= output_catchup(nqr-nchild);
349 >        } else if (nqr > 0)             /* clear output before blocking */
350 >                nqr -= output_catchup(0);
351                                          /* prepare select() call */
352          FD_ZERO(&readset); FD_ZERO(&errset);
353          n = nr = 0;
# Line 362 | Line 364 | tryagain:
364                  return(-1);
365          if ((nr > 1) | (pmode == &polling)) {
366                  errno = 0;
367 <                i = select(n, &readset, NULL, &errset, pmode);
368 <                if (!i) {
367 >                nr = select(n, &readset, NULL, &errset, pmode);
368 >                if (!nr) {
369                          pmode = NULL;   /* try again, blocking this time */
370                          goto tryagain;
371                  }
372 <                if (i < 0)
372 >                if (nr < 0)
373                          error(SYSTEM, "select() error in next_child_nq()");
374          } else
375                  FD_ZERO(&errset);
# Line 423 | Line 425 | parental_loop()
425                  }
426                  if (d == 0.0) {
427                          if ((yres <= 0) | (xres <= 0))
428 <                                waitflush = 1;          /* flush right after */
428 >                                waitflush = 1;          /* flush next */
429                          put_zero_record(++lastray);
430                  } else {                                /* else assign ray */
431 <                        i = next_child_nq(0);
431 >                        i = next_child_nq(0);           /* manages output */
432                          if (writebuf(kida[i].w, (char *)orgdir,
433                                          sizeof(orgdir)) != sizeof(orgdir))
434                                  error(SYSTEM, "pipe write error");
435 <                        kida[i].running = ++lastray;
435 >                        kida[i].running = ++lastray;    /* busy now */
436                  }
437                  if (raysleft && !--raysleft)
438                          break;                          /* preemptive EOI */
# Line 439 | Line 441 | parental_loop()
441                  ;
442                                                  /* output accumulated record */
443          if (accumulate <= 0 || account < accumulate) {
444 +                end_children();                 /* frees up file descriptors */
445                  if (account < accumulate) {
446                          error(WARNING, "partial accumulation in final record");
447                          accumulate -= account;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines