diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-09-29 01:39:30 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-09-30 00:19:53 +0200 |
| commit | 7482e2f584d2a9a8917171b9ed04ce4f21d2ea62 (patch) | |
| tree | 547db66195303f3c8e7e2a8558bf6a92818e4f6d /src/lib/j2k_encoder.h | |
| parent | 24fc7b5d990044c7e9f2c95ea82ce12f024b1bfc (diff) | |
fixup! wip: CUDA with nvjpeg2k
Diffstat (limited to 'src/lib/j2k_encoder.h')
| -rw-r--r-- | src/lib/j2k_encoder.h | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/lib/j2k_encoder.h b/src/lib/j2k_encoder.h index 5c8ad030d..14d5ad9c0 100644 --- a/src/lib/j2k_encoder.h +++ b/src/lib/j2k_encoder.h @@ -98,8 +98,27 @@ private: void frame_done (); void servers_list_changed (); - void remake_threads(int cpu, int gpu, std::list<EncodeServerDescription> servers); + void remake_threads(int cpu, int grok, int nvjpeg2k, std::list<EncodeServerDescription> servers); void terminate_threads (); + void remove_threads(int wanted, int current, std::function<bool (std::shared_ptr<J2KEncoderThread>)> predicate); + + template <class T, typename... Args> + void setup_threads(int target, Args&&... args) + { + auto const is_target_thread = [](std::shared_ptr<J2KEncoderThread> thread) { + return static_cast<bool>(std::dynamic_pointer_cast<T>(thread)); + }; + + auto const current_target_threads = std::count_if(_threads.begin(), _threads.end(), is_target_thread); + + for (auto i = current_target_threads; i < target; ++i) { + auto thread = std::make_shared<T>(*this, std::forward<Args>(args)...); + thread->start(); + _threads.push_back(thread); + } + + remove_threads(target, current_target_threads, is_target_thread); + } boost::mutex _threads_mutex; std::vector<std::shared_ptr<J2KEncoderThread>> _threads; |
