LIBJXL_DOC
parallel_runner.h
Go to the documentation of this file.
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 
37 #ifndef JXL_PARALLEL_RUNNER_H_
38 #define JXL_PARALLEL_RUNNER_H_
39 
40 #include <stddef.h>
41 #include <stdint.h>
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
52 typedef int JxlParallelRetCode;
53 
57 #define JXL_PARALLEL_RET_SUCCESS (0)
58 
63 #define JXL_PARALLEL_RET_RUNNER_ERROR (-1)
64 
83 typedef JxlParallelRetCode (*JxlParallelRunInit)(void* jpegxl_opaque,
84  size_t num_threads);
85 
102 typedef void (*JxlParallelRunFunction)(void* jpegxl_opaque, uint32_t value,
103  size_t thread_id);
104 
128  void* runner_opaque, void* jpegxl_opaque, JxlParallelRunInit init,
129  JxlParallelRunFunction func, uint32_t start_range, uint32_t end_range);
130 
131 /* The following is an example of a @ref JxlParallelRunner that doesn't use any
132  * multi-threading. Note that this implementation doesn't store any state
133  * between multiple calls of the ExampleSequentialRunner function, so the
134  * runner_opaque value is not used.
135 
136  JxlParallelRetCode ExampleSequentialRunner(void* runner_opaque,
137  void* jpegxl_opaque,
138  JxlParallelRunInit init,
139  JxlParallelRunFunction func,
140  uint32_t start_range,
141  uint32_t end_range) {
142  // We only use one thread (the currently running thread).
143  JxlParallelRetCode init_ret = (*init)(jpegxl_opaque, 1);
144  if (init_ret != 0) return init_ret;
145 
146  // In case of other initialization error (for example when initializing the
147  // threads) one can return JXL_PARALLEL_RET_RUNNER_ERROR.
148 
149  for (uint32_t i = start_range; i < end_range; i++) {
150  // Every call is in the thread number 0. These don't need to be in any
151  // order.
152  (*func)(jpegxl_opaque, i, 0);
153  }
154  return JXL_PARALLEL_RET_SUCCESS;
155  }
156  */
157 
158 #ifdef __cplusplus
159 }
160 #endif
161 
162 #endif /* JXL_PARALLEL_RUNNER_H_ */
163 
JxlParallelRetCode(* JxlParallelRunInit)(void *jpegxl_opaque, size_t num_threads)
Definition: parallel_runner.h:83
int JxlParallelRetCode
Definition: parallel_runner.h:52
JxlParallelRetCode(* JxlParallelRunner)(void *runner_opaque, void *jpegxl_opaque, JxlParallelRunInit init, JxlParallelRunFunction func, uint32_t start_range, uint32_t end_range)
Definition: parallel_runner.h:127
void(* JxlParallelRunFunction)(void *jpegxl_opaque, uint32_t value, size_t thread_id)
Definition: parallel_runner.h:102