@return : 0 on success, 1 on error */
| 7167 | |
| 7168 | /* @return : 0 on success, 1 on error */ |
| 7169 | static 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 */ |
| 7198 | int POOL_resize(POOL_ctx* ctx, size_t numThreads) |
no test coverage detected