zstdmt_compress.h 4.6 KB

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