Class JobPromise¶
Defined in File job.h
Nested Relationships¶
Nested Types¶
Inheritance Relationships¶
Derived Types¶
public portal::ResultPromise< Result >(Template Class ResultPromise)public portal::ResultPromise< void >(Template Class ResultPromise< void >)
Class Documentation¶
-
class JobPromise¶
Promise type for the C++20 coroutine protocol used by Job<T>.
JobPromise manages the coroutine’s state, result storage, and integration with the work-stealing scheduler. It implements the promise_type concept required for C++20 coroutines, handling suspension, resumption, result storage, and scheduler integration.
See also
ResultPromise for typed promise implementation
See also
Job for the coroutine type using this promise
Subclassed by portal::ResultPromise< Result >, portal::ResultPromise< void >
Public Functions
-
JobPromise()¶
-
inline std::suspend_always initial_suspend() noexcept¶
-
inline FinalizeJob final_suspend() noexcept¶
-
void unhandled_exception() noexcept¶
-
template<typename Result>
inline std::expected<Result, JobResultStatus> get_result()¶ Retrieve the job’s result value.
- Template Parameters:
Result – The return type of the job
- Returns:
Expected containing result or JobResultStatus::Missing if incomplete
-
void add_switch_information(SwitchType type)¶
Record a state transition for profiling.
- Parameters:
type – The type of state transition (Start, Resume, Pause, etc.)
-
template<typename Result>
inline void initialize_result()¶ Allocate and default-construct result storage.
- Template Parameters:
Result – The return type to allocate storage for
-
template<typename Result>
inline void destroy_result()¶ Destroy result storage and deallocate memory.
- Template Parameters:
Result – The return type to destroy
-
void *operator new(size_t n) noexcept¶
-
void operator delete(void *ptr) noexcept¶
-
void set_scheduler(jobs::Scheduler *scheduler_ptr) noexcept¶
Set the scheduler for this job.
- Parameters:
scheduler_ptr – Pointer to the owning scheduler
-
void set_counter(jobs::Counter *counter_ptr) noexcept¶
Set the counter to decrement on completion.
- Parameters:
counter_ptr – Pointer to the synchronization counter
-
void set_continuation(std::coroutine_handle<> caller) noexcept¶
Set the coroutine to resume after this job completes.
- Parameters:
caller – Handle to the continuation coroutine
-
inline std::coroutine_handle get_continuation() const noexcept¶
-
inline bool is_completed() const noexcept¶
-
inline auto operator co_await() noexcept¶
Public Static Functions
-
static size_t get_allocated_size() noexcept¶
Protected Attributes
-
std::coroutine_handle continuation¶
-
void *result = nullptr¶
-
bool completed = false¶
-
llvm::SmallVector<SwitchInformation> switch_information¶
Protected Static Functions
-
static void *allocate_result(size_t size) noexcept¶
-
static void deallocate_result(void *ptr, size_t size) noexcept¶
-
class JobAwaiter¶
Awaiter for suspending parent job until child job completes.
When a Job is co_awaited (e.g.,
co_await child_job()), this awaiter:Checks if child is already complete (await_ready)
Sets parent as continuation and dispatches child (await_suspend)
Returns child’s result when resumed (await_resume)
Public Functions
-
inline explicit JobAwaiter(const std::coroutine_handle<JobPromise> handle)¶
Construct awaiter for a job.
- Parameters:
handle – Handle to the job being awaited
-
bool await_ready() noexcept¶
Check if job is already complete (optimization to skip suspension).
- Returns:
true if job already finished, false if must suspend
-
std::coroutine_handle<JobPromise> await_suspend(std::coroutine_handle<> caller) noexcept¶
Suspend calling job and establish parent-child relationship.
- Parameters:
caller – The parent job’s coroutine handle
- Returns:
Handle to resume next (the child job to execute)
-
template<typename T = void>
inline void await_resume() noexcept¶
-
template<typename T>
inline std::expected<T, JobResultStatus> await_resume() noexcept¶
-
JobPromise()¶