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

Comparing ray/src/util/rpiece.c (file contents):
Revision 2.8 by greg, Sun Aug 9 12:12:48 1992 UTC vs.
Revision 2.9 by greg, Sun Aug 9 13:31:30 1992 UTC

# Line 15 | Line 15 | static char SCCSid[] = "$SunId$ LBL";
15   #include "view.h"
16   #include "resolu.h"
17  
18 +                                /* set the following to 0 to forgo forking */
19 + #ifndef MAXFORK
20 + #define  MAXFORK                2       /* max. unreaped child processes */
21 + #endif
22 +
23                                  /* rpict command */
24   char  *rpargv[128] = {"rpict", "-S", "1", "-x", "512", "-y", "512", "-pa", "1"};
25   int  rpargc = 9;
# Line 30 | Line 35 | char  *outfile = NULL;
35   int  outfd;
36   long  scanorig;
37   int  syncfd = -1;               /* lock file descriptor */
38 + int  nforked = 0;
39  
40   char  *progname;
41   int  verbose = 0;
# Line 245 | Line 251 | int  *xp, *yp;
251   int
252   cleanup()                       /* close rpict process and clean up */
253   {
254 <        register int  rpstat;
254 >        register int  pid;
255 >        int  status, rstat = 0;
256  
257          free((char *)pbuf);
258          fclose(torp);
259          fclose(fromrp);
260 <        rpstat = close_process(rpd);
261 <        if (rpstat == -1)
262 <                rpstat = 0;
263 <        return(rpstat);
260 >        while ((pid = wait(&status)) != -1)
261 >                if (rstat == 0)
262 >                        rstat = status>>8 & 0xff;
263 >        return(rstat);
264   }
265  
266  
# Line 302 | Line 309 | rpiece()                       /* render picture piece by piece */
309   }
310  
311  
312 + int
313   putpiece(xpos, ypos)            /* get next piece from rpict */
314   int  xpos, ypos;
315   {
316          struct flock  fls;
317 +        int  pid, status;
318          int  hr, vr;
319          register int  y;
320                                  /* check bounds */
# Line 328 | Line 337 | int  xpos, ypos;
337                                          progname, rpargv[0]);
338                          exit(1);
339                  }
340 + #if MAXFORK
341 +                                /* fork so we don't slow rpict down */
342 +        if ((pid = fork()) > 0) {
343 +                if (++nforked > MAXFORK) {
344 +                        wait(&status);          /* reap a child */
345 +                        if (status)
346 +                                exit(status>>8 & 0xff);
347 +                        nforked--;
348 +                }
349 +                return(pid);
350 +        }
351 + #else
352 +        pid = -1;               /* no forking */
353 + #endif
354                                  /* lock file section so NFS doesn't mess up */
355          fls.l_whence = 0;
356          fls.l_len = (long)vres*hmult*hres*sizeof(COLR);
# Line 337 | Line 360 | int  xpos, ypos;
360                                  /* write new piece to file */
361          if (lseek(outfd, fls.l_start+(long)xpos*hres*sizeof(COLR), 0) == -1)
362                  goto seekerr;
363 <        for (y = 0; y < vr; y++) {
364 <                if (writebuf(outfd, (char *)(pbuf+y*hr), hr*sizeof(COLR)) !=
365 <                                hr*sizeof(COLR)) {
366 <                        fprintf(stderr, "%s: write error on file \"%s\"\n",
367 <                                        progname, outfile);
368 <                        exit(1);
363 >        if (hmult == 1) {
364 >                if (writebuf(outfd, (char *)pbuf,
365 >                                vr*hr*sizeof(COLR)) != vr*hr*sizeof(COLR))
366 >                        goto writerr;
367 >        } else
368 >                for (y = 0; y < vr; y++) {
369 >                        if (writebuf(outfd, (char *)(pbuf+y*hr),
370 >                                        hr*sizeof(COLR)) != hr*sizeof(COLR))
371 >                                goto writerr;
372 >                        if (y < vr-1 && lseek(outfd,
373 >                                        (long)(hmult-1)*hr*sizeof(COLR),
374 >                                        1) == -1)
375 >                                goto seekerr;
376                  }
377 <                if (hmult != 1 && y < vr-1 && lseek(outfd,
378 <                                (long)(hmult-1)*hr*sizeof(COLR), 1) == -1)
379 <                        goto seekerr;
377 >        if (pid == -1) {        /* fork failed */
378 >                fls.l_type = F_UNLCK;           /* release lock */
379 >                fcntl(outfd, F_SETLKW, &fls);
380 >                return(0);
381          }
382 <                                /* unlock file section */
352 <        fls.l_type = F_UNLCK;
353 <        fcntl(outfd, F_SETLKW, &fls);
354 <        return;
382 >        _exit(0);               /* else exit child process (releasing lock) */
383   seekerr:
384          fprintf(stderr, "%s: seek error on file \"%s\"\n", progname, outfile);
385 <        exit(1);
385 >        _exit(1);
386 > writerr:
387 >        fprintf(stderr, "%s: write error on file \"%s\"\n", progname, outfile);
388 >        _exit(1);
389   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines