// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.
#include"lib/jxl/base/compiler_specific.h" #include"lib/jxl/base/status.h" #if JXL_COMPILER_MSVC // suppress warnings about the const & applied to function types #pragma warning(disable : 4180) #endif
// Runs init_func(num_threads) followed by data_func(task, thread) on worker // thread(s) for every task in [begin, end). init_func() must return a Status // indicating whether the initialization succeeded. // "thread" is an integer smaller than num_threads. // Not thread-safe - no two calls to Run may overlap. // Subsequent calls will reuse the same threads. // // Precondition: begin <= end. template <class InitFunc, class DataFunc>
Status Run(uint32_t begin, uint32_t end, const InitFunc& init_func, const DataFunc& data_func, constchar* caller) {
JXL_ENSURE(begin <= end); if (begin == end) returntrue;
RunCallState<InitFunc, DataFunc> call_state(init_func, data_func); // The runner_ uses the C convention and returns 0 in case of error, so we // convert it to a Status. if (!runner_) { void* jpegxl_opaque = static_cast<void*>(&call_state); if (call_state.CallInitFunc(jpegxl_opaque, 1) !=
JXL_PARALLEL_RET_SUCCESS) { return JXL_FAILURE("Failed to initialize thread");
} for (uint32_t i = begin; i < end; i++) {
call_state.CallDataFunc(jpegxl_opaque, i, 0);
} if (call_state.HasError()) { return JXL_FAILURE("[%s] failed", caller);
} returntrue;
}
JxlParallelRetCode ret = (*runner_)(
runner_opaque_, static_cast<void*>(&call_state),
&call_state.CallInitFunc, &call_state.CallDataFunc, begin, end);
// Use this as init_func when no initialization is needed. static Status NoInit(size_t num_threads) { returntrue; }
private: // class holding the state of a Run() call to pass to the runner_ as an // opaque_jpegxl pointer. template <class InitFunc, class DataFunc> class RunCallState final { public:
RunCallState(const InitFunc& init_func, const DataFunc& data_func)
: init_func_(init_func), data_func_(data_func) {}
// JxlParallelRunInit interface. staticint CallInitFunc(void* jpegxl_opaque, size_t num_threads) { auto* self = static_cast<RunCallState<InitFunc, DataFunc>*>(jpegxl_opaque); // Returns -1 when the internal init function returns false Status to // indicate an error. if (!self->init_func_(num_threads)) {
self->has_error_ = true; return JXL_PARALLEL_RET_RUNNER_ERROR;
} return JXL_PARALLEL_RET_SUCCESS;
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.28Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.