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.2 by greg, Sat Jun 9 16:47:27 2012 UTC vs.
Revision 2.3 by greg, Sun Jun 10 05:25:42 2012 UTC

# Line 150 | Line 150 | queue_output(BINQ *bp)
150                  bp->next = out_bq;
151                  out_bq = bp;
152          }
153 <        if (accumulate <= 1)            /* no accumulating? */
153 >        if (accumulate == 1)            /* no accumulation? */
154                  return;
155          b_cur = out_bq;                 /* else merge accumulation entries */
156          while (b_cur->next != NULL) {
# Line 170 | Line 170 | queue_output(BINQ *bp)
170   }
171  
172  
173 < /* Get current with output FIFO by producing ready results */
173 > /* Get current with output queue by producing ready results */
174   static int
175   output_catchup()
176   {
# Line 196 | Line 196 | output_catchup()
196   }
197  
198  
199 < /* Put a zero record in results queue */
199 > /* Put a zero record in results queue & output */
200   void
201 < zero_record(int ndx)
201 > put_zero_record(int ndx)
202   {
203          BINQ    *bp = new_binq();
204          int     i;
# Line 207 | Line 207 | zero_record(int ndx)
207                  memset(bp->mca[i]->cbin, 0, sizeof(DCOLOR)*bp->mca[i]->nbins);
208          bp->ndx = ndx;
209          queue_output(bp);
210 +        output_catchup();
211   }
212  
213  
# Line 233 | Line 234 | in_rchild()
234                  int     p0[2], p1[2];
235                  int     pid;
236                                          /* prepare i/o pipes */
237 +                errno = 0;
238                  if (pipe(p0) < 0 || pipe(p1) < 0)
239                          error(SYSTEM, "pipe() call failed!");
240                  pid = fork();           /* fork parent process */
# Line 253 | Line 255 | in_rchild()
255                  }
256                  if (pid < 0)
257                          error(SYSTEM, "fork() call failed!");
258 <                                        /* connect our pipes */
258 >                                        /* connect parent's pipes */
259                  close(p0[0]); close(p1[1]);
260                  kida[nchild].r = p1[0];
261                  kida[nchild].w = p0[1];
# Line 262 | Line 264 | in_rchild()
264                  inq_fp[nchild] = fdopen(p1[0], "rb");
265                  if (inq_fp[nchild] == NULL)
266                          error(SYSTEM, "out of memory in in_rchild()");
267 + #ifdef getc_unlocked
268 +                flockfile(inq_fp[nchild]);      /* avoid mutex overhead */
269 + #endif
270                  ++nchild;
271          }
272          return(0);                      /* parent return value */
# Line 314 | Line 319 | next_child_nq(int force_wait)
319                  if (kida[i].r >= n)
320                          n = kida[i].r + 1;
321          }
317        if (!nr)                        /* nothing going on */
318                return(-1);
322   tryagain:
323 <        if (pmode == NULL)              /* about to block, so catch up */
323 >        if (pmode == NULL)              /* catch up in case we block */
324                  output_catchup();
325 +        if (!nr)                        /* nothing to wait for? */
326 +                return(-1);
327          if ((nr > 1) | (pmode == &polling)) {
328                  errno = 0;
329 <                nr = select(n, &readset, NULL, &errset, pmode);
330 <                if (!nr & (pmode == &polling)) {
329 >                i = select(n, &readset, NULL, &errset, pmode);
330 >                if (!i) {
331                          pmode = NULL;   /* try again, blocking this time */
332                          goto tryagain;
333                  }
334 <                if (nr <= 0)
335 <                        error(SYSTEM, "select call error in next_child_nq()");
334 >                if (i < 0)
335 >                        error(SYSTEM, "select() error in next_child_nq()");
336          } else
337                  FD_ZERO(&errset);
338          n = -1;                         /* read results from child(ren) */
# Line 341 | Line 346 | tryagain:
346                  bq->ndx = kida[i].running;
347                                          /* read from child */
348                  for (j = 0; j < nmods; j++) {
349 <                        n = bq->mca[j]->nbins;
350 <                        nr = fread(bq->mca[j]->cbin,sizeof(DCOLOR),n,inq_fp[i]);
351 <                        if (nr != n)
349 >                        nr = bq->mca[j]->nbins;
350 >                        if (fread(bq->mca[j]->cbin, sizeof(DCOLOR), nr,
351 >                                                        inq_fp[i]) != nr)
352                                  error(SYSTEM, "read error from render process");
353                  }
354 <                queue_output(bq);       /* put results in output queue */
354 >                queue_output(bq);       /* add results to output queue */
355                  kida[i].running = -1;   /* mark child as available */
356                  n = i;
357          }
358 <        return(n);                      /* last available child */
358 >        return(n);                      /* first available child */
359   }
360  
361  
# Line 361 | Line 366 | parental_loop()
366          static int      ignore_warning_given = 0;
367          FVECT           orgdir[2];
368          double          d;
369 +        int             i;
370                                          /* load rays from stdin & process */
371   #ifdef getc_unlocked
372          flockfile(stdin);               /* avoid lock/unlock overhead */
# Line 376 | Line 382 | parental_loop()
382                  }
383                  if ((d == 0.0) | (lastray+1 < lastray)) {
384                          while (next_child_nq(1) >= 0)
385 <                                ;
385 >                                ;                       /* clear the queue */
386                          lastdone = lastray = 0;
387                  }
388                  if (d == 0.0) {
389                          if ((yres <= 0) | (xres <= 0))
390                                  waitflush = 1;          /* flush right after */
391 <                        zero_record(++lastray);
392 <                } else {                                /* else assign */
393 <                        int     avail = next_child_nq(0);
394 <                        if (writebuf(kida[avail].w, (char *)orgdir,
395 <                                        sizeof(FVECT)*2) != sizeof(FVECT)*2)
391 >                        put_zero_record(++lastray);
392 >                } else {                                /* else assign ray */
393 >                        i = next_child_nq(0);
394 >                        if (writebuf(kida[i].w, (char *)orgdir,
395 >                                        sizeof(orgdir)) != sizeof(orgdir))
396                                  error(SYSTEM, "pipe write error");
397 <                        kida[avail].running = ++lastray;
397 >                        kida[i].running = ++lastray;
398                  }
399                  if (raysleft && !--raysleft)
400                          break;                          /* preemptive EOI */
# Line 397 | Line 403 | parental_loop()
403                  ;
404                                                  /* output accumulated record */
405          if (accumulate <= 0 || account < accumulate) {
400                int     i;
406                  if (account < accumulate) {
407                          error(WARNING, "partial accumulation in final record");
408                          accumulate -= account;
# Line 405 | Line 410 | parental_loop()
410                  for (i = 0; i < nmods; i++)
411                          mod_output(out_bq->mca[i]);
412                  end_record();
413 +                free_binq(out_bq);
414 +                out_bq = NULL;
415          }
416          if (raysleft)
417                  error(USER, "unexpected EOF on input");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines