zstdmt_compress.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) Meta Platforms, Inc. and affiliates.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under both the BSD-style license (found in the
  6. * LICENSE file in the root directory of this source tree) and the GPLv2 (found
  7. * in the COPYING file in the root directory of this source tree).
  8. * You may select, at your option, one of the above-listed licenses.
  9. */
  10. #ifndef ZSTDMT_COMPRESS_H
  11. #define ZSTDMT_COMPRESS_H
  12. /* === Dependencies === */
  13. #include "../common/zstd_deps.h" /* size_t */
  14. #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters */
  15. #include "../zstd.h" /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTDLIB_API */
  16. /* Note : This is an internal API.
  17. * These APIs used to be exposed with ZSTDLIB_API,
  18. * because it used to be the only way to invoke MT compression.
  19. * Now, you must use ZSTD_compress2 and ZSTD_compressStream2() instead.
  20. *
  21. * This API requires ZSTD_MULTITHREAD to be defined during compilation,
  22. * otherwise ZSTDMT_createCCtx*() will fail.
  23. */
  24. /* === Constants === */
  25. #ifndef ZSTDMT_NBWORKERS_MAX /* a different value can be selected at compile time */
  26. # define ZSTDMT_NBWORKERS_MAX ((sizeof(void*)==4) /*32-bit*/ ? 64 : 256)
  27. #endif
  28. #ifndef ZSTDMT_JOBSIZE_MIN /* a different value can be selected at compile time */
  29. # define ZSTDMT_JOBSIZE_MIN (512 KB)
  30. #endif
  31. #define ZSTDMT_JOBLOG_MAX (MEM_32bits() ? 29 : 30)
  32. #define ZSTDMT_JOBSIZE_MAX (MEM_32bits() ? (512 MB) : (1024 MB))
  33. /* ========================================================
  34. * === Private interface, for use by ZSTD_compress.c ===
  35. * === Not exposed in libzstd. Never invoke directly ===
  36. * ======================================================== */
  37. /* === Memory management === */
  38. typedef struct ZSTDMT_CCtx_s ZSTDMT_CCtx;
  39. /* Requires ZSTD_MULTITHREAD to be defined during compilation, otherwise it will return NULL. */
  40. ZSTDMT_CCtx* ZSTDMT_createCCtx_advanced(unsigned nbWorkers,
  41. ZSTD_customMem cMem,
  42. ZSTD_threadPool *pool);
  43. size_t ZSTDMT_freeCCtx(ZSTDMT_CCtx* mtctx);
  44. size_t ZSTDMT_sizeof_CCtx(ZSTDMT_CCtx* mtctx);
  45. /* === Streaming functions === */
  46. size_t ZSTDMT_nextInputSizeHint(const ZSTDMT_CCtx* mtctx);
  47. /*! ZSTDMT_initCStream_internal() :
  48. * Private use only. Init streaming operation.
  49. * expects params to be valid.
  50. * must receive dict, or cdict, or none, but not both.
  51. * mtctx can be freshly constructed or reused from a prior compression.
  52. * If mtctx is reused, memory allocations from the prior compression may not be freed,
  53. * even if they are not needed for the current compression.
  54. * @return : 0, or an error code */
  55. size_t ZSTDMT_initCStream_internal(ZSTDMT_CCtx* mtctx,
  56. const void* dict, size_t dictSize, ZSTD_dictContentType_e dictContentType,
  57. const ZSTD_CDict* cdict,
  58. ZSTD_CCtx_params params, unsigned long long pledgedSrcSize);
  59. /*! ZSTDMT_compressStream_generic() :
  60. * Combines ZSTDMT_compressStream() with optional ZSTDMT_flushStream() or ZSTDMT_endStream()
  61. * depending on flush directive.
  62. * @return : minimum amount of data still to be flushed
  63. * 0 if fully flushed
  64. * or an error code
  65. * note : needs to be init using any ZSTD_initCStream*() variant */
  66. size_t ZSTDMT_compressStream_generic(ZSTDMT_CCtx* mtctx,
  67. ZSTD_outBuffer* output,
  68. ZSTD_inBuffer* input,
  69. ZSTD_EndDirective endOp);
  70. /*! ZSTDMT_toFlushNow()
  71. * Tell how many bytes are ready to be flushed immediately.
  72. * Probe the oldest active job (not yet entirely flushed) and check its output buffer.
  73. * If return 0, it means there is no active job,
  74. * or, it means oldest job is still active, but everything produced has been flushed so far,
  75. * therefore flushing is limited by speed of oldest job. */
  76. size_t ZSTDMT_toFlushNow(ZSTDMT_CCtx* mtctx);
  77. /*! ZSTDMT_updateCParams_whileCompressing() :
  78. * Updates only a selected set of compression parameters, to remain compatible with current frame.
  79. * New parameters will be applied to next compression job. */
  80. void ZSTDMT_updateCParams_whileCompressing(ZSTDMT_CCtx* mtctx, const ZSTD_CCtx_params* cctxParams);
  81. /*! ZSTDMT_getFrameProgression():
  82. * tells how much data has been consumed (input) and produced (output) for current frame.
  83. * able to count progression inside worker threads.
  84. */
  85. ZSTD_frameProgression ZSTDMT_getFrameProgression(ZSTDMT_CCtx* mtctx);
  86. #endif /* ZSTDMT_COMPRESS_H */