Blender V5.0
GPU_worker.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include "BLI_vector.hh"
8#include "GPU_context.hh"
9
10#include <atomic>
11#include <condition_variable>
12#include <functional>
13#include <memory>
14#include <mutex>
15#include <thread>
16
17namespace blender::gpu {
18
24class GPUWorker {
25 private:
27 std::condition_variable condition_var_;
28 std::mutex &mutex_;
29 bool terminate_ = false;
30
31 public:
32 enum class ContextType {
37 };
38
51 GPUWorker(uint32_t threads_count,
52 ContextType context_type,
53 std::mutex &mutex,
54 std::function<void *()> pop_work,
55 std::function<void(void *)> do_work);
56 ~GPUWorker();
57
58 /* Wake up a single thread. */
59 void wake_up()
60 {
61 condition_var_.notify_one();
62 }
63
64 private:
65 void run(std::shared_ptr<GPUSecondaryContext> context,
66 std::function<void *()> pop_work,
67 std::function<void(void *)> do_work);
68};
69
70} // namespace blender::gpu
GPUWorker(uint32_t threads_count, ContextType context_type, std::mutex &mutex, std::function< void *()> pop_work, std::function< void(void *)> do_work)
Definition gpu_worker.cc:9
ThreadMutex mutex