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.27 by gwlarson, Wed Nov 4 16:44:16 1998 UTC vs.
Revision 3.28 by gwlarson, Mon Nov 9 17:10:53 1998 UTC

# Line 103 | Line 103 | register int   fd;
103   }
104  
105  
106 markdirty(hp)                   /* mark holodeck section directory dirty */
107 register HOLO   *hp;
108 {
109        static BEAMI    smudge = {0, -1};
110
111        if (hp->dirty)          /* already marked? */
112                return;
113        hp->dirty = 1;
114        if (lseek(hp->fd, biglob(hp)->fo+(nbeams(hp)-1)*sizeof(BEAMI), 0) < 0
115                        || write(hp->fd, (char *)&smudge,
116                                        sizeof(BEAMI)) != sizeof(BEAMI))
117                error(SYSTEM, "seek/write error in markdirty");
118 }
119
120
106   HOLO *
107   hdinit(fd, hproto)      /* initialize a holodeck section in a file */
108   int     fd;                     /* corresponding file descriptor */
# Line 144 | Line 129 | HDGRID *hproto;                /* holodeck section grid */
129                  if (read(fd, (char *)(hp->bi+1), n) != n)
130                          error(SYSTEM, "failure loading holodeck directory");
131                                                  /* check that it's clean */
132 <                if (hp->bi[nbeams(hp)].fo < 0)
133 <                        error(WARNING, "dirty holodeck section");
132 >                for (n = nbeams(hp); n > 0; n--)
133 >                        if (hp->bi[n].fo < 0) {
134 >                                hp->bi[n].fo = 0;
135 >                                error(WARNING, "dirty holodeck section");
136 >                                break;
137 >                        }
138          } else {                        /* assume we're creating it */
139                  if ((hp = hdalloc(hproto)) == NULL)
140                          goto memerr;
# Line 189 | Line 178 | memerr:
178   }
179  
180  
181 + markdirty(hp, i)                /* mark holodeck directory position dirty */
182 + register HOLO   *hp;
183 + int     i;
184 + {
185 +        static BEAMI    smudge = {0, -1};
186 +        int     mindist, minpos;
187 +        register int    j;
188 +
189 +        if (!hp->dirty++) {                     /* write smudge first time */
190 +                if (lseek(hp->fd, biglob(hp)->fo+(i-1)*sizeof(BEAMI), 0) < 0
191 +                                || write(hp->fd, (char *)&smudge,
192 +                                        sizeof(BEAMI)) != sizeof(BEAMI))
193 +                        error(SYSTEM, "seek/write error in markdirty");
194 +                hp->dirseg[0].s = i;
195 +                hp->dirseg[0].n = 1;
196 +                return;
197 +        }
198 +                                                /* insert into segment list */
199 +        for (j = hp->dirty; j--; ) {
200 +                if (!j || hp->dirseg[j-1].s < i) {
201 +                        hp->dirseg[j].s = i;
202 +                        hp->dirseg[j].n = 1;
203 +                        break;
204 +                }
205 +                copystruct(hp->dirseg+j, hp->dirseg+(j-1));
206 +        }
207 +        mindist = nbeams(hp);                   /* find closest neighbors */
208 +        for (j = hp->dirty; --j; )
209 +                if (hp->dirseg[j].s - (hp->dirseg[j-1].s + hp->dirseg[j-1].n)
210 +                                < mindist) {
211 +                        mindist = hp->dirseg[j].s -
212 +                                        (hp->dirseg[j-1].s + hp->dirseg[j-1].n);
213 +                        minpos = j;
214 +                }
215 +        if (hp->dirty > MAXDIRSE || mindist <= BUFSIZ/sizeof(BEAMI)) {
216 +                j = minpos - 1;                 /* coalesce neighbors */
217 +                if (hp->dirseg[j].s + hp->dirseg[j].n <
218 +                                hp->dirseg[minpos].s + hp->dirseg[minpos].n) {
219 +                        hp->dirseg[j].n = hp->dirseg[minpos].s +
220 +                                        hp->dirseg[minpos].n - hp->dirseg[j].s;
221 +                }
222 +                hp->dirty--;                    /* close the gap */
223 +                for (j = minpos; j < hp->dirty; j++)
224 +                        copystruct(hp->dirseg+j, hp->dirseg+(j+1));
225 +        }
226 + }
227 +
228 +
229   int
230   hdsync(hp, all)                 /* update beams and directory on disk */
231   register HOLO   *hp;
# Line 208 | Line 245 | int    all;
245                          hdsyncbeam(hp, j);
246          if (!hp->dirty)                 /* directory clean? */
247                  return(0);
248 <        errno = 0;
249 <        if (lseek(hp->fd, biglob(hp)->fo, 0) < 0)
250 <                error(SYSTEM, "cannot seek on holodeck file");
251 <        n = nbeams(hp)*sizeof(BEAMI);
252 <        if (write(hp->fd, (char *)(hp->bi+1), n) != n)
253 <                error(SYSTEM, "cannot update holodeck section directory");
254 <        hp->dirty = 0;
248 >        errno = 0;                      /* write dirty segments */
249 >        for (j = 0; j < hp->dirty; j++) {
250 >                if (lseek(hp->fd, biglob(hp)->fo +
251 >                                (hp->dirseg[j].s-1)*sizeof(BEAMI), 0) < 0)
252 >                        error(SYSTEM, "cannot seek on holodeck file");
253 >                n = hp->dirseg[j].n * sizeof(BEAMI);
254 >                if (write(hp->fd, (char *)(hp->bi+hp->dirseg[j].s), n) != n)
255 >                        error(SYSTEM, "cannot update section directory");
256 >        }
257 >        hp->dirty = 0;                  /* all clean */
258          return(1);
259   }
260  
# Line 567 | Line 607 | register int   i;
607                  hp->bi[i].fo = 0L;
608          biglob(hp)->nrd += nrays - hp->bi[i].nrd;
609          hp->bi[i].nrd = nrays;
610 <        markdirty(hp);                  /* section directory now out of date */
610 >        markdirty(hp, i);               /* section directory now out of date */
611          return(1);
612   }
613  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines