#else /* ZSTD_PTHREAD not defined */
/* No multithreading support */
-typedef int pthread_mutex_t;
+#define pthread_mutex_t int /* #define rather than typedef, as sometimes pthread support is implicit, resulting in duplicated symbols */
#define pthread_mutex_init(a,b)
#define pthread_mutex_destroy(a)
#define pthread_mutex_lock(a)
#define pthread_mutex_unlock(a)
-typedef int pthread_cond_t;
+#define pthread_cond_t int
#define pthread_cond_init(a,b)
#define pthread_cond_destroy(a)
#define pthread_cond_wait(a,b)
static buffer_t ZSTDMT_getBuffer(ZSTDMT_bufferPool* pool, size_t bSize)
{
if (pool->nbBuffers) { /* try to use an existing buffer */
- pool->nbBuffers--;
- buffer_t const buf = pool->bTable[pool->nbBuffers];
+ buffer_t const buf = pool->bTable[--(pool->nbBuffers)];
size_t const availBufferSize = buf.size;
if ((availBufferSize >= bSize) & (availBufferSize <= 10*bSize)) /* large enough, but not too much */
return buf;
free(buf.start); /* size conditions not respected : create a new buffer */
}
/* create new buffer */
- buffer_t buf;
- buf.size = bSize;
- buf.start = malloc(bSize);
- return buf;
+ { buffer_t buf;
+ buf.size = bSize;
+ buf.start = malloc(bSize);
+ return buf;
+ }
}
/* effectively store buffer for later re-use, up to pool capacity */
/* ZSTDMT_compressFrame() : POOL_function type */
void ZSTDMT_compressFrame(void* jobDescription)
{
- DEBUGLOG(5, "Entering ZSTDMT_compressFrame() ");
ZSTDMT_jobDescription* const job = (ZSTDMT_jobDescription*)jobDescription;
- DEBUGLOG(5, "compressing %u bytes from frame %u with ZSTD_compressCCtx : ", (unsigned)job->srcSize, job->jobCompleted);
+ DEBUGLOG(5, "thread : compressing %u bytes from frame %u with ZSTD_compressCCtx : ", (unsigned)job->srcSize, job->jobCompleted);
job->cSize = ZSTD_compressCCtx(job->cctx, job->dstBuff.start, job->dstBuff.size, job->srcStart, job->srcSize, job->compressionLevel);
DEBUGLOG(5, "compressed to %u bytes ", (unsigned)job->cSize);
DEBUGLOG(5, "sending jobCompleted signal");
ZSTDMT_CCtx *ZSTDMT_createCCtx(unsigned nbThreads)
{
+ ZSTDMT_CCtx* cctx;
if ((nbThreads < 1) | (nbThreads > ZSTDMT_NBTHREADS_MAX)) return NULL;
- ZSTDMT_CCtx* const cctx = (ZSTDMT_CCtx*) calloc(1, sizeof(ZSTDMT_CCtx) + nbThreads*sizeof(ZSTDMT_jobDescription));
+ cctx = (ZSTDMT_CCtx*) calloc(1, sizeof(ZSTDMT_CCtx) + nbThreads*sizeof(ZSTDMT_jobDescription));
if (!cctx) return NULL;
cctx->nbThreads = nbThreads;
cctx->factory = POOL_create(nbThreads, 1);
static clock_t _ticksPerSecond = 0;
if (_ticksPerSecond <= 0) _ticksPerSecond = sysconf(_SC_CLK_TCK);
- struct tms junk; clock_t newTicks = (clock_t) times(&junk); (void)junk;
- return ((((clock_us_t)newTicks)*(1000000))/_ticksPerSecond);
+ { struct tms junk; clock_t newTicks = (clock_t) times(&junk); (void)junk;
+ return ((((clock_us_t)newTicks)*(1000000))/_ticksPerSecond); }
}