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

Comparing ray/src/rt/raypcalls.c (file contents):
Revision 2.29 by greg, Fri Mar 4 02:48:14 2016 UTC vs.
Revision 2.40 by greg, Wed Aug 21 20:42:20 2024 UTC

# Line 147 | Line 147 | static const char      RCSid[] = "$Id$";
147   #include  "selcall.h"
148  
149   #ifndef RAYQLEN
150 < #define RAYQLEN         12              /* # rays to send at once */
150 > #define RAYQLEN         24              /* # rays to send at once */
151   #endif
152  
153   #ifndef MAX_RPROCS
# Line 158 | Line 158 | static const char      RCSid[] = "$Id$";
158   #endif
159   #endif
160  
161 extern char     *shm_boundary;          /* boundary of shared memory */
162
161   int             ray_pnprocs = 0;        /* number of child processes */
162   int             ray_pnidle = 0;         /* number of idle children */
163  
# Line 212 | Line 210 | ray_pflush(void)                       /* send queued rays to idle childre
210          for (i = ray_pnprocs; nc && i--; ) {
211                  if (r_proc[i].npending > 0)
212                          continue;       /* child looks busy */
213 <                n = (r_send_next - sfirst)/nc--;
213 >                n = (r_send_next - sfirst) / nc--;
214                  if (!n)
215                          continue;
216                                          /* smuggle set size in crtype */
217                  r_queue[sfirst].crtype = n;
218 <                nw = writebuf(r_proc[i].fd_send, (char *)&r_queue[sfirst],
218 >                nw = writebuf(r_proc[i].fd_send, &r_queue[sfirst],
219                                  sizeof(RAY)*n);
220                  if (nw != sizeof(RAY)*n)
221                          return(-1);     /* write error */
# Line 290 | Line 288 | ray_presult(           /* check for a completed ray */
288          static struct timeval   tpoll;  /* zero timeval struct */
289          static fd_set   readset, errset;
290          int     n, ok;
291 <        register int    pn;
291 >        int     pn;
292  
293          if (r == NULL)
294                  return(0);
# Line 348 | Line 346 | getready:                              /* any children waiting for us? */
346                  error(CONSISTENCY, "buffer shortage in ray_presult()");
347  
348                                          /* read rendered ray data */
349 <        n = readbuf(r_proc[pn].fd_recv, (char *)&r_queue[r_recv_next],
349 >        n = readbuf(r_proc[pn].fd_recv, &r_queue[r_recv_next],
350                          sizeof(RAY)*r_proc[pn].npending);
351          if (n > 0) {
352                  r_recv_next += n/sizeof(RAY);
# Line 368 | Line 366 | getready:                              /* any children waiting for us? */
366          }
367                                          /* preen returned rays */
368          for (n = r_recv_next - r_recv_first; n--; ) {
369 <                register RAY    *rp = &r_queue[r_recv_first + n];
369 >                RAY     *rp = &r_queue[r_recv_first + n];
370                  rp->rno = r_proc[pn].rno[n];
371                  rp->parent = NULL;
372                  rp->newcset = rp->clipset = NULL;
# Line 388 | Line 386 | ray_pdone(             /* reap children and free data */
386   {
387          ray_pclose(0);                  /* close child processes */
388  
389 <        if (shm_boundary != NULL) {     /* clear shared memory boundary */
392 <                free((void *)shm_boundary);
393 <                shm_boundary = NULL;
394 <        }
389 >        cow_doneshare();                /* clear shared memory boundary */
390  
391          ray_done(freall);               /* free rendering data */
392   }
# Line 404 | Line 399 | ray_pchild(    /* process rays (never returns) */
399   )
400   {
401          int     n;
402 <        register int    i;
402 >        int     i;
403                                          /* flag child process for quit() */
404          ray_pnprocs = -1;
405                                          /* read each ray request set */
# Line 435 | Line 430 | ray_pchild(    /* process rays (never returns) */
430                          rayvalue(&r_queue[i]);
431                  }
432                                          /* write back our results */
433 <                i = writebuf(fd_out, (char *)r_queue, sizeof(RAY)*n);
433 >                i = writebuf(fd_out, r_queue, sizeof(RAY)*n);
434                  if (i != sizeof(RAY)*n)
435                          error(SYSTEM, "write error in ray_pchild()");
436          }
# Line 456 | Line 451 | ray_popen(                     /* open the specified # processes */
451                  nadd = MAX_NPROCS - ray_pnprocs;
452          if (nadd <= 0)
453                  return;
454 +        if (nobjects <= 0)
455 +                error(CONSISTENCY, "ray_popen() called before scene loaded");
456          ambsync();                      /* load any new ambient values */
457 <        if (shm_boundary == NULL) {     /* first child process? */
461 <                preload_objs();         /* preload auxiliary data */
462 <                                        /* set shared memory boundary */
463 <                shm_boundary = (char *)malloc(16);
464 <                strcpy(shm_boundary, "SHM_BOUNDARY");
465 <        }
457 >        cow_memshare();                 /* copy-on-write shared memory */
458          fflush(NULL);                   /* clear pending output */
459          samplestep = ray_pnprocs + nadd;
460          while (nadd--) {                /* fork each new process */
# Line 510 | Line 502 | ray_pclose(            /* close one or more child processes */
502          static int      inclose = 0;
503          RAY             res;
504          int             i, status = 0;
505 +                                        /* check no child / in child */
506 +        if (ray_pnprocs <= 0)
507 +                return;
508                                          /* check recursion */
509          if (inclose)
510                  return;
511          inclose++;
517                                        /* check no child / in child */
518        if (ray_pnprocs <= 0)
519                return;
512                                          /* check argument */
513          if ((nsub <= 0) | (nsub > ray_pnprocs))
514                  nsub = ray_pnprocs;
515                                          /* clear our ray queue */
516 +        i = r_send_next;
517 +        r_send_next = 0;
518          while (ray_presult(&res,0) > 0)
519 <                ;
520 <        r_send_next = 0;                /* hard reset in case of error */
519 >                ++i;
520 >        if (i) {
521 >                sprintf(errmsg, "dropped %d rays in ray_pclose()", i);
522 >                error(WARNING, errmsg);
523 >        }
524          r_recv_first = r_recv_next = RAYQLEN;
525                                          /* close send pipes */
526          for (i = ray_pnprocs-nsub; i < ray_pnprocs; i++)
# Line 537 | Line 534 | ray_pclose(            /* close one or more child processes */
534                  for (i = 0; i < nsub; ) {
535                          int     j, mystatus;
536                          RT_PID  pid = wait(&mystatus);
537 +                        if (pid < 0) {
538 +                                status = 127<<8;
539 +                                break;
540 +                        }
541                          for (j = ray_pnprocs-nsub; j < ray_pnprocs; j++)
542                                  if (r_proc[j].pid == pid) {
543                                          if (mystatus)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines