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.54 by greg, Wed Oct 22 02:06:34 2003 UTC vs.
Revision 3.57 by greg, Thu Sep 9 01:41:21 2004 UTC

# Line 12 | Line 12 | static const char      RCSid[] = "$Id$";
12   #include <string.h>
13  
14   #include "platform.h"
15 + #include "rtprocess.h"
16  
17   #include "holo.h"
18  
# Line 63 | Line 64 | static struct fraglist {
64  
65   static int      nhdfragls;      /* size of hdfragl array */
66  
67 + static HOLO *hdalloc(HDGRID *hproto);
68 + static char *hdrealloc(char *ptr, unsigned siz, char *rout);
69 + static void hdattach(int fd, int wr);
70 + static void hdrelease(int fd);
71 + static void hdmarkdirty(HOLO *hp, int i);
72 + static unsigned int hdmemuse(int all);
73 + static int hdfilord(const void *hb1, const void *hb2);
74 + static off_t hdallocfrag(int fd, uint32 nrays);
75 + static int hdsyncbeam(HOLO *hp, int i);
76 + static int hdlrulist(HDBEAMI *hb, int nents, int n, HOLO *hp);
77 + static int hdfreecache(int pct, HOLO *honly);
78  
79 +
80 +
81   HOLO *
82 < hdalloc(hproto)         /* allocate and set holodeck section based on grid */
83 < HDGRID  *hproto;
82 > hdalloc(                /* allocate and set holodeck section based on grid */
83 >        HDGRID  *hproto
84 > )
85   {
86          HOLO    hdhead;
87          register HOLO   *hp;
# Line 99 | Line 114 | HDGRID *hproto;
114  
115  
116   char *
117 < hdrealloc(ptr, siz, rout)       /* (re)allocate memory, retry then error */
118 < char    *ptr;
119 < unsigned        siz;
120 < char    *rout;
117 > hdrealloc(      /* (re)allocate memory, retry then error */
118 >        char    *ptr,
119 >        unsigned        siz,
120 >        char    *rout
121 > )
122   {
123          register char   *newp;
124                                          /* call malloc/realloc */
# Line 122 | Line 138 | char   *rout;
138   }
139  
140  
141 < hdattach(fd, wr)        /* start tracking file fragments for some section */
142 < register int    fd;
143 < int     wr;
141 > void
142 > hdattach(       /* start tracking file fragments for some section */
143 >        register int    fd,
144 >        int     wr
145 > )
146   {
147          if (fd >= nhdfragls) {
148                  hdfragl = (struct fraglist *)hdrealloc((char *)hdfragl,
# Line 143 | Line 161 | int    wr;
161   /* Do we need a routine to locate file fragments given known occupants? */
162  
163  
164 < hdrelease(fd)           /* stop tracking file fragments for some section */
165 < register int    fd;
164 > void
165 > hdrelease(              /* stop tracking file fragments for some section */
166 >        register int    fd
167 > )
168   {
169          if ((fd < 0) | (fd >= nhdfragls) || !hdfragl[fd].nlinks)
170                  return;
# Line 156 | Line 176 | register int   fd;
176   }
177  
178  
179 < HOLO *
180 < hdinit(fd, hproto)      /* initialize a holodeck section in a file */
181 < int     fd;                     /* corresponding file descriptor */
182 < HDGRID  *hproto;                /* holodeck section grid */
179 > extern HOLO *
180 > hdinit( /* initialize a holodeck section in a file */
181 >        int     fd,                     /* corresponding file descriptor */
182 >        HDGRID  *hproto         /* holodeck section grid */
183 > )
184   {
185          off_t   rtrunc;
186          off_t   fpos;
# Line 238 | Line 259 | HDGRID *hproto;                /* holodeck section grid */
259          return(hp);
260   memerr:
261          error(SYSTEM, "cannot allocate holodeck grid");
262 +        return NULL; /* pro forma return */
263   }
264  
265  
266 < hdmarkdirty(hp, i)              /* mark holodeck directory position dirty */
267 < register HOLO   *hp;
268 < int     i;
266 > void
267 > hdmarkdirty(            /* mark holodeck directory position dirty */
268 >        register HOLO   *hp,
269 >        int     i
270 > )
271   {
272          static BEAMI    smudge = {0, -1};
273          int     mindist, minpos;
# Line 293 | Line 317 | int    i;
317   }
318  
319  
320 < int
321 < hdsync(hp, all)                 /* update beams and directory on disk */
322 < register HOLO   *hp;
323 < int     all;
320 > extern int
321 > hdsync(                 /* update beams and directory on disk */
322 >        register HOLO   *hp,
323 >        int     all
324 > )
325   {
326          register int    j, n;
327  
# Line 326 | Line 351 | int    all;
351   }
352  
353  
354 < unsigned
355 < hdmemuse(all)           /* return memory usage (in bytes) */
356 < int     all;                    /* include overhead (painful) */
354 > unsigned int
355 > hdmemuse(               /* return memory usage (in bytes) */
356 >        int     all                     /* include overhead (painful) */
357 > )
358   {
359          long    total = 0;
360          register int    i, j;
# Line 355 | Line 381 | int    all;                    /* include overhead (painful) */
381   }
382  
383  
384 < off_t
385 < hdfilen(fd)             /* return file length for fd */
386 < int     fd;
384 > extern off_t
385 > hdfilen(                /* return file length for fd */
386 >        int     fd
387 > )
388   {
389          off_t   fpos, flen;
390  
# Line 374 | Line 401 | int    fd;
401   }
402  
403  
404 < off_t
405 < hdfiluse(fd, all)       /* compute file usage (in bytes) */
406 < int     fd;                     /* open file descriptor to check */
407 < int     all;                    /* include overhead and unflushed data */
404 > extern off_t
405 > hdfiluse(       /* compute file usage (in bytes) */
406 >        int     fd                      /* open file descriptor to check */
407 > )
408   {
409          off_t   total = 0;
410 <        register int    i, j;
410 >        register int    j;
411  
412          for (j = 0; hdlist[j] != NULL; j++) {
413                  if (hdlist[j]->fd != fd)
414                          continue;
415                  total += biglob(hdlist[j])->nrd * sizeof(RAYVAL);
416 <                if (all) {
417 <                        for (i = nbeams(hdlist[j]); i > 0; i--)
418 <                                if (hdlist[j]->bl[i] != NULL)
419 <                                        total += sizeof(RAYVAL) *
416 >                total += nbeams(hdlist[j])*sizeof(BEAMI) + sizeof(HDGRID);
417 > #if 0
418 >                for (i = nbeams(hdlist[j]); i > 0; i--)
419 >                        if (hdlist[j]->bl[i] != NULL)
420 >                                total += sizeof(RAYVAL) *
421                                                  (hdlist[j]->bl[i]->nrm -
422                                                  hdlist[j]->bi[i].nrd);
423 <                        total += sizeof(HDGRID) +
396 <                                        nbeams(hdlist[j])*sizeof(BEAMI);
397 <                }
423 > #endif
424          }
425 <        return(total);          /* does not include fragments */
425 >        return(total);          /* doesn't include fragments, unflushed rays */
426   }
427  
428  
429 < RAYVAL *
430 < hdnewrays(hp, i, nr)    /* allocate space for add'l rays and return pointer */
431 < register HOLO   *hp;
432 < register int    i;
433 < int     nr;                     /* number of new rays desired */
429 > extern RAYVAL *
430 > hdnewrays(      /* allocate space for add'l rays and return pointer */
431 >        register HOLO   *hp,
432 >        register int    i,
433 >        int     nr                      /* number of new rays desired */
434 > )
435   {
436          RAYVAL  *p;
437          int     n;
# Line 444 | Line 471 | int    nr;                     /* number of new rays desired */
471   }
472  
473  
474 < BEAM *
475 < hdgetbeam(hp, i)        /* get beam (from file if necessary) */
476 < register HOLO   *hp;
477 < register int    i;
474 > extern BEAM *
475 > hdgetbeam(      /* get beam (from file if necessary) */
476 >        register HOLO   *hp,
477 >        register int    i
478 > )
479   {
480          register int    n;
481  
# Line 475 | Line 503 | register int   i;
503  
504  
505   int
506 < hdfilord(hb1, hb2)      /* order beams for quick loading */
507 < register HDBEAMI        *hb1, *hb2;
506 > hdfilord(       /* order beams for quick loading */
507 >        register const void     *hb1,
508 >        register const void     *hb2
509 > )
510   {
511          register off_t  c;
512                                  /* residents go first */
513 <        if (hb2->h->bl[hb2->b] != NULL)
514 <                return(hb1->h->bl[hb1->b] == NULL);
515 <        if (hb1->h->bl[hb1->b] != NULL)
513 >        if (((HDBEAMI*)hb2)->h->bl[((HDBEAMI*)hb2)->b] != NULL)
514 >                return(((HDBEAMI*)hb1)->h->bl[((HDBEAMI*)hb1)->b] == NULL);
515 >        if (((HDBEAMI*)hb1)->h->bl[((HDBEAMI*)hb1)->b] != NULL)
516                  return(-1);
517                                  /* otherwise sort by file descriptor */
518 <        if (hb1->h->fd != hb2->h->fd)
519 <                return(hb1->h->fd - hb2->h->fd);
518 >        if (((HDBEAMI*)hb1)->h->fd != ((HDBEAMI*)hb2)->h->fd)
519 >                return(((HDBEAMI*)hb1)->h->fd - ((HDBEAMI*)hb2)->h->fd);
520                                  /* then by position in file */
521 <        c = hb1->h->bi[hb1->b].fo - hb2->h->bi[hb2->b].fo;
521 >        c = ((HDBEAMI*)hb1)->h->bi[((HDBEAMI*)hb1)->b].fo
522 >                - ((HDBEAMI*)hb2)->h->bi[((HDBEAMI*)hb2)->b].fo;
523          return(c > 0 ? 1 : c < 0 ? -1 : 0);
524   }
525  
526  
527 < hdloadbeams(hb, n, bf)  /* load a list of beams in optimal order */
528 < register HDBEAMI        *hb;    /* list gets sorted by hdfilord() */
529 < int     n;                      /* list length */
530 < void    (*bf)();                /* callback function (optional) */
527 > extern void
528 > hdloadbeams(    /* load a list of beams in optimal order */
529 >        register HDBEAMI        *hb,    /* list gets sorted by hdfilord() */
530 >        int     n,                      /* list length */
531 >        void    (*bf)(BEAM *bp, HDBEAMI *hb)    /* callback function (optional) */
532 > )
533   {
534          unsigned        origcachesize, memuse;
535          int     bytesloaded, needbytes, bytes2free;
# Line 538 | Line 571 | void   (*bf)();                /* callback function (optional) */
571   }
572  
573  
574 < int
575 < hdfreefrag(hp, i)                       /* free a file fragment */
576 < HOLO    *hp;
577 < int     i;
574 > extern int
575 > hdfreefrag(                     /* free a file fragment */
576 >        HOLO    *hp,
577 >        int     i
578 > )
579   {
580          register BEAMI  *bi = &hp->bi[i];
581          register struct fraglist        *f;
# Line 617 | Line 651 | int    i;
651   }
652  
653  
654 < int
655 < hdfragOK(fd, listlen, listsiz)  /* get fragment list status for file */
656 < int     fd;
657 < int     *listlen;
658 < register int32  *listsiz;
654 > extern int
655 > hdfragOK(       /* get fragment list status for file */
656 >        int     fd,
657 >        int     *listlen,
658 >        register int32  *listsiz
659 > )
660   {
661          register struct fraglist        *f;
662          register int    i;
# Line 642 | Line 677 | register int32 *listsiz;
677  
678  
679   off_t
680 < hdallocfrag(fd, nrays)          /* allocate a file fragment */
681 < int     fd;
682 < uint32  nrays;
680 > hdallocfrag(            /* allocate a file fragment */
681 >        int     fd,
682 >        uint32  nrays
683 > )
684   {
685          register struct fraglist        *f;
686          register int    j;
# Line 671 | Line 707 | uint32 nrays;
707  
708  
709   int
710 < hdsyncbeam(hp, i)               /* sync beam in memory with beam on disk */
711 < register HOLO   *hp;
712 < register int    i;
710 > hdsyncbeam(             /* sync beam in memory with beam on disk */
711 >        register HOLO   *hp,
712 >        register int    i
713 > )
714   {
715          int     fragfreed;
716          uint32  nrays;
# Line 711 | Line 748 | register int   i;
748   }
749  
750  
751 < int
752 < hdfreebeam(hp, i)               /* free beam, writing if dirty */
753 < register HOLO   *hp;
754 < register int    i;
751 > extern int
752 > hdfreebeam(             /* free beam, writing if dirty */
753 >        register HOLO   *hp,
754 >        register int    i
755 > )
756   {
757          int     nchanged;
758  
# Line 752 | Line 790 | register int   i;
790   }
791  
792  
793 < int
794 < hdkillbeam(hp, i)               /* delete beam from holodeck */
795 < register HOLO   *hp;
796 < register int    i;
793 > extern int
794 > hdkillbeam(             /* delete beam from holodeck */
795 >        register HOLO   *hp,
796 >        register int    i
797 > )
798   {
799          int     nchanged;
800  
# Line 798 | Line 837 | register int   i;
837  
838  
839   int
840 < hdlrulist(hb, nents, n, hp)     /* add beams from holodeck to LRU list */
841 < register HDBEAMI        *hb;            /* beam list */
842 < int     nents;                          /* current list length */
843 < int     n;                              /* maximum list length */
844 < register HOLO   *hp;                    /* section we're adding from */
840 > hdlrulist(      /* add beams from holodeck to LRU list */
841 >        register HDBEAMI        *hb,            /* beam list */
842 >        int     nents,                          /* current list length */
843 >        int     n,                              /* maximum list length */
844 >        register HOLO   *hp                     /* section we're adding from */
845 > )
846   {
847          register int    i, j;
848                                          /* insert each beam from hp */
# Line 830 | Line 870 | register HOLO  *hp;                    /* section we're adding from */
870  
871  
872   int
873 < hdfreecache(pct, honly)         /* free up cache space, writing changes */
874 < int     pct;                            /* maximum percentage to free */
875 < register HOLO   *honly;                 /* NULL means check all */
873 > hdfreecache(            /* free up cache space, writing changes */
874 >        int     pct,                            /* maximum percentage to free */
875 >        register HOLO   *honly                  /* NULL means check all */
876 > )
877   {
878          HDBEAMI hb[FREEBEAMS];
879          int     freetarget;
# Line 873 | Line 914 | register HOLO  *honly;                 /* NULL means check all */
914   }
915  
916  
917 < hddone(hp)              /* clean up holodeck section and free */
918 < register HOLO   *hp;            /* NULL means clean up all */
917 > extern void
918 > hddone(         /* clean up holodeck section and free */
919 >        register HOLO   *hp             /* NULL means clean up all */
920 > )
921   {
922          register int    i;
923  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines