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

Function POOL_resize_internal

freebsd/contrib/zstd/lib/common/pool.c:204–230  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

202
203/* @return : 0 on success, 1 on error */
204static int POOL_resize_internal(POOL_ctx* ctx, size_t numThreads)
205{
206 if (numThreads <= ctx->threadCapacity) {
207 if (!numThreads) return 1;
208 ctx->threadLimit = numThreads;
209 return 0;
210 }
211 /* numThreads > threadCapacity */
212 { ZSTD_pthread_t* const threadPool = (ZSTD_pthread_t*)ZSTD_customMalloc(numThreads * sizeof(ZSTD_pthread_t), ctx->customMem);
213 if (!threadPool) return 1;
214 /* replace existing thread pool */
215 ZSTD_memcpy(threadPool, ctx->threads, ctx->threadCapacity * sizeof(*threadPool));
216 ZSTD_customFree(ctx->threads, ctx->customMem);
217 ctx->threads = threadPool;
218 /* Initialize additional threads */
219 { size_t threadId;
220 for (threadId = ctx->threadCapacity; threadId < numThreads; ++threadId) {
221 if (ZSTD_pthread_create(&threadPool[threadId], NULL, &POOL_thread, ctx)) {
222 ctx->threadCapacity = threadId;
223 return 1;
224 } }
225 } }
226 /* successfully expanded */
227 ctx->threadCapacity = numThreads;
228 ctx->threadLimit = numThreads;
229 return 0;
230}
231
232/* @return : 0 on success, 1 on error */
233int POOL_resize(POOL_ctx* ctx, size_t numThreads)

Callers 1

POOL_resizeFunction · 0.70

Calls 3

ZSTD_customMallocFunction · 0.85
ZSTD_customFreeFunction · 0.85
ZSTD_pthread_createFunction · 0.85

Tested by

no test coverage detected