Example #1
0
ZSTDMT_CCtx *ZSTDMT_createCCtx(unsigned nbThreads)
{
    ZSTDMT_CCtx* cctx;
    U32 const minNbJobs = nbThreads + 2;
    U32 const nbJobsLog2 = ZSTD_highbit32(minNbJobs) + 1;
    U32 const nbJobs = 1 << nbJobsLog2;
    DEBUGLOG(5, "nbThreads : %u  ; minNbJobs : %u ;  nbJobsLog2 : %u ;  nbJobs : %u  \n",
            nbThreads, minNbJobs, nbJobsLog2, nbJobs);
    if ((nbThreads < 1) | (nbThreads > ZSTDMT_NBTHREADS_MAX)) return NULL;
    cctx = (ZSTDMT_CCtx*) calloc(1, sizeof(ZSTDMT_CCtx) + nbJobs*sizeof(ZSTDMT_jobDescription));
    if (!cctx) return NULL;
    cctx->nbThreads = nbThreads;
    cctx->jobIDMask = nbJobs - 1;
    cctx->allJobsCompleted = 1;
    cctx->sectionSize = 0;
    cctx->overlapRLog = 3;
    cctx->factory = POOL_create(nbThreads, 1);
    cctx->buffPool = ZSTDMT_createBufferPool(nbThreads);
    cctx->cctxPool = ZSTDMT_createCCtxPool(nbThreads);
    if (!cctx->factory | !cctx->buffPool | !cctx->cctxPool) {  /* one object was not created */
        ZSTDMT_freeCCtx(cctx);
        return NULL;
    }
    if (nbThreads==1) {
        cctx->cstream = ZSTD_createCStream();
        if (!cctx->cstream) {
            ZSTDMT_freeCCtx(cctx); return NULL;
    }   }
    pthread_mutex_init(&cctx->jobCompleted_mutex, NULL);   /* Todo : check init function return */
    pthread_cond_init(&cctx->jobCompleted_cond, NULL);
    DEBUGLOG(4, "mt_cctx created, for %u threads \n", nbThreads);
    return cctx;
}
Example #2
0
CEncoder::~CEncoder()
{
  if (_ctx)
    ZSTDMT_freeCCtx(_ctx);
}