MCPcopy Create free account
hub / github.com/F-Stack/f-stack / POOL_resize_internal

Function POOL_resize_internal

freebsd/contrib/openzfs/module/zstd/lib/zstd.c:7169–7195  ·  view source on GitHub ↗

@return : 0 on success, 1 on error */

Source from the content-addressed store, hash-verified

7167
7168/* @return : 0 on success, 1 on error */
7169static int POOL_resize_internal(POOL_ctx* ctx, size_t numThreads)
7170{
7171 if (numThreads <= ctx->threadCapacity) {
7172 if (!numThreads) return 1;
7173 ctx->threadLimit = numThreads;
7174 return 0;
7175 }
7176 /* numThreads > threadCapacity */
7177 { ZSTD_pthread_t* const threadPool = (ZSTD_pthread_t*)ZSTD_malloc(numThreads * sizeof(ZSTD_pthread_t), ctx->customMem);
7178 if (!threadPool) return 1;
7179 /* replace existing thread pool */
7180 memcpy(threadPool, ctx->threads, ctx->threadCapacity * sizeof(*threadPool));
7181 ZSTD_free(ctx->threads, ctx->customMem);
7182 ctx->threads = threadPool;
7183 /* Initialize additional threads */
7184 { size_t threadId;
7185 for (threadId = ctx->threadCapacity; threadId < numThreads; ++threadId) {
7186 if (ZSTD_pthread_create(&threadPool[threadId], NULL, &POOL_thread, ctx)) {
7187 ctx->threadCapacity = threadId;
7188 return 1;
7189 } }
7190 } }
7191 /* successfully expanded */
7192 ctx->threadCapacity = numThreads;
7193 ctx->threadLimit = numThreads;
7194 return 0;
7195}
7196
7197/* @return : 0 on success, 1 on error */
7198int POOL_resize(POOL_ctx* ctx, size_t numThreads)

Callers 1

POOL_resizeFunction · 0.70

Calls 4

ZSTD_mallocFunction · 0.85
ZSTD_freeFunction · 0.85
ZSTD_pthread_createFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected