libjxl

FORK: libjxl patches used on blog
git clone https://git.neptards.moe/blog/libjxl.git
Log | Files | Refs | Submodules | README | LICENSE

resizable_parallel_runner.h (2789B)


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