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
34#ifndef JXL_PARALLEL_RUNNER_H_
35#define JXL_PARALLEL_RUNNER_H_
36
37#include <stddef.h>
38#include <stdint.h>
39
40#if defined(__cplusplus) || defined(c_plusplus)
41 extern "C" {
42#endif
43
49 typedef int JxlParallelRetCode;
50
55#define JXL_PARALLEL_RET_RUNNER_ERROR (-1)
56
74 typedef JxlParallelRetCode (*JxlParallelRunInit)(void* jpegxl_opaque,
75 size_t num_threads);
76
92 typedef void (*JxlParallelRunFunction)(void* jpegxl_opaque, uint32_t value,
93 size_t thread_id);
94
116 typedef JxlParallelRetCode (*JxlParallelRunner)(
117 void* runner_opaque, void* jpegxl_opaque, JxlParallelRunInit init,
118 JxlParallelRunFunction func, uint32_t start_range, uint32_t end_range);
119
120/* The following is an example of a JxlParallelRunner that doesn't use any
121 * multi-threading. Note that this implementation doesn't store any state
122 * between multiple calls of the ExampleSequentialRunner function, so the
123 * runner_opaque value is not used.
124
125 JxlParallelRetCode ExampleSequentialRunner(void* runner_opaque,
126 void* jpegxl_opaque,
127 JxlParallelRunInit init,
128 JxlParallelRunFunction func,
129 uint32_t start_range,
130 uint32_t end_range) {
131 // We only use one thread (the currently running thread).
132 JxlParallelRetCode init_ret = (*init)(jpegxl_opaque, 1);
133 if (init_ret != 0) return init_ret;
134
135 // In case of other initialization error (for example when initializing the
136 // threads) one can return JXL_PARALLEL_RET_RUNNER_ERROR.
137
138 for (uint32_t i = start_range; i < end_range; i++) {
139 // Every call is in the thread number 0. These don't need to be in any
140 // order.
141 (*func)(jpegxl_opaque, i, 0);
142 }
143 return 0;
144 }
145 */
146
147#if defined(__cplusplus) || defined(c_plusplus)
148}
149#endif
150
151#endif /* JXL_PARALLEL_RUNNER_H_ */
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:116
JxlParallelRunInit
JxlParallelRetCode(* JxlParallelRunInit)(void *jpegxl_opaque, size_t num_threads)
Definition: parallel_runner.h:74
JxlParallelRetCode
int JxlParallelRetCode
Definition: parallel_runner.h:49
JxlParallelRunFunction
void(* JxlParallelRunFunction)(void *jpegxl_opaque, uint32_t value, size_t thread_id)
Definition: parallel_runner.h:92