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.11 by greg, Tue May 21 16:27:26 2024 UTC vs.
Revision 2.12 by greg, Tue May 21 17:39:17 2024 UTC

# Line 5 | Line 5 | static const char RCSid[] = "$Id$";
5   * General component matrix combiner, operating on a row at a time.
6   */
7  
8 + #include <signal.h>
9   #include <math.h>
10   #include "platform.h"
11   #include "rtprocess.h"
# Line 56 | 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) */
61 + int             nr_out = 0;                     /* # of rows output by kids */
62  
63   static int      checksymbolic(ROPMAT *rop);
64  
65 + 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 */
70 + }
71 +
72   static int
73   split_input(ROPMAT *rop)
74   {
# Line 586 | Line 596 | spawned_children(int np)
596   #endif
597                  return(0);
598          }
599 +        gpid = setpgrp();       /* set group process ID */
600 +        signal(SIGIO, on_sigio);
601          fflush(stdout);         /* flush header & spawn children */
602          cproc = (SUBPROC *)malloc(sizeof(SUBPROC)*np);
603          if (!cproc)
# Line 656 | Line 668 | parent_loop()
668                  break;
669              for (i = 0; i < nmats; i++)
670                  if (!rmx_write_data(mop[i].imx.mtx, mop[i].imx.ncomp,
671 <                                mop[i].imx.ncols, DTdouble, ofp))
671 >                                        mop[i].imx.ncols, DTdouble, ofp))
672                          return(0);
673              if (fflush(ofp) == EOF)
674                  return(0);
# Line 760 | Line 772 | combine_input()
772                          return(0);
773              }
774              rmx_free(mres); mres = NULL;
775 <            if (inchild >= 0) {
776 <                i = getc(stdin);        /* child waits for turn to output */
777 <                if (i != EOF) ungetc(i, stdin);
766 <            }
775 >            if (inchild >= 0)           /* children share stdout */
776 >                while (nr_out < cur_row)
777 >                    pause();            /* wait for our turn */
778              if (!rmx_write_data(res->rmp->mtx, res->rmp->ncomp,
779                                  res->rmp->ncols, res->rmp->dtype, stdout))
780                  return(0);
781 <            if (inchild >= 0 && fflush(stdout) == EOF)
782 <                return(0);
781 >            if (inchild >= 0) {         /* flush and notify group */
782 >                if (fflush(stdout) == EOF)
783 >                    return(0);
784 >                killpg(gpid, SIGIO);    /* increments everyone's nr_out */
785 >            }
786          }
787          return(inchild >= 0 || fflush(stdout) != EOF);
788   memerror:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines