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.11 by gregl, Thu Dec 11 19:57:58 1997 UTC vs.
Revision 3.12 by gregl, Fri Dec 12 19:52:31 1997 UTC

# Line 157 | Line 157 | memerr:
157  
158  
159   int
160 < hdsync(hp)                      /* update directory on disk if necessary */
160 > hdsync(hp, all)                 /* update beams and directory on disk */
161   register HOLO   *hp;
162 + int     all;
163   {
164          register int    j, n;
165  
166 <        if (hp == NULL) {               /* do all */
166 >        if (hp == NULL) {               /* do all holodecks */
167                  n = 0;
168                  for (j = 0; hdlist[j] != NULL; j++)
169 <                        n += hdsync(hdlist[j]);
169 >                        n += hdsync(hdlist[j], all);
170                  return(n);
171          }
172 <        if (!hp->dirty)                 /* check first */
172 >                                        /* sync the beams */
173 >        for (j = all ? nbeams(hp) : 0; j > 0; j--)
174 >                if (hp->bl[j] != NULL)
175 >                        hdsyncbeam(hp, j);
176 >        if (!hp->dirty)                 /* directory dirty? */
177                  return(0);
178          errno = 0;
179          if (lseek(hp->fd, biglob(hp)->fo, 0) < 0)
# Line 335 | Line 340 | register int   i;
340  
341  
342   int
343 < hdsyncbi(hp, i)                 /* sync beam in memory with beam on disk */
343 > hdsyncbeam(hp, i)               /* sync beam in memory with beam on disk */
344   register HOLO   *hp;
345   register int    i;
346   {
347 <        unsigned int    nrays = hp->bl[i]->nrm;
347 >        unsigned int    nrays;
348          long    nfo;
349          unsigned int    n;
350 + #ifdef DEBUG
351 +        if (i < 1 | i > nbeams(hp))
352 +                error(CONSISTENCY, "bad beam index in hdsyncbeam");
353 + #endif
354                                          /* is current fragment OK? */
355 <        if (nrays == hp->bi[i].nrd)
355 >        if (hp->bl[i] == NULL || (nrays = hp->bl[i]->nrm) == hp->bi[i].nrd)
356                  return(0);
357                                          /* check file status */
358          if (hp->dirty < 0)
# Line 375 | Line 384 | register int   i;
384                                                  (j+FRAGBLK)*sizeof(BEAMI));
385                                  if (f->fi == NULL)
386                                          error(SYSTEM,
387 <                                                "out of memory in hdsyncbi");
387 >                                                "out of memory in hdsyncbeam");
388                          }
389                          for ( ; ; j--) {        /* insert in descending list */
390                                  if (!j || hp->bi[i].fo < f->fi[j-1].fo) {
# Line 427 | Line 436 | register int   i;
436                  n = hp->bl[i]->nrm * sizeof(RAYVAL);
437                  if (write(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) {
438                          hp->dirty = -1;         /* avoid recursive error */
439 <                        error(SYSTEM, "write error in hdsyncbi");
439 >                        error(SYSTEM, "write error in hdsyncbeam");
440                  }
441          }
442          biglob(hp)->nrd += nrays - hp->bi[i].nrd;
# Line 458 | Line 467 | register int   i;
467                                  nchanged += hdfreebeam(hp, i);
468                  return(nchanged);
469          }
470 + #ifdef DEBUG
471          if (i < 1 | i > nbeams(hp))
472                  error(CONSISTENCY, "bad beam index to hdfreebeam");
473 + #endif
474          if (hp->bl[i] == NULL)
475                  return(0);
476                                          /* check for additions */
477          nchanged = hp->bl[i]->nrm - hp->bi[i].nrd;
478          if (nchanged)
479 <                hdsyncbi(hp, i);                        /* write new fragment */
479 >                hdsyncbeam(hp, i);              /* write new fragment */
480          blglob(hp)->nrm -= hp->bl[i]->nrm;
481          free((char *)hp->bl[i]);                /* free memory */
482          hp->bl[i] = NULL;
# Line 498 | Line 509 | register int   i;
509   #endif
510                  return(nchanged);
511          }
512 + #ifdef DEBUG
513          if (i < 1 | i > nbeams(hp))
514                  error(CONSISTENCY, "bad beam index to hdkillbeam");
515 + #endif
516          if (hp->bl[i] != NULL) {        /* free memory */
517                  blglob(hp)->nrm -= nchanged = hp->bl[i]->nrm;
518                  free((char *)hp->bl[i]);
# Line 507 | Line 520 | register int   i;
520                  nchanged = hp->bi[i].nrd;
521          if (hp->bi[i].nrd) {            /* free file fragment */
522                  hp->bl[i] = &emptybeam;
523 <                hdsyncbi(hp, i);
523 >                hdsyncbeam(hp, i);
524          }
525          hp->bl[i] = NULL;
526          return(nchanged);
# Line 574 | Line 587 | register HOLO  *honly;                 /* NULL means check all */
587                  if ((freetarget -= hp[i]->bi[bn[i]].nrd) <= 0)
588                          break;
589          }
590 <        hdsync(honly);          /* synchronize directories as necessary */
590 >        hdsync(honly, 0);       /* synchronize directories as necessary */
591   }
592  
593  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines