--- ray/src/hd/rholo3.c 1999/01/07 22:04:49 3.27 +++ ray/src/hd/rholo3.c 1999/02/02 16:13:24 3.30 @@ -9,6 +9,7 @@ static char SCCSid[] = "$SunId$ SGI"; */ #include "rholo.h" +#include #ifndef NFRAG2CHUNK #define NFRAG2CHUNK 4096 /* number of fragments to start chunking */ @@ -23,11 +24,14 @@ static char SCCSid[] = "$SunId$ SGI"; #define rchunk(n) (((n)+(RPACKSIZ/2))/RPACKSIZ) +extern time_t time(); + +int chunkycmp = 0; /* clump beams together on disk */ + static PACKHEAD *complist=NULL; /* list of beams to compute */ static int complen=0; /* length of complist */ static int listpos=0; /* current list position for next_packet */ static int lastin= -1; /* last ordered position in list */ -static int chunky=0; /* clump beams together on disk */ int @@ -37,12 +41,13 @@ register PACKHEAD *b0, *b1; BEAMI *bip0, *bip1; register long c; /* first check desired quantities */ - if (chunky) - c = rchunk(b1->nr)*(rchunk(b0->nc)+1) - - rchunk(b0->nr)*(rchunk(b1->nc)+1); + if (chunkycmp) + c = rchunk(b1->nr)*(rchunk(b0->nc)+1L) - + rchunk(b0->nr)*(rchunk(b1->nc)+1L); else - c = b1->nr*(b0->nc+1) - b0->nr*(b1->nc+1); - if (c) return(c); + c = b1->nr*(b0->nc+1L) - b0->nr*(b1->nc+1L); + if (c > 0) return(1); + if (c < 0) return(-1); /* only one file, so skip the following: */ #if 0 /* next, check file descriptors */ @@ -98,6 +103,10 @@ register HDBEAMI *hb; error(CONSISTENCY, "unregistered holodeck in dispbeam"); p->bi = hb->b; disp_packet(p); /* display it */ + if (n >= 1024) { /* free ridiculous packets */ + free((char *)p); + p = NULL; n = 0; + } } @@ -258,6 +267,8 @@ init_global() /* initialize global ray computation * free((char *)complist); done_packets(flush_queue()); } + /* reseed random number generator */ + srandom(time(NULL)); /* allocate beam list */ complen = 0; for (j = 0; hdlist[j] != NULL; j++) @@ -324,17 +335,17 @@ sortcomplist() /* fix our list order */ if (complen <= 0) /* check to see if there is even a list */ return; - if (!chunky) /* check to see if fragment list is full */ + if (!chunkycmp) /* check to see if fragment list is full */ if (!hdfragOK(hdlist[0]->fd, &listlen, NULL) #if NFRAG2CHUNK || listlen >= NFRAG2CHUNK #endif ) { + chunkycmp++; /* use "chunky" comparison */ + lastin = -1; /* need to re-sort list */ #ifdef DEBUG error(WARNING, "using chunky comparison mode"); #endif - chunky++; /* use "chunky" comparison */ - lastin = -1; /* need to re-sort list */ } if (lastin < 0 || listpos*4 >= complen*3) qsort((char *)complist, complen, sizeof(PACKHEAD), beamcmp); @@ -391,10 +402,8 @@ int n; p->nr = complist[listpos].nr - p->nc; if (p->nr <= 0) return(0); -#ifdef DEBUG - if (n < 1 | n > RPACKSIZ) - error(CONSISTENCY, "next_packet called with bad n value"); -#endif + DCHECK(n < 1 | n > RPACKSIZ, + CONSISTENCY, "next_packet called with bad n value"); if (p->nr > n) p->nr = n; complist[listpos].nc += p->nr; /* find where this one would go */