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 |
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 */ |
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 */ |
219 |
|
r_queue[sfirst].crtype = n; |
220 |
< |
nw = writebuf(r_proc[i].fd_send, (char *)&r_queue[sfirst], |
220 |
> |
nw = writebuf(r_proc[i].fd_send, &r_queue[sfirst], |
221 |
|
sizeof(RAY)*n); |
222 |
|
if (nw != sizeof(RAY)*n) |
223 |
|
return(-1); /* write error */ |
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); |
348 |
|
error(CONSISTENCY, "buffer shortage in ray_presult()"); |
349 |
|
|
350 |
|
/* read rendered ray data */ |
351 |
< |
n = readbuf(r_proc[pn].fd_recv, (char *)&r_queue[r_recv_next], |
351 |
> |
n = readbuf(r_proc[pn].fd_recv, &r_queue[r_recv_next], |
352 |
|
sizeof(RAY)*r_proc[pn].npending); |
353 |
|
if (n > 0) { |
354 |
|
r_recv_next += n/sizeof(RAY); |
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; |
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 */ |
435 |
|
rayvalue(&r_queue[i]); |
436 |
|
} |
437 |
|
/* write back our results */ |
438 |
< |
i = writebuf(fd_out, (char *)r_queue, sizeof(RAY)*n); |
438 |
> |
i = writebuf(fd_out, r_queue, sizeof(RAY)*n); |
439 |
|
if (i != sizeof(RAY)*n) |
440 |
|
error(SYSTEM, "write error in ray_pchild()"); |
441 |
|
} |
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 */ |
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 |
|
} |