LIBJXL
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 #if defined(__cplusplus) || defined(c_plusplus)
44 extern "C" {
45 #endif
46 
52 typedef int JxlParallelRetCode;
53 
58 #define JXL_PARALLEL_RET_RUNNER_ERROR (-1)
59 
77 typedef JxlParallelRetCode (*JxlParallelRunInit)(void* jpegxl_opaque,
78  size_t num_threads);
79 
95 typedef void (*JxlParallelRunFunction)(void* jpegxl_opaque, uint32_t value,
96  size_t thread_id);
97 
120  void* runner_opaque, void* jpegxl_opaque, JxlParallelRunInit init,
121  JxlParallelRunFunction func, uint32_t start_range, uint32_t end_range);
122 
123 /* The following is an example of a JxlParallelRunner that doesn't use any
124  * multi-threading. Note that this implementation doesn't store any state
125  * between multiple calls of the ExampleSequentialRunner function, so the
126  * runner_opaque value is not used.
127 
128  JxlParallelRetCode ExampleSequentialRunner(void* runner_opaque,
129  void* jpegxl_opaque,
130  JxlParallelRunInit init,
131  JxlParallelRunFunction func,
132  uint32_t start_range,
133  uint32_t end_range) {
134  // We only use one thread (the currently running thread).
135  JxlParallelRetCode init_ret = (*init)(jpegxl_opaque, 1);
136  if (init_ret != 0) return init_ret;
137 
138  // In case of other initialization error (for example when initializing the
139  // threads) one can return JXL_PARALLEL_RET_RUNNER_ERROR.
140 
141  for (uint32_t i = start_range; i < end_range; i++) {
142  // Every call is in the thread number 0. These don't need to be in any
143  // order.
144  (*func)(jpegxl_opaque, i, 0);
145  }
146  return 0;
147  }
148  */
149 
150 #if defined(__cplusplus) || defined(c_plusplus)
151 }
152 #endif
153 
154 #endif /* JXL_PARALLEL_RUNNER_H_ */
155 
void(* JxlParallelRunFunction)(void *jpegxl_opaque, uint32_t value, size_t thread_id)
Definition: parallel_runner.h:95
JxlParallelRetCode(* JxlParallelRunInit)(void *jpegxl_opaque, size_t num_threads)
Definition: parallel_runner.h:77
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:119