Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions strings/base_coroutine_foundation.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace winrt::impl
template<bool preserve_context, typename Awaiter>
struct disconnect_aware_handler : private std::conditional_t<preserve_context, resume_apartment_context, ignore_apartment_context>
{
disconnect_aware_handler(Awaiter* awaiter, coroutine_handle<> handle) noexcept
disconnect_aware_handler(Awaiter* awaiter, std::coroutine_handle<> handle) noexcept
: m_awaiter(awaiter), m_handle(handle) { }

disconnect_aware_handler(disconnect_aware_handler&& other) = default;
Expand All @@ -123,7 +123,7 @@ namespace winrt::impl

private:
movable_primitive<Awaiter*> m_awaiter;
movable_primitive<coroutine_handle<>, nullptr> m_handle;
movable_primitive<std::coroutine_handle<>, nullptr> m_handle;

void Complete()
{
Expand All @@ -149,7 +149,6 @@ namespace winrt::impl
}
};

#ifdef WINRT_IMPL_COROUTINES
template <typename Async, bool preserve_context = true>
struct await_adapter : cancellable_awaiter<await_adapter<Async, preserve_context>>
{
Expand All @@ -175,7 +174,7 @@ namespace winrt::impl
}

template <typename T>
bool await_suspend(coroutine_handle<T> handle)
bool await_suspend(std::coroutine_handle<T> handle)
{
this->set_cancellable_promise_from_handle(handle);
return register_completed_callback(handle);
Expand All @@ -189,7 +188,7 @@ namespace winrt::impl
}

private:
bool register_completed_callback(coroutine_handle<> handle)
bool register_completed_callback(std::coroutine_handle<> handle)
{
if constexpr (!preserve_context)
{
Expand All @@ -212,7 +211,6 @@ namespace winrt::impl
}
}
};
#endif

template <typename D>
auto consume_Windows_Foundation_IAsyncAction<D>::get() const
Expand Down Expand Up @@ -259,7 +257,6 @@ namespace winrt::impl
}
}

#ifdef WINRT_IMPL_COROUTINES
WINRT_EXPORT namespace winrt
{
template<typename Async, typename = std::enable_if_t<std::is_convertible_v<Async, winrt::Windows::Foundation::IAsyncInfo>>>
Expand Down Expand Up @@ -294,7 +291,6 @@ WINRT_EXPORT namespace winrt::Windows::Foundation
return{ async };
}
}
#endif

WINRT_EXPORT namespace winrt
{
Expand Down Expand Up @@ -327,7 +323,7 @@ namespace winrt::impl
return true;
}

void await_suspend(coroutine_handle<>) const noexcept
void await_suspend(std::coroutine_handle<>) const noexcept
{
}

Expand Down Expand Up @@ -373,7 +369,7 @@ namespace winrt::impl
return true;
}

void await_suspend(coroutine_handle<>) const noexcept
void await_suspend(std::coroutine_handle<>) const noexcept
{
}

Expand Down Expand Up @@ -411,7 +407,7 @@ namespace winrt::impl
if (remaining == 0)
{
std::atomic_thread_fence(std::memory_order_acquire);
coroutine_handle<Derived>::from_promise(*static_cast<Derived*>(this)).destroy();
std::coroutine_handle<Derived>::from_promise(*static_cast<Derived*>(this)).destroy();
}

return remaining;
Expand Down Expand Up @@ -577,7 +573,7 @@ namespace winrt::impl
}
}

suspend_never initial_suspend() const noexcept
std::suspend_never initial_suspend() const noexcept
{
return{};
}
Expand All @@ -595,7 +591,7 @@ namespace winrt::impl
{
}

bool await_suspend(coroutine_handle<>) const noexcept
bool await_suspend(std::coroutine_handle<>) const noexcept
{
promise->set_completed();
std::uint32_t const remaining = promise->subtract_reference();
Expand Down Expand Up @@ -705,11 +701,7 @@ namespace winrt::impl
};
}

#ifdef __cpp_lib_coroutine
namespace std
#else
namespace std::experimental
#endif
{
template <typename... Args>
struct coroutine_traits<winrt::Windows::Foundation::IAsyncAction, Args...>
Expand Down Expand Up @@ -844,7 +836,6 @@ namespace std::experimental

WINRT_EXPORT namespace winrt
{
#ifdef WINRT_IMPL_COROUTINES
template <typename... T>
Windows::Foundation::IAsyncAction when_all(T... async)
{
Expand Down Expand Up @@ -890,5 +881,4 @@ WINRT_EXPORT namespace winrt
impl::check_status_canceled(shared->status);
co_return shared->result.GetResults();
}
#endif
}
4 changes: 1 addition & 3 deletions strings/base_coroutine_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ WINRT_EXPORT namespace winrt
return m_queued;
}

bool await_suspend(impl::coroutine_handle<> handle)
bool await_suspend(std::coroutine_handle<> handle)
{
return m_dispatcher.TryEnqueue(m_priority, [handle, this]
{
Expand All @@ -41,10 +41,8 @@ WINRT_EXPORT namespace winrt
return awaitable{ dispatcher, priority };
};

#ifdef WINRT_IMPL_COROUTINES
inline auto operator co_await(Windows::System::DispatcherQueue const& dispatcher)
{
return resume_foreground(dispatcher);
}
#endif
}
4 changes: 1 addition & 3 deletions strings/base_coroutine_system_winui.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ WINRT_EXPORT namespace winrt
return m_queued;
}

bool await_suspend(impl::coroutine_handle<> handle)
bool await_suspend(std::coroutine_handle<> handle)
{
return m_dispatcher.TryEnqueue(m_priority, [handle, this]
{
Expand All @@ -41,10 +41,8 @@ WINRT_EXPORT namespace winrt
return awaitable{ dispatcher, priority };
};

#ifdef WINRT_IMPL_COROUTINES
inline auto operator co_await(Microsoft::System::DispatcherQueue const& dispatcher)
{
return resume_foreground(dispatcher);
}
#endif
}
50 changes: 21 additions & 29 deletions strings/base_coroutine_threadpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ namespace winrt::impl

inline void __stdcall resume_background_callback(void*, void* context) noexcept
{
coroutine_handle<>::from_address(context)();
std::coroutine_handle<>::from_address(context)();
};

inline auto resume_background(coroutine_handle<> handle)
inline auto resume_background(std::coroutine_handle<> handle)
{
submit_threadpool_callback(resume_background_callback, handle.address());
}
Expand Down Expand Up @@ -64,11 +64,11 @@ namespace winrt::impl

inline std::int32_t __stdcall resume_apartment_callback(com_callback_args* args) noexcept
{
coroutine_handle<>::from_address(args->data)();
std::coroutine_handle<>::from_address(args->data)();
return 0;
};

[[nodiscard]] inline bool resume_apartment_sync(com_ptr<IContextCallback> const& context, coroutine_handle<> handle, std::int32_t* failure)
[[nodiscard]] inline bool resume_apartment_sync(com_ptr<IContextCallback> const& context, std::coroutine_handle<> handle, std::int32_t* failure)
{
com_callback_args args{};
args.data = handle.address();
Expand All @@ -85,10 +85,10 @@ namespace winrt::impl

struct threadpool_resume
{
threadpool_resume(com_ptr<IContextCallback> const& context, coroutine_handle<> handle, std::int32_t* failure) :
threadpool_resume(com_ptr<IContextCallback> const& context, std::coroutine_handle<> handle, std::int32_t* failure) :
m_context(context), m_handle(handle), m_failure(failure) { }
com_ptr<IContextCallback> m_context;
coroutine_handle<> m_handle;
std::coroutine_handle<> m_handle;
std::int32_t* m_failure;
};

Expand All @@ -101,14 +101,14 @@ namespace winrt::impl
}
}

inline void resume_apartment_on_threadpool(com_ptr<IContextCallback> const& context, coroutine_handle<> handle, std::int32_t* failure)
inline void resume_apartment_on_threadpool(com_ptr<IContextCallback> const& context, std::coroutine_handle<> handle, std::int32_t* failure)
{
auto state = std::make_unique<threadpool_resume>(context, handle, failure);
submit_threadpool_callback(fallback_submit_threadpool_callback, state.get());
state.release();
}

