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.28 by greg, Sat Aug 20 18:23:38 2011 UTC vs.
Revision 2.38 by greg, Tue Apr 30 22:25:46 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 164 | Line 164 | int            ray_pnprocs = 0;        /* number of child processes */
164   int             ray_pnidle = 0;         /* number of idle children */
165  
166   static struct child_proc {
167 <        int     pid;                            /* child process id */
167 >        RT_PID  pid;                            /* child process id */
168          int     fd_send;                        /* write to child here */
169          int     fd_recv;                        /* read from child here */
170          int     npending;                       /* # rays in process */
# Line 212 | Line 212 | ray_pflush(void)                       /* send queued rays to idle childre
212          for (i = ray_pnprocs; nc && i--; ) {
213                  if (r_proc[i].npending > 0)
214                          continue;       /* child looks busy */
215 <                n = (r_send_next - sfirst)/nc--;
215 >                n = (r_send_next - sfirst) / nc--;
216                  if (!n)
217                          continue;
218                                          /* smuggle set size in crtype */
# Line 290 | Line 290 | ray_presult(           /* check for a completed ray */
290          static struct timeval   tpoll;  /* zero timeval struct */
291          static fd_set   readset, errset;
292          int     n, ok;
293 <        register int    pn;
293 >        int     pn;
294  
295          if (r == NULL)
296                  return(0);
# Line 368 | Line 368 | getready:                              /* any children waiting for us? */
368          }
369                                          /* preen returned rays */
370          for (n = r_recv_next - r_recv_first; n--; ) {
371 <                register RAY    *rp = &r_queue[r_recv_first + n];
371 >                RAY     *rp = &r_queue[r_recv_first + n];
372                  rp->rno = r_proc[pn].rno[n];
373                  rp->parent = NULL;
374                  rp->newcset = rp->clipset = NULL;
# Line 404 | Line 404 | ray_pchild(    /* process rays (never returns) */
404   )
405   {
406          int     n;
407 <        register int    i;
407 >        int     i;
408                                          /* flag child process for quit() */
409          ray_pnprocs = -1;
410                                          /* read each ray request set */
# Line 456 | Line 456 | ray_popen(                     /* open the specified # processes */
456                  nadd = MAX_NPROCS - ray_pnprocs;
457          if (nadd <= 0)
458                  return;
459 +        if (nobjects <= 0)
460 +                error(CONSISTENCY, "ray_popen() called before scene loaded");
461          ambsync();                      /* load any new ambient values */
462          if (shm_boundary == NULL) {     /* first child process? */
463                  preload_objs();         /* preload auxiliary data */
# Line 508 | Line 510 | ray_pclose(            /* close one or more child processes */
510   )
511   {
512          static int      inclose = 0;
513 <        RAY     res;
513 >        RAY             res;
514 >        int             i, status = 0;
515 >                                        /* check no child / in child */
516 >        if (ray_pnprocs <= 0)
517 >                return;
518                                          /* check recursion */
519          if (inclose)
520                  return;
521          inclose++;
516                                        /* check no child / in child */
517        if (ray_pnprocs <= 0)
518                return;
522                                          /* check argument */
523          if ((nsub <= 0) | (nsub > ray_pnprocs))
524                  nsub = ray_pnprocs;
525                                          /* clear our ray queue */
526 +        i = r_send_next;
527 +        r_send_next = 0;
528          while (ray_presult(&res,0) > 0)
529 <                ;
530 <        r_send_next = 0;                /* hard reset in case of error */
529 >                ++i;
530 >        if (i) {
531 >                sprintf(errmsg, "dropped %d rays in ray_pclose()", i);
532 >                error(WARNING, errmsg);
533 >        }
534          r_recv_first = r_recv_next = RAYQLEN;
535 <                                        /* clean up children */
536 <        while (nsub--) {
537 <                int     status;
538 <                ray_pnprocs--;
539 <                close(r_proc[ray_pnprocs].fd_send);
540 <                if (waitpid(r_proc[ray_pnprocs].pid, &status, 0) < 0)
535 >                                        /* close send pipes */
536 >        for (i = ray_pnprocs-nsub; i < ray_pnprocs; i++)
537 >                close(r_proc[i].fd_send);
538 >
539 >        if (nsub == 1) {                /* awaiting single process? */
540 >                if (waitpid(r_proc[ray_pnprocs-1].pid, &status, 0) < 0)
541                          status = 127<<8;
542 <                close(r_proc[ray_pnprocs].fd_recv);
543 <                if (status) {
544 <                        sprintf(errmsg,
545 <                                "rendering process %d exited with code %d",
546 <                                        r_proc[ray_pnprocs].pid, status>>8);
547 <                        error(WARNING, errmsg);
542 >                close(r_proc[ray_pnprocs-1].fd_recv);
543 >        } else                          /* else unordered wait */
544 >                for (i = 0; i < nsub; ) {
545 >                        int     j, mystatus;
546 >                        RT_PID  pid = wait(&mystatus);
547 >                        if (pid < 0) {
548 >                                status = 127<<8;
549 >                                break;
550 >                        }
551 >                        for (j = ray_pnprocs-nsub; j < ray_pnprocs; j++)
552 >                                if (r_proc[j].pid == pid) {
553 >                                        if (mystatus)
554 >                                                status = mystatus;
555 >                                        close(r_proc[j].fd_recv);
556 >                                        ++i;
557 >                                }
558                  }
559 <                ray_pnidle--;
559 >        ray_pnprocs -= nsub;
560 >        ray_pnidle -= nsub;
561 >        if (status) {
562 >                sprintf(errmsg, "rendering process exited with code %d", status>>8);
563 >                error(WARNING, errmsg);
564          }
565          inclose--;
566   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines