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

Comparing ray/src/hd/holofile.c (file contents):
Revision 3.35 by gwlarson, Mon Jan 25 09:58:41 1999 UTC vs.
Revision 3.40 by gwlarson, Fri Mar 12 09:37:48 1999 UTC

# Line 14 | Line 14 | static char SCCSid[] = "$SunId$ SGI";
14  
15   #ifndef CACHESIZE
16   #ifdef BIGMEM
17 < #define CACHESIZE       32      /* default cache size (Mbytes, 0==inf) */
17 > #define CACHESIZE       17      /* default cache size (Mbytes, 0==inf) */
18   #else
19 < #define CACHESIZE       12
19 > #define CACHESIZE       5
20   #endif
21   #endif
22   #ifndef FREEBEAMS
# Line 30 | Line 30 | static char SCCSid[] = "$SunId$ SGI";
30   #endif
31   #ifndef FF_DEFAULT
32                                  /* when to free a beam fragment */
33 < #define FF_DEFAULT      (FF_ALLOC|FF_WRITE|FF_KILL)
33 > #define FF_DEFAULT      (FF_WRITE|FF_KILL)
34   #endif
35   #ifndef MINDIRSEL
36                                  /* minimum directory seek length */
# Line 61 | Line 61 | static struct fraglist {
61   static int      nhdfragls;      /* size of hdfragl array */
62  
63  
64 + HOLO *
65 + hdalloc(hproto)         /* allocate and set holodeck section based on grid */
66 + HDGRID  *hproto;
67 + {
68 +        HOLO    hdhead;
69 +        register HOLO   *hp;
70 +        int     n;
71 +                                /* copy grid to temporary header */
72 +        bcopy((char *)hproto, (char *)&hdhead, sizeof(HDGRID));
73 +                                /* compute grid vectors and sizes */
74 +        hdcompgrid(&hdhead);
75 +                                /* allocate header with directory */
76 +        n = sizeof(HOLO)+nbeams(&hdhead)*sizeof(BEAMI);
77 +        if ((hp = (HOLO *)malloc(n)) == NULL)
78 +                return(NULL);
79 +                                /* copy header information */
80 +        copystruct(hp, &hdhead);
81 +                                /* allocate and clear beam list */
82 +        hp->bl = (BEAM **)malloc((nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM));
83 +        if (hp->bl == NULL) {
84 +                free((char *)hp);
85 +                return(NULL);
86 +        }
87 +        bzero((char *)hp->bl, (nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM));
88 +        hp->bl[0] = (BEAM *)(hp->bl+nbeams(hp)+1);      /* set blglob(hp) */
89 +        hp->fd = -1;
90 +        hp->dirty = 0;
91 +        hp->priv = NULL;
92 +                                /* clear beam directory */
93 +        bzero((char *)hp->bi, (nbeams(hp)+1)*sizeof(BEAMI));
94 +        return(hp);             /* all is well */
95 + }
96 +
97 +
98   char *
99   hdrealloc(ptr, siz, rout)       /* (re)allocate memory, retry then error */
100   char    *ptr;
# Line 191 | Line 225 | memerr:
225   }
226  
227  
228 < markdirty(hp, i)                /* mark holodeck directory position dirty */
228 > hdmarkdirty(hp, i)              /* mark holodeck directory position dirty */
229   register HOLO   *hp;
230   int     i;
231   {
# Line 203 | Line 237 | int    i;
237                  if (lseek(hp->fd, biglob(hp)->fo+(i-1)*sizeof(BEAMI), 0) < 0
238                                  || write(hp->fd, (char *)&smudge,
239                                          sizeof(BEAMI)) != sizeof(BEAMI))
240 <                        error(SYSTEM, "seek/write error in markdirty");
240 >                        error(SYSTEM, "seek/write error in hdmarkdirty");
241                  hp->dirseg[0].s = i;
242                  hp->dirseg[0].n = 1;
243                  return;
# Line 559 | Line 593 | int    i;
593          biglob(hp)->nrd -= bi->nrd;             /* tell fragment it's free */
594          bi->nrd = 0;
595          bi->fo = 0L;
596 +        hdmarkdirty(hp, i);                     /* assume we'll reallocate */
597          return(1);
598   }
599  
# Line 621 | Line 656 | hdsyncbeam(hp, i)              /* sync beam in memory with beam on
656   register HOLO   *hp;
657   register int    i;
658   {
659 +        int     fragfreed;
660          unsigned int4   nrays;
661          unsigned int    n;
662          long    nfo;
# Line 632 | Line 668 | register int   i;
668                                          /* is current fragment OK? */
669          if (hp->bl[i] == NULL || (nrays = hp->bl[i]->nrm) == hp->bi[i].nrd)
670                  return(0);
671 <        if (hdfragflags&FF_WRITE && hp->bi[i].nrd)
672 <                hdfreefrag(hp, i);      /* relinquish old fragment */
671 >                                        /* relinquish old fragment? */
672 >        fragfreed = hdfragflags&FF_WRITE && hp->bi[i].nrd && hdfreefrag(hp,i);
673          if (nrays) {                    /* get and write new fragment */
674                  nfo = hdallocfrag(hp->fd, nrays);
675                  errno = 0;
# Line 650 | Line 686 | register int   i;
686                  hp->bi[i].fo = 0L;
687          biglob(hp)->nrd += nrays - hp->bi[i].nrd;
688          hp->bi[i].nrd = nrays;
689 <        markdirty(hp, i);               /* section directory now out of date */
689 >        if (!fragfreed)
690 >                hdmarkdirty(hp, i);             /* need to flag dir. ent. */
691          return(1);
692   }
693  
# Line 671 | Line 708 | register int   i;
708          if (hdfragl[hp->fd].writerr)    /* check for file error */
709                  return(0);
710          if (i == 0) {                   /* clear entire holodeck */
711 +                if (blglob(hp)->nrm == 0)
712 +                        return(0);              /* already clear */
713                  nchanged = 0;
714                  for (i = nbeams(hp); i > 0; i--)
715                          if (hp->bl[i] != NULL)
716                                  nchanged += hdfreebeam(hp, i);
717 +                DCHECK(blglob(hp)->nrm != 0,
718 +                                CONSISTENCY, "bad beam count in hdfreebeam");
719                  return(nchanged);
720          }
721          DCHECK(i < 1 | i > nbeams(hp),
# Line 706 | Line 747 | register int   i;
747                  return(nchanged);
748          }
749          if (i == 0) {                   /* clobber entire holodeck */
750 +                if (biglob(hp)->nrd == 0 & blglob(hp)->nrm == 0)
751 +                        return(0);              /* already empty */
752                  nchanged = 0;
753 +                nchanged = 0;
754                  for (i = nbeams(hp); i > 0; i--)
755                          if (hp->bi[i].nrd > 0 || hp->bl[i] != NULL)
756                                  nchanged += hdkillbeam(hp, i);
# Line 719 | Line 763 | register int   i;
763          if (hp->bl[i] != NULL) {        /* free memory */
764                  blglob(hp)->nrm -= nchanged = hp->bl[i]->nrm;
765                  free((char *)hp->bl[i]);
766 +                hp->bl[i] = NULL;
767          } else
768                  nchanged = hp->bi[i].nrd;
769 <        if (hp->bi[i].nrd) {
770 <                if (hdfragflags&FF_KILL)
771 <                        hdfreefrag(hp, i);
727 <                biglob(hp)->nrd -= hp->bi[i].nrd;
728 <                hp->bi[i].nrd = 0;      /* make sure it's gone */
769 >        if (hp->bi[i].nrd && !(hdfragflags&FF_KILL && hdfreefrag(hp,i))) {
770 >                biglob(hp)->nrd -= hp->bi[i].nrd;       /* free failed */
771 >                hp->bi[i].nrd = 0;
772                  hp->bi[i].fo = 0L;
773 +                hdmarkdirty(hp, i);
774          }
731        hp->bl[i] = NULL;
775          return(nchanged);
776   }
777  
# Line 822 | Line 865 | register HOLO  *hp;            /* NULL means clean up all */
865                  return;
866          }
867                                          /* flush all data and free memory */
868 <        hdfreebeam(hp, 0);
826 <        hdsync(hp, 0);
868 >        hdflush(hp);
869                                          /* release fragment resources */
870          hdrelease(hp->fd);
871                                          /* remove hp from active list */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines