Skip to content

Engine → Core

main_thread.h

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

CONJURE_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

[[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

[[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

[[nodiscard]] CONJURE_API usize main_thread_queue_size();

Number of tasks waiting for the next drain.

jobs::post_to_main_thread

CONJURE_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

CONJURE_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.

jobs::set_main_thread

CONJURE_API void set_main_thread() noexcept;

Designates the calling thread as the main thread. The engine calls this at startup; tests call it before using the main-thread queue.