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.3 by gregl, Mon Nov 3 13:40:22 1997 UTC vs.
Revision 3.4 by gregl, Tue Nov 4 10:42:03 1997 UTC

# Line 21 | Line 21 | static char SCCSid[] = "$SunId$ SGI";
21   #ifndef PCTFREE
22   #define PCTFREE         12      /* maximum fraction to free (%) */
23   #endif
24 #ifndef FFDMAX
25 #define FFDMAX          64      /* max. file descriptor for tracking */
26 #endif
27 #ifndef MAXFRAG
28 #define MAXFRAG         2048    /* maximum fragments tracked in each file */
29 #endif
24  
25 + #define MAXFRAG         8192    /* maximum fragments tracked per open file */
26 +
27 + #define FRAGBLK         64      /* number of fragments to allocate at a time */
28 +
29   int     hdcachesize = CACHESIZE*1024*1024;      /* target cache size (bytes) */
30   unsigned long   hdclock;        /* clock value */
31  
# Line 36 | Line 34 | HOLO   *hdlist[HDMAX+1];       /* holodeck pointers (NULL term
34   static struct fragment {
35          short   nlinks;         /* number of holodeck sections using us */
36          short   nfrags;         /* number of known fragments */
37 <        BEAMI   fi[MAXFRAG];    /* fragments, descending file position */
37 >        BEAMI   *fi;            /* fragments, descending file position */
38          long    flen;           /* last known file length */
39 < } *hdfrag[FFDMAX];      /* fragment lists, indexed by file descriptor */
39 > } *hdfrag;              /* fragment lists, indexed by file descriptor */
40  
41 + static int      nhdfrags;       /* size of hdfrag array */
42  
43 +
44   hdattach(fd)            /* start tracking file fragments for some section */
45   register int    fd;
46   {
47 <        if (fd >= FFDMAX)
48 <                return;                         /* descriptor out of range */
49 <        if (hdfrag[fd] == NULL) {
50 <                if ((hdfrag[fd] = (struct fragment *)
51 <                                malloc(sizeof(struct fragment))) == NULL)
52 <                        return;                 /* should flag error? */
53 <                hdfrag[fd]->nlinks = 0;
54 <                hdfrag[fd]->nfrags = 0;
47 >        if (fd >= nhdfrags) {
48 >                if (nhdfrags)
49 >                        hdfrag = (struct fragment *)realloc((char *)hdfrag,
50 >                                        (fd+1)*sizeof(struct fragment));
51 >                else
52 >                        hdfrag = (struct fragment *)malloc(
53 >                                        (fd+1)*sizeof(struct fragment));
54 >                if (hdfrag == NULL)
55 >                        error(SYSTEM, "out of memory in hdattach");
56 >                bzero((char *)(hdfrag+nhdfrags),
57 >                                (fd+1-nhdfrags)*sizeof(struct fragment));
58 >                nhdfrags = fd+1;
59          }
60 <        hdfrag[fd]->nlinks++;
61 <        hdfrag[fd]->flen = lseek(fd, 0L, 2);    /* get file length */
60 >        hdfrag[fd].nlinks++;
61 >        hdfrag[fd].flen = lseek(fd, 0L, 2);     /* get file length */
62   }
63  
64  
# Line 64 | Line 68 | register int   fd;
68   hdrelease(fd)           /* stop tracking file fragments for some section */
69   register int    fd;
70   {
71 <        if (fd >= FFDMAX || hdfrag[fd] == NULL)
71 >        if (fd >= nhdfrags || !hdfrag[fd].nlinks)
72                  return;
73 <        if (!--hdfrag[fd]->nlinks) {
74 <                free((char *)hdfrag[fd]);
75 <                hdfrag[fd] = NULL;
73 >        if (!--hdfrag[fd].nlinks && hdfrag[fd].nfrags) {
74 >                free((char *)hdfrag[fd].fi);
75 >                hdfrag[fd].fi = NULL;
76 >                hdfrag[fd].nfrags = 0;
77          }
78   }
79  
# Line 172 | Line 177 | int    all;                    /* include overhead (painful) */
177                  }
178          }
179          if (all)
180 <                for (j = 0; j < FFDMAX; j++)
181 <                        if (hdfrag[j] != NULL)
182 <                                total += sizeof(struct fragment);
180 >                for (j = 0; j < nhdfrags; j++) {
181 >                        total += sizeof(struct fragment);
182 >                        if (hdfrag[j].nfrags)
183 >                                total += FRAGBLK*sizeof(BEAMI) *
184 >                                        ((hdfrag[j].nfrags-1)/FRAGBLK + 1) ;
185 >                }
186          return(total);
187   }
188  
# Line 294 | Line 302 | register int   i;
302          if (hp->bi[i].nrd == nrays)     /* current one will do? */
303                  return(0);
304  
305 <        if (hp->fd >= FFDMAX || hdfrag[hp->fd] == NULL) /* untracked */
305 >        if (hp->fd >= nhdfrags || !hdfrag[hp->fd].nlinks) /* untracked */
306                  hp->bi[i].fo = lseek(hp->fd, 0L, 2);
307  
308          else if (hp->bi[i].fo + hp->bi[i].nrd*sizeof(RAYVAL) ==
309 <                        hdfrag[hp->fd]->flen)           /* EOF special case */
310 <                hdfrag[hp->fd]->flen = hp->bi[i].fo + nrays*sizeof(RAYVAL);
309 >                        hdfrag[hp->fd].flen)            /* EOF special case */
310 >                hdfrag[hp->fd].flen = hp->bi[i].fo + nrays*sizeof(RAYVAL);
311  
312          else {                                          /* general case */
313 <                register struct fragment        *f = hdfrag[hp->fd];
313 >                register struct fragment        *f = &hdfrag[hp->fd];
314                  register int    j, k;
315                                          /* relinquish old fragment */
316                  if (hp->bi[i].nrd) {
317 <                        if ((j = ++f->nfrags) >= MAXFRAG)
317 >                        j = ++f->nfrags;
318 > #ifdef MAXFRAG
319 >                        if (j >= MAXFRAG)
320                                  f->nfrags--;
321 +                        else
322 + #endif
323 +                        if (j % FRAGBLK == 1) {         /* more frag. space */
324 +                                if (f->fi == NULL)
325 +                                        f->fi = (BEAMI *)malloc(
326 +                                                        FRAGBLK*sizeof(BEAMI));
327 +                                else
328 +                                        f->fi = (BEAMI *)realloc((char *)f->fi,
329 +                                                (FRAGBLK-1+j)*sizeof(BEAMI));
330 +                                if (f->fi == NULL)
331 +                                        error(SYSTEM,
332 +                                                "out of memory in hdgetbi");
333 +                        }
334                          for ( ; ; ) {   /* stick it in our descending list */
335                                  if (!--j || hp->bi[i].fo < f->fi[j-1].fo) {
336                                          f->fi[j].fo = hp->bi[i].fo;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines