Skip to content

Commit

Permalink
Add more get_return_address customizations
Browse files Browse the repository at this point in the history
This PR continues what was started in #635 and adds more customizations
of `get_return_address`, starting with `task<>`.
  • Loading branch information
ispeters committed Sep 11, 2024
1 parent c93740d commit 70cb3df
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions include/unifex/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,11 @@ struct _promise final {
, _return_value_or_void<T, nothrow>::type {
using result_type = T;

typename _task<T, nothrow>::type get_return_object() noexcept {
typename _task<T, nothrow>::type get_return_object(
instruction_ptr returnAddress =
instruction_ptr::read_return_address()) noexcept {
return typename _task<T, nothrow>::type{
coro::coroutine_handle<type>::from_promise(*this)};
coro::coroutine_handle<type>::from_promise(*this), returnAddress};
}

auto final_suspend() noexcept {
Expand Down Expand Up @@ -750,8 +752,11 @@ struct _task<T, nothrow>::type
}

private:
explicit type(coro::coroutine_handle<promise_type> h) noexcept
: coro_holder(h) {}
explicit type(
coro::coroutine_handle<promise_type> h,
instruction_ptr returnAddress) noexcept
: coro_holder(h)
, returnAddress_(returnAddress) {}

template <typename Promise>
friend auto
Expand Down Expand Up @@ -789,6 +794,13 @@ struct _task<T, nothrow>::type
tag_t<with_scheduler_affinity>, type&& task, Scheduler&&) noexcept {
return {std::move(task)};
}

friend instruction_ptr
tag_invoke(tag_t<get_return_address>, const type& task) noexcept {
return returnAddress_;
}

instruction_ptr returnAddress_;
};

/**
Expand Down

0 comments on commit 70cb3df

Please sign in to comment.