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

Comparing ray/src/util/rcomb.c (file contents):
Revision 2.12 by greg, Tue May 21 17:39:17 2024 UTC vs.
Revision 2.13 by greg, Wed May 22 00:39:30 2024 UTC

# Line 57 | Line 57 | int            cur_chan;                       /* if we're looping channels */
57   SUBPROC         *cproc = NULL;                  /* child process array */
58   int             nchildren = 0;                  /* # of child processes */
59   int             inchild = -1;                   /* our child ID (-1: parent) */
60 < int             gpid = -1;                      /* group process ID (parent) */
60 > int             pgid = -1;                      /* process group ID */
61   int             nr_out = 0;                     /* # of rows output by kids */
62  
63   static int      checksymbolic(ROPMAT *rop);
# Line 66 | Line 66 | static void
66   on_sigio(int dummy)
67   {
68          nr_out++;                       /* happens when child outputs row */
69        signal(SIGIO, on_sigio);        /* reset to maximize portability */
69   }
70  
71   static int
# Line 596 | Line 595 | spawned_children(int np)
595   #endif
596                  return(0);
597          }
598 <        gpid = setpgrp();       /* set group process ID */
598 >        pgid = setpgrp();       /* set process group ID */
599          signal(SIGIO, on_sigio);
600          fflush(stdout);         /* flush header & spawn children */
601          cproc = (SUBPROC *)malloc(sizeof(SUBPROC)*np);
# Line 701 | Line 700 | combine_input()
700          int             set_r, set_c;
701          RMATRIX         *tmp = NULL;
702          int             co_set;
703 +        sigset_t        iomask;
704          int             i;
705  
706          if (mcat && mcat_last &&
# Line 720 | Line 720 | combine_input()
720                  set_c = varlookup("c") != NULL && !vardefined("c");
721          } else                          /* save a little time */
722                  set_r = set_c = 0;
723 <                                        /* read/process row-by-row */
723 >
724 >        sigemptyset(&iomask);           /* read/process row-by-row */
725 >        sigaddset(&iomask, SIGIO);
726          for (cur_row = row0; (in_nrows <= 0) | (cur_row < in_nrows); cur_row += rstep) {
727              RMATRIX     *mres = NULL;
728 <            for (i = 0; i < nmats; i++)
728 >            for (i = 0; i < nmats; i++) {
729 >                if (inchild >= 0) sigprocmask(SIG_BLOCK, &iomask, NULL);
730                  if (!rmx_load_row(mop[i].imx.mtx, &mop[i].imx, mop[i].infp)) {
731                          if (cur_row > in_nrows) /* unknown #input rows? */
732                                  break;
# Line 731 | Line 734 | combine_input()
734                                          mop[i].inspec, cur_row);
735                          return(0);
736                  }
737 +                if (inchild >= 0) sigprocmask(SIG_UNBLOCK, &iomask, NULL);
738 +            }
739              if (i < nmats)
740                  break;
741              for (i = 0; i < nmats; i++)
# Line 772 | Line 777 | combine_input()
777                          return(0);
778              }
779              rmx_free(mres); mres = NULL;
780 <            if (inchild >= 0)           /* children share stdout */
780 >            if (inchild >= 0) {         /* children share stdout */
781                  while (nr_out < cur_row)
782                      pause();            /* wait for our turn */
783 +                sigprocmask(SIG_BLOCK, &iomask, NULL);
784 +            }
785              if (!rmx_write_data(res->rmp->mtx, res->rmp->ncomp,
786                                  res->rmp->ncols, res->rmp->dtype, stdout))
787                  return(0);
788              if (inchild >= 0) {         /* flush and notify group */
789                  if (fflush(stdout) == EOF)
790                      return(0);
791 <                killpg(gpid, SIGIO);    /* increments everyone's nr_out */
791 >                sigprocmask(SIG_UNBLOCK, &iomask, NULL);
792 >                killpg(pgid, SIGIO);    /* increments everyone's nr_out */
793              }
794          }
795          return(inchild >= 0 || fflush(stdout) != EOF);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines