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

Comparing ray/src/hd/rholo2l.c (file contents):
Revision 3.14 by schorsch, Mon Jun 30 14:59:12 2003 UTC vs.
Revision 3.23 by greg, Wed Jan 22 18:28:32 2025 UTC

# Line 23 | Line 23 | int    nprocs = 0;                             /* running process count */
23  
24   static char     pfile[] = TEMPLATE;             /* persist file name */
25  
26 < static SUBPROC  rtpd[MAXPROC];          /* process descriptors */
26 > static SUBPROC  rtpd[MAXPROC];                  /* process descriptors */
27   static float    *rtbuf = NULL;                  /* allocated i/o buffer */
28 < static int      maxqlen = 0;                    /* maximum packets per queue */
28 > static int      maxqlen;                        /* maximum packets per queue */
29  
30   static PACKET   *pqueue[MAXPROC];               /* packet queues */
31   static int      pqlen[MAXPROC];                 /* packet queue lengths */
32  
33 + static int bestout(void);
34 + static int slots_avail(void);
35 + static void queue_packet(PACKET *p);
36 + static PACKET * get_packets(int poll);
37 + static void killpersist(void);
38  
39 +
40   int
41 < start_rtrace()                  /* start rtrace process */
41 > start_rtrace(void)                      /* start rtrace process */
42   {
43          static char     buf1[8];
44          int     rmaxpack = 0;
# Line 53 | Line 59 | start_rtrace()                 /* start rtrace process */
59                  rtargv[rtargc++] = "-I-";
60                  rtargv[rtargc++] = "-h-";
61                  rtargv[rtargc++] = "-ld-";
62 +                rtargv[rtargc++] = "-co-";
63                  sprintf(buf1, "%d", RPACKSIZ);
64                  rtargv[rtargc++] = "-x"; rtargv[rtargc++] = buf1;
65                  rtargv[rtargc++] = "-y"; rtargv[rtargc++] = "0";
# Line 72 | Line 79 | start_rtrace()                 /* start rtrace process */
79                  psiz = open_process(&rtpd[nprocs], rtargv);
80                  if (psiz <= 0)
81                          error(SYSTEM, "cannot start rtrace process");
82 <                n = psiz/(RPACKSIZ*6*sizeof(float));
83 <                if (maxqlen == 0) {
84 <                        if (!(maxqlen = n))
78 <                                error(INTERNAL,
79 <                                        "bad pipe buffer size assumption");
82 >                n = psiz/(RPACKSIZ*6*sizeof(float)) + 1;
83 >                if (!maxqlen) {
84 >                        maxqlen = n;
85                          sleep(2);
86                  } else if (n != maxqlen)
87                          error(INTERNAL, "varying pipe buffer size!");
# Line 90 | Line 95 | start_rtrace()                 /* start rtrace process */
95  
96  
97   static int
98 < bestout()                       /* get best process to process packet */
98 > bestout(void)                   /* get best process to process packet */
99   {
100          int     cnt;
101 <        register int    pn, i;
101 >        int     pn, i;
102  
103          pn = 0;                 /* find shortest queue */
104          for (i = 1; i < nprocs; i++)
# Line 107 | Line 112 | bestout()                      /* get best process to process packet */
112                  if (pqlen[i] == pqlen[pn])
113                          cnt++;
114                                  /* break ties fairly */
115 <        if ((cnt = random() % cnt))
115 >        if ((cnt = irandom(cnt)))
116                  for (i = pn; i < nprocs; i++)
117                          if (pqlen[i] == pqlen[pn] && !cnt--)
118                                  return(i);
# Line 115 | Line 120 | bestout()                      /* get best process to process packet */
120   }
121  
122  
123 < int
124 < slots_avail()                   /* count packet slots available */
123 > static int
124 > slots_avail(void)                       /* count packet slots available */
125   {
126 <        register int    nslots = 0;
127 <        register int    i;
126 >        int     nslots = 0;
127 >        int     i;
128  
129          for (i = nprocs; i--; )
130                  nslots += maxqlen - pqlen[i];
# Line 127 | Line 132 | slots_avail()                  /* count packet slots available */
132   }
133  
134  
135 < queue_packet(p)                 /* queue up a beam packet */
136 < register PACKET *p;
135 > static void
136 > queue_packet(                   /* queue up a beam packet */
137 >        PACKET  *p
138 > )
139   {
140          int     pn, n;
141                                  /* determine process to write to */
# Line 138 | Line 145 | register PACKET        *p;
145          packrays(rtbuf, p);
146          if ((n = p->nr) < RPACKSIZ)     /* add flush block? */
147                  memset((char *)(rtbuf+6*n++), '\0', 6*sizeof(float));
148 <        if (writebuf(rtpd[pn].w, (char *)rtbuf, 6*sizeof(float)*n) < 0)
148 >        if (writebuf(rtpd[pn].w, rtbuf, 6*sizeof(float)*n) < 0)
149                  error(SYSTEM, "write error in queue_packet");
150          p->next = NULL;
151          if (!pqlen[pn]++)       /* add it to the end of the queue */
152                  pqueue[pn] = p;
153          else {
154 <                register PACKET *rpl = pqueue[pn];
154 >                PACKET  *rpl = pqueue[pn];
155                  while (rpl->next != NULL)
156                          rpl = rpl->next;
157                  rpl->next = p;
# Line 152 | Line 159 | register PACKET        *p;
159   }
160  
161  
162 < PACKET *
163 < get_packets(poll)               /* read packets from rtrace processes */
164 < int     poll;
162 > static PACKET *
163 > get_packets(            /* read packets from rtrace processes */
164 >        int     poll
165 > )
166   {
167          static struct timeval   tpoll;  /* zero timeval struct */
168          fd_set  readset, errset;
169          PACKET  *pldone = NULL, *plend;
170 <        register PACKET *p;
170 >        PACKET  *p;
171          int     n, nr;
172 <        register int    pn;
172 >        int     pn;
173          float   *bp;
174                                          /* prepare select call */
175          FD_ZERO(&readset); FD_ZERO(&errset); n = 0;
# Line 191 | Line 199 | int    poll;
199                  n = read(rtpd[pn].r, (char *)rtbuf,
200                                  4*sizeof(float)*RPACKSIZ*pqlen[pn]);
201                  if (n < 0) {
202 <                        if (errno == EINTR | errno == EAGAIN)
202 >                        if ((errno == EINTR) | (errno == EAGAIN))
203                                  goto reread;
204                          error(SYSTEM, "read error in get_packets");
205                  }
# Line 227 | Line 235 | int    poll;
235          return(pldone);                         /* return finished packets */
236   eoferr:
237          error(USER, "rtrace process died");
238 +        return NULL; /* pro forma return */
239   }
240  
241  
242   PACKET *
243 < do_packets(pl)                  /* queue a packet list, return finished */
244 < register PACKET *pl;
243 > do_packets(                     /* queue a packet list, return finished */
244 >        PACKET  *pl
245 > )
246   {
247 <        register PACKET *p;
247 >        PACKET  *p;
248                                          /* consistency check */
249          if (nprocs < 1)
250                  error(CONSISTENCY, "do_packets called with no active process");
# Line 248 | Line 258 | register PACKET        *pl;
258  
259  
260   PACKET *
261 < flush_queue()                   /* empty all rtrace queues */
261 > flush_queue(void)                       /* empty all rtrace queues */
262   {
263          PACKET  *rpdone = NULL;
264 <        register PACKET *rpl;
264 >        PACKET  *rpl = NULL;
265          float   *bp;
266 <        register PACKET *p;
266 >        PACKET  *p;
267          int     i, n, nr;
268  
269          for (i = 0; i < nprocs; i++)
# Line 270 | Line 280 | flush_queue()                  /* empty all rtrace queues */
280                                  if (rpl->nr < RPACKSIZ)
281                                          nr++;           /* add flush block */
282                          }
283 <                        n = readbuf(rtpd[i].r, (char *)rtbuf,
274 <                                        4*sizeof(float)*nr);
283 >                        n = readbuf(rtpd[i].r, rtbuf, 4*sizeof(float)*nr);
284                          if (n < 0)
285                                  error(SYSTEM, "read failure in flush_queue");
286                          bp = rtbuf;                     /* process packets */
# Line 292 | Line 301 | flush_queue()                  /* empty all rtrace queues */
301   }
302  
303  
304 < static
305 < killpersist()                   /* kill persistent process */
304 > static void
305 > killpersist(void)                       /* kill persistent process */
306   {
307          FILE    *fp;
308          int     pid;
# Line 307 | Line 316 | killpersist()                  /* kill persistent process */
316  
317  
318   int
319 < end_rtrace()                    /* close rtrace process(es) */
319 > end_rtrace(void)                        /* close rtrace process(es) */
320   {
321          int     status = 0, rv;
322  
323          if (nprocs > 1)
324                  killpersist();
325 <        while (nprocs > 0) {
326 <                rv = close_process(&rtpd[--nprocs]);
318 <                if (rv > 0)
319 <                        status = rv;
320 <        }
325 >        status = close_processes(rtpd, nprocs);
326 >        nprocs = 0;
327          free((void *)rtbuf);
328          rtbuf = NULL;
329          maxqlen = 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines