resizable_parallel_runner.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Copyright (c) the JPEG XL Project Authors. All rights reserved.
  2. *
  3. * Use of this source code is governed by a BSD-style
  4. * license that can be found in the LICENSE file.
  5. */
  6. /** @addtogroup libjxl_threads
  7. * @{
  8. * @file resizable_parallel_runner.h
  9. * @brief implementation using std::thread of a resizeable ::JxlParallelRunner.
  10. */
  11. /** Implementation of JxlParallelRunner than can be used to enable
  12. * multithreading when using the JPEG XL library. This uses std::thread
  13. * internally and related synchronization functions. The number of threads
  14. * created can be changed after creation of the thread pool; the threads
  15. * (including the main thread) are re-used for every
  16. * ResizableParallelRunner::Runner call. Only one concurrent
  17. * @ref JxlResizableParallelRunner call per instance is allowed at a time.
  18. *
  19. * This is a scalable, lower-overhead thread pool runner, especially suitable
  20. * for data-parallel computations in the fork-join model, where clients need to
  21. * know when all tasks have completed.
  22. *
  23. * Compared to the implementation in @ref thread_parallel_runner.h, this
  24. * implementation is tuned for execution on lower-powered systems, including
  25. * for example ARM CPUs with big.LITTLE computation models.
  26. */
  27. #ifndef JXL_RESIZABLE_PARALLEL_RUNNER_H_
  28. #define JXL_RESIZABLE_PARALLEL_RUNNER_H_
  29. #include <jxl/jxl_threads_export.h>
  30. #include <jxl/memory_manager.h>
  31. #include <jxl/parallel_runner.h>
  32. #include <stddef.h>
  33. #include <stdint.h>
  34. #include <stdlib.h>
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /** Parallel runner internally using std::thread. Use as @ref JxlParallelRunner.
  39. */
  40. JXL_THREADS_EXPORT JxlParallelRetCode JxlResizableParallelRunner(
  41. void* runner_opaque, void* jpegxl_opaque, JxlParallelRunInit init,
  42. JxlParallelRunFunction func, uint32_t start_range, uint32_t end_range);
  43. /** Creates the runner for @ref JxlResizableParallelRunner. Use as the opaque
  44. * runner. The runner will execute tasks on the calling thread until
  45. * @ref JxlResizableParallelRunnerSetThreads is called.
  46. */
  47. JXL_THREADS_EXPORT void* JxlResizableParallelRunnerCreate(
  48. const JxlMemoryManager* memory_manager);
  49. /** Changes the number of threads for @ref JxlResizableParallelRunner.
  50. */
  51. JXL_THREADS_EXPORT void JxlResizableParallelRunnerSetThreads(
  52. void* runner_opaque, size_t num_threads);
  53. /** Suggests a number of threads to use for an image of given size.
  54. */
  55. JXL_THREADS_EXPORT uint32_t
  56. JxlResizableParallelRunnerSuggestThreads(uint64_t xsize, uint64_t ysize);
  57. /** Destroys the runner created by @ref JxlResizableParallelRunnerCreate.
  58. */
  59. JXL_THREADS_EXPORT void JxlResizableParallelRunnerDestroy(void* runner_opaque);
  60. #ifdef __cplusplus
  61. }
  62. #endif
  63. #endif /* JXL_RESIZABLE_PARALLEL_RUNNER_H_ */
  64. /** @}*/