/** * Called when a thread is about to be launched. * Increments liveJobs. */ public static void COVER_best_start(COVER_best_s *best) { if (best == null) { return; } ++best->liveJobs; }
/** * Wait until liveJobs == 0. */ public static void COVER_best_wait(COVER_best_s *best) { if (best == null) { return; } while (best->liveJobs != 0) { } }
/** * Called when a thread finishes executing, both on error or success. * Decrements liveJobs and signals any waiting threads if liveJobs == 0. * If this dictionary is the best so far save it and its parameters. */ public static void COVER_best_finish(COVER_best_s *best, ZDICT_cover_params_t parameters, COVER_dictSelection selection) { void *dict = (void *)selection.dictContent; nuint compressedSize = selection.totalCompressedSize; nuint dictSize = selection.dictSize; if (best == null) { return; } { nuint liveJobs; --best->liveJobs; liveJobs = best->liveJobs; if (compressedSize < best->compressedSize) { if (best->dict == null || best->dictSize < dictSize) { if (best->dict != null) { free(best->dict); } best->dict = malloc(dictSize); if (best->dict == null) { best->compressedSize = (unchecked ((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_GENERIC))); best->dictSize = 0; return; } } if (dict != null) { memcpy(best->dict, dict, dictSize); best->dictSize = dictSize; best->parameters = parameters; best->compressedSize = compressedSize; } } if (liveJobs == 0) { } } }
/** * Call COVER_best_wait() and then destroy the COVER_best_t. */ public static void COVER_best_destroy(COVER_best_s *best) { if (best == null) { return; } COVER_best_wait(best); if (best->dict != null) { free(best->dict); } }
/** * Initialize the `COVER_best_t`. */ public static void COVER_best_init(COVER_best_s *best) { if (best == null) { return; } best->liveJobs = 0; best->dict = null; best->dictSize = 0; best->compressedSize = unchecked ((nuint)(-1)); memset((void *)&best->parameters, 0, (nuint)(sizeof(ZDICT_cover_params_t))); }