LIBJXL: jxl/parallel_runner.h Source File

LIBJXL

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