36f8f6fb024b20cc523cdf9ebde7491eca84fd7c markd Sun Dec 6 20:33:20 2020 -0800 multiple request per connect works except hgBlat diff --git src/jkOwnLib/genoFind.c src/jkOwnLib/genoFind.c index 005320c..233f912 100644 --- src/jkOwnLib/genoFind.c +++ src/jkOwnLib/genoFind.c @@ -65,32 +65,35 @@ totalRead += oneRead; } return totalRead; } void genoFindFree(struct genoFind **pGenoFind) /* Free up a genoFind index. */ { struct genoFind *gf = *pGenoFind; int i; struct gfSeqSource *sources; if (gf != NULL) { freeMem(gf->lists); + if (!gf->isMapped) + { freeMem(gf->listSizes); freeMem(gf->allocated); + } if ((sources = gf->sources) != NULL) { for (i=0; i<gf->sourceCount; ++i) bitFree(&sources[i].maskedBits); freeMem(sources); } freez(pGenoFind); } } static off_t mustSeekAligned(FILE *f) /* seek so that the current offset is 64-bit aligned */ { off_t off = ftell(f); if ((off & 0x7) != 0) @@ -314,30 +317,31 @@ hdr.endListsOff = genoFindWriteEndLists(gf, f); // rewrite header with offsets off_t endOff = mustSeekAligned(f); mustSeek(f, hdrOff, SEEK_SET); mustWrite(f, &hdr, sizeof(hdr)); mustSeek(f, endOff, SEEK_SET); return hdrOff; } static struct genoFind *genoFindLoad(FILE* f ,void *memMapped, off_t off) /* construct one genoFind from mapped file */ { struct genoFind *gf; AllocVar(gf); +gf->isMapped = TRUE; struct genoFindFileHdr *hdr = memMapped + off; genoFindReadHdr(hdr, gf); genoFindReadSources(f, hdr->sourcesOff, gf); genoFindMapListSize(memMapped, hdr->listSizesOff, gf); if (gf->segSize == 0) genoFindMapLists(memMapped, hdr->listsOff, gf); else genoFindMapEndLists(memMapped, hdr->endListsOff, gf); return gf; } static struct genoFindIndex* genoFindIndexNew(boolean isTrans) /* construct an empty genoFindIndex */ @@ -471,30 +475,53 @@ if (madvise(gfIdx->memMapped, gfIdx->memLength, MADV_RANDOM | MADV_WILLNEED) < 0) errnoAbort("madvise of index file failed: %s", fileName); struct genoFindIndexFileHdr hdr; genoFindIndexReadHeader(gfIdx->memMapped, &hdr, gfIdx); if (isTrans) genoFindIndexMapTrans(f, gfIdx->memMapped, &hdr, gfIdx); else gfIdx->untransGf = genoFindLoad(f, gfIdx->memMapped, hdr.untransOff); carefulClose(&f); return gfIdx; } +void genoFindIndexFree(struct genoFindIndex **pGfIdx) +/* free a genoFindIndex */ +{ +struct genoFindIndex *gfIdx = *pGfIdx; +if (gfIdx != NULL) + { + if (gfIdx->untransGf != NULL) + genoFindFree(&gfIdx->untransGf); + else + { + for (int i = 0; i < 2; i++) + for (int j = 0; j < 3; j++) + genoFindFree(&gfIdx->transGf[i][j]); + } + if (gfIdx->memMapped != NULL) + { + if (munmap(gfIdx->memMapped, gfIdx->memLength)) + errnoAbort("munmap error"); + } + freez(pGfIdx); + } +} + int gfPowerOf20(int n) /* Return a 20 to the n */ { int res = 20; while (--n > 0) res *= 20; return res; } void gfCheckTileSize(int tileSize, boolean isPep) /* Check that tile size is legal. Abort if not. */ { if (isPep) { if (tileSize < 3 || tileSize > 8)