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