CCtxPool starts empty, as suggested by @terrelln
Also : make zstdmt now a target from root
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
# Executables
|
# Executables
|
||||||
zstd
|
zstd
|
||||||
|
zstdmt
|
||||||
*.exe
|
*.exe
|
||||||
*.out
|
*.out
|
||||||
*.app
|
*.app
|
||||||
|
|||||||
@@ -50,6 +50,11 @@ zstd:
|
|||||||
@$(MAKE) -C $(PRGDIR) $@
|
@$(MAKE) -C $(PRGDIR) $@
|
||||||
cp $(PRGDIR)/zstd$(EXT) .
|
cp $(PRGDIR)/zstd$(EXT) .
|
||||||
|
|
||||||
|
.PHONY: zstdmt
|
||||||
|
zstdmt:
|
||||||
|
@$(MAKE) -C $(PRGDIR) $@
|
||||||
|
cp $(PRGDIR)/zstd$(EXT) ./zstdmt$(EXT)
|
||||||
|
|
||||||
.PHONY: zlibwrapper
|
.PHONY: zlibwrapper
|
||||||
zlibwrapper:
|
zlibwrapper:
|
||||||
$(MAKE) -C $(ZWRAPDIR) test
|
$(MAKE) -C $(ZWRAPDIR) test
|
||||||
|
|||||||
@@ -122,8 +122,8 @@ typedef struct {
|
|||||||
static void ZSTDMT_freeCCtxPool(ZSTDMT_CCtxPool* pool)
|
static void ZSTDMT_freeCCtxPool(ZSTDMT_CCtxPool* pool)
|
||||||
{
|
{
|
||||||
unsigned u;
|
unsigned u;
|
||||||
for (u=0; u<pool->availCCtx; u++) /* note : availCCtx is supposed == totalCCtx; otherwise, some CCtx are still in use */
|
for (u=0; u<pool->totalCCtx; u++)
|
||||||
ZSTD_freeCCtx(pool->cctx[u]);
|
ZSTD_freeCCtx(pool->cctx[u]); /* note : compatible with free on NULL */
|
||||||
free(pool);
|
free(pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,15 +131,8 @@ static ZSTDMT_CCtxPool* ZSTDMT_createCCtxPool(unsigned nbThreads)
|
|||||||
{
|
{
|
||||||
ZSTDMT_CCtxPool* const cctxPool = (ZSTDMT_CCtxPool*) calloc(1, sizeof(ZSTDMT_CCtxPool) + nbThreads*sizeof(ZSTD_CCtx*));
|
ZSTDMT_CCtxPool* const cctxPool = (ZSTDMT_CCtxPool*) calloc(1, sizeof(ZSTDMT_CCtxPool) + nbThreads*sizeof(ZSTD_CCtx*));
|
||||||
if (!cctxPool) return NULL;
|
if (!cctxPool) return NULL;
|
||||||
{ unsigned threadNb;
|
cctxPool->totalCCtx = nbThreads;
|
||||||
for (threadNb=0; threadNb<nbThreads; threadNb++) {
|
cctxPool->availCCtx = 0;
|
||||||
cctxPool->cctx[threadNb] = ZSTD_createCCtx();
|
|
||||||
if (cctxPool->cctx[threadNb]==NULL) { /* failed cctx allocation : abort cctxPool creation */
|
|
||||||
cctxPool->totalCCtx = cctxPool->availCCtx = threadNb;
|
|
||||||
ZSTDMT_freeCCtxPool(cctxPool);
|
|
||||||
return NULL;
|
|
||||||
} } }
|
|
||||||
cctxPool->totalCCtx = cctxPool->availCCtx = nbThreads;
|
|
||||||
return cctxPool;
|
return cctxPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,17 +142,16 @@ static ZSTD_CCtx* ZSTDMT_getCCtx(ZSTDMT_CCtxPool* pool)
|
|||||||
pool->availCCtx--;
|
pool->availCCtx--;
|
||||||
return pool->cctx[pool->availCCtx];
|
return pool->cctx[pool->availCCtx];
|
||||||
}
|
}
|
||||||
/* note : should not be possible, since totalCCtx==nbThreads */
|
return ZSTD_createCCtx(); /* note : can be NULL, when creation fails ! */
|
||||||
return ZSTD_createCCtx(); /* note : can be NULL is creation fails ! */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ZSTDMT_releaseCCtx(ZSTDMT_CCtxPool* pool, ZSTD_CCtx* cctx)
|
static void ZSTDMT_releaseCCtx(ZSTDMT_CCtxPool* pool, ZSTD_CCtx* cctx)
|
||||||
{
|
{
|
||||||
if (cctx==NULL) return; /* release on NULL */
|
if (cctx==NULL) return; /* compatibility with release on NULL */
|
||||||
if (pool->availCCtx < pool->totalCCtx)
|
if (pool->availCCtx < pool->totalCCtx)
|
||||||
pool->cctx[pool->availCCtx++] = cctx;
|
pool->cctx[pool->availCCtx++] = cctx;
|
||||||
else
|
else
|
||||||
/* note : should not be possible, since totalCCtx==nbThreads */
|
/* pool overflow : should not happen, since totalCCtx==nbThreads */
|
||||||
ZSTD_freeCCtx(cctx);
|
ZSTD_freeCCtx(cctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user