[[nodiscard]] inline auto resume_apartment(resume_apartment_context const& context, coroutine_handle<> handle, std::int32_t* failure)
[[nodiscard]] inline auto resume_apartment(resume_apartment_context const& context, std::coroutine_handle<> handle, std::int32_t* failure)
{
WINRT_ASSERT(context.valid());
if ((context.m_context == nullptr) || (context.m_context == try_capture<IContextCallback>(WINRT_IMPL_CoGetObjectContext)))
Expand Down Expand Up @@ -217,7 +217,7 @@ WINRT_EXPORT namespace winrt

protected:
template <typename T>
void set_cancellable_promise_from_handle(impl::coroutine_handle<T> const& handle)
void set_cancellable_promise_from_handle(std::coroutine_handle<T> const& handle)
{
if constexpr (std::is_base_of_v<cancellable_promise, T>)
{
Expand Down Expand Up @@ -254,7 +254,7 @@ WINRT_EXPORT namespace winrt
{
}

void await_suspend(impl::coroutine_handle<> handle) const
void await_suspend(std::coroutine_handle<> handle) const
{
impl::resume_background(handle);
}
Expand All @@ -281,7 +281,7 @@ WINRT_EXPORT namespace winrt
{
}

void await_suspend(impl::coroutine_handle<> resume)
void await_suspend(std::coroutine_handle<> resume)
{
m_resume = resume;

Expand All @@ -301,7 +301,7 @@ WINRT_EXPORT namespace winrt
}

T const& m_context;
impl::coroutine_handle<> m_resume{ nullptr };
std::coroutine_handle<> m_resume{ nullptr };
};

return awaitable{ context };
Expand Down Expand Up @@ -336,7 +336,7 @@ namespace winrt::impl
check_hresult(failure);
}

bool await_suspend(impl::coroutine_handle<> handle)
bool await_suspend(std::coroutine_handle<> handle)
{
auto context_copy = context;
return impl::resume_apartment(context_copy.context, handle, &failure);
Expand Down Expand Up @@ -381,7 +381,7 @@ namespace winrt::impl
}

template <typename T>
void await_suspend(impl::coroutine_handle<T> handle)
void await_suspend(std::coroutine_handle<T> handle)
{
set_cancellable_promise_from_handle(handle);

Expand Down Expand Up @@ -445,7 +445,7 @@ namespace winrt::impl

handle_type<timer_traits> m_timer;
Windows::Foundation::TimeSpan m_duration;
impl::coroutine_handle<> m_handle;
std::coroutine_handle<> m_handle;
std::atomic<state> m_state{ state::idle };
};

Expand Down Expand Up @@ -489,7 +489,7 @@ namespace winrt::impl
}

template <typename T>
void await_suspend(impl::coroutine_handle<T> resume)
void await_suspend(std::coroutine_handle<T> resume)
{
set_cancellable_promise_from_handle(resume);

Expand Down Expand Up @@ -559,31 +559,27 @@ namespace winrt::impl
Windows::Foundation::TimeSpan m_timeout;
void* m_handle;
std::uint32_t m_result{};
impl::coroutine_handle<> m_resume{ nullptr };
std::coroutine_handle<> m_resume{ nullptr };
std::atomic<state> m_state{ state::idle };
};
}

WINRT_EXPORT namespace winrt
{
#ifdef WINRT_IMPL_COROUTINES
inline impl::apartment_awaiter operator co_await(apartment_context const& context)
{
return{ context };
}
#endif

[[nodiscard]] inline impl::timespan_awaiter resume_after(Windows::Foundation::TimeSpan duration) noexcept
{
return impl::timespan_awaiter{ duration };
}

#ifdef WINRT_IMPL_COROUTINES
inline impl::timespan_awaiter operator co_await(Windows::Foundation::TimeSpan duration)
{
return resume_after(duration);
}
#endif

[[nodiscard]] inline impl::signal_awaiter resume_on_signal(void* handle, Windows::Foundation::TimeSpan timeout = {}) noexcept
{
Expand Down Expand Up @@ -613,7 +609,7 @@ WINRT_EXPORT namespace winrt
{
}

void await_suspend(impl::coroutine_handle<> handle)
void await_suspend(std::coroutine_handle<> handle)
{
if (!WINRT_IMPL_TrySubmitThreadpoolCallback(callback, handle.address(), &m_environment))
{
Expand All @@ -625,7 +621,7 @@ WINRT_EXPORT namespace winrt

static void __stdcall callback(void*, void* context) noexcept
{
impl::coroutine_handle<>::from_address(context)();
std::coroutine_handle<>::from_address(context)();
}

struct pool_traits
Expand Down Expand Up @@ -673,11 +669,7 @@ WINRT_EXPORT namespace winrt
struct fire_and_forget {};
}

#ifdef __cpp_lib_coroutine
namespace std
#else
namespace std::experimental
#endif
{
template <typename... Args>
struct coroutine_traits<winrt::fire_and_forget, Args...>
Expand All @@ -693,12 +685,12 @@ namespace std::experimental
{
}

suspend_never initial_suspend() const noexcept
std::suspend_never initial_suspend() const noexcept
{
return{};
}

suspend_never final_suspend() const noexcept
std::suspend_never final_suspend() const noexcept
{
return{};
}
Expand Down
Loading