main_thread.h
| File Path | engine/include/conjure/core/jobs/main_thread.h |
| API ↗ | Jobs and threading |
The main thread and its task queue. Worker threads and dedicated threads post work that must run on the main thread (window, GPU submission, editor state); the engine drains the queue once per frame before FRAME_BEGIN.
Functions
Public
jobs::drain_main_thread_queue
jobs::drain_main_thread_queueCONJURE_API usize drain_main_thread_queue();Runs every task queued so far, once, in posting order, and returns how many ran. Tasks posted while draining run on the next drain. Called off the designated main thread (or before one is designated) it asserts, runs nothing, leaves the tasks queued and returns 0; it never claims the main-thread designation for the caller.
jobs::is_main_thread
jobs::is_main_thread[[nodiscard]] CONJURE_API bool is_main_thread() noexcept;True on the main thread: the thread that first called set_main_thread() or constructed the first job_system. When neither has happened, the first thread to ask becomes the main thread.
jobs::main_thread_id
jobs::main_thread_id[[nodiscard]] CONJURE_API std::thread::id main_thread_id() noexcept;Identifier of the designated main thread, or a default-constructed id when none is set. Does not claim the calling thread.
jobs::main_thread_queue_size
jobs::main_thread_queue_size[[nodiscard]] CONJURE_API usize main_thread_queue_size();Number of tasks waiting for the next drain.
jobs::post_to_main_thread
jobs::post_to_main_threadCONJURE_API void post_to_main_thread(std::function<void()> task);Queues a task for the next drain_main_thread_queue(). Thread-safe. Empty tasks assert and are dropped.
jobs::reset_main_thread
jobs::reset_main_threadCONJURE_API void reset_main_thread() noexcept;Forgets the designation so the next set_main_thread() / is_main_thread() claims it again. Intended for tests and for restarting the engine inside one process.