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.16 by gregl, Wed Dec 31 11:35:39 1997 UTC vs.
Revision 3.18 by gregl, Thu Jan 1 16:40:38 1998 UTC

# Line 348 | Line 348 | register int   i;
348  
349  
350   int
351 < hdfilord(hb1, hb2)      /* order beams for optimal loading */
351 > hdfilord(hb1, hb2)      /* order beams for quick loading */
352   register HDBEAMI        *hb1, *hb2;
353   {
354 <        register int    c;
355 <                                /* sort by file descriptor first */
354 >        register long   c;
355 >                                /* residents go first */
356 >        if (hb2->h->bl[hb2->b] != NULL)
357 >                return(hb1->h->bl[hb1->b] == NULL);
358 >        if (hb1->h->bl[hb1->b] != NULL)
359 >                return(-1);
360 >                                /* otherwise sort by file descriptor */
361          if ((c = hb1->h->fd - hb2->h->fd))
362                  return(c);
363                                  /* then by position in file */
364 <        return(hb1->h->bi[hb1->b].fo - hb2->h->bi[hb2->b].fo);
364 >        c = hb1->h->bi[hb1->b].fo - hb2->h->bi[hb2->b].fo;
365 >        return(c > 0 ? 1 : c < 0 ? -1 : 0);
366   }
367  
368  
# Line 375 | Line 381 | int    (*bf)();                /* callback function (optional) */
381                          error(CONSISTENCY, "bad beam in hdloadbeams");
382                                          /* sort list for optimal access */
383          qsort((char *)hb, n, sizeof(HDBEAMI), hdfilord);
384 <        bytesloaded = needbytes = 0;    /* figure out memory needs */
384 >        bytesloaded = 0;                /* run through loaded beams */
385 >        for ( ; n && (bp = hb->h->bl[hb->b]) != NULL; n--, hb++) {
386 >                bp->tick = hdclock;             /* preempt swap */
387 >                bytesloaded += bp->nrm;
388 >                if (bf != NULL)
389 >                        (*bf)(bp, hb->h, hb->b);
390 >        }
391 >        bytesloaded *= sizeof(RAYVAL);
392          if ((origcachesize = hdcachesize) > 0) {
393 +                needbytes = 0;          /* figure out memory needs */
394                  for (i = n; i--; )
395 <                        if ((bp = hb[i].h->bl[hb[i].b]) != NULL) {
382 <                                bp->tick = hdclock;     /* preempt swap */
383 <                                bytesloaded += bp->nrm;
384 <                        } else                          /* prepare to load */
385 <                                needbytes += hb[i].h->bi[hb[i].b].nrd;
386 <                bytesloaded *= sizeof(RAYVAL);
395 >                        needbytes += hb[i].h->bi[hb[i].b].nrd;
396                  needbytes *= sizeof(RAYVAL);
397                  do {                            /* free enough memory */
398                          memuse = hdmemuse(0);
399 <                        bytes2free = needbytes - (signed)(hdcachesize-memuse);
400 <                        if (bytes2free > (signed)(memuse - bytesloaded))
399 >                        bytes2free = needbytes - (int)(hdcachesize-memuse);
400 >                        if (bytes2free > (int)(memuse - bytesloaded))
401                                  bytes2free = memuse - bytesloaded;
402                  } while (bytes2free > 0 &&
403                                  hdfreecache(100*bytes2free/memuse, NULL) < 0);
404 +                hdcachesize = 0;                /* load beams w/o swap */
405          }
396        hdcachesize = 0;                /* load the ordered beams w/o swap */
406          for (i = 0; i < n; i++)
407                  if ((bp = hdgetbeam(hb[i].h, hb[i].b)) != NULL && bf != NULL)
408                          (*bf)(bp, hb[i].h, hb[i].b);
# Line 420 | Line 429 | register int   i;
429          if (hp->bl[i] == NULL || (nrays = hp->bl[i]->nrm) == hp->bi[i].nrd)
430                  return(0);
431                                          /* locate fragment */
432 <        if (hp->fd >= nhdfragls || !hdfragl[hp->fd].nlinks) /* untracked */
424 <                hp->bi[i].fo = lseek(hp->fd, 0L, 2);
425 <
426 <        else if (hp->bi[i].fo + hp->bi[i].nrd*sizeof(RAYVAL) ==
432 >        if (hp->bi[i].fo + hp->bi[i].nrd*sizeof(RAYVAL) ==
433                          hdfragl[hp->fd].flen)           /* EOF special case */
434                  hdfragl[hp->fd].flen = (nfo=hp->bi[i].fo) + nrays*sizeof(RAYVAL);
435  
# Line 503 | Line 509 | register int   i;
509                  n = hp->bl[i]->nrm * sizeof(RAYVAL);
510                  if (write(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) {
511                          hdfragl[hp->fd].writerr++;
512 <                        hdsync(hp, 0);          /* sync directory */
512 >                        hdsync(NULL, 0);        /* sync directories */
513                          error(SYSTEM, "write error in hdsyncbeam");
514                  }
515          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines