Skip to content

Commit

Permalink
Remove old implement of c++20 coroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
owent committed May 29, 2022
1 parent 6d37791 commit e0143a1
Show file tree
Hide file tree
Showing 17 changed files with 871 additions and 2,124 deletions.
4 changes: 2 additions & 2 deletions docs/sphinx/example/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Let c++20 coroutine work with cotask::task<MACRO>

This is a simple example to let c++20 coroutine await cotask::task

.. literalinclude:: ../../../sample/sample_readme_10.cpp
.. literalinclude:: ../../../sample/sample_readme_9.cpp
:language: cpp
:encoding: utf-8

Expand All @@ -91,6 +91,6 @@ Using ``SetUnhandledExceptionFilter`` on Windows with cotask::task<MACRO>

Some applications will use ``SetUnhandledExceptionFilter`` to catch unhandled exception and analysis crash problem. But ``SetUnhandledExceptionFilter`` is only works with `coroutine context of windows fiber <https://github.com/owent/libcopp/blob/v2/include/libcopp/coroutine/coroutine_context_fiber_container.h>`_ . This is a sample of using **windows fiber** as coroutine context in ``cotask::task<MACRO>`` .

.. literalinclude:: ../../../sample/sample_readme_11.cpp
.. literalinclude:: ../../../sample/sample_readme_10.cpp
:language: cpp
:encoding: utf-8
2 changes: 2 additions & 0 deletions include/libcopp/coroutine/callable_promise.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ class LIBCOPP_COPP_API_HEAD_ONLY callable_future {
LIBCOPP_MACRO_STD_COROUTINE_NAMESPACE coroutine_handle<promise_type> handle;
};
initial_awaitable initial_suspend() noexcept { return {}; }
# if defined(LIBCOPP_MACRO_ENABLE_EXCEPTION) && LIBCOPP_MACRO_ENABLE_EXCEPTION
void unhandled_exception() { throw; }
# endif
};
using handle_type = LIBCOPP_MACRO_STD_COROUTINE_NAMESPACE coroutine_handle<promise_type>;
using awaitable_type = callable_awaitable<promise_type, std::is_void<typename std::decay<value_type>::type>::value>;
Expand Down
11 changes: 9 additions & 2 deletions include/libcopp/coroutine/generator_promise.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ class LIBCOPP_COPP_API_HEAD_ONLY generator_context_base {
remove_caller(handle_delegate{handle}, inherit_status);
}

inline bool has_multiple_callers() const noexcept { return caller_manager_.has_multiple_callers(); }

protected:
inline UTIL_FORCEINLINE void wake() { caller_manager_.resume_callers(); }
UTIL_FORCEINLINE void wake() { caller_manager_.resume_callers(); }

protected:
future::future<TVALUE> data_;
Expand Down Expand Up @@ -334,13 +336,18 @@ class LIBCOPP_COPP_API_HEAD_ONLY generator_awaitable<TCONTEXT, false> : public g
: base_type(context, await_suspend_callback, await_resume_callback) {}

inline value_type await_resume() {
bool has_multiple_callers = get_context()->has_multiple_callers();
promise_status error_status = detach();

if (promise_status::kDone != error_status) {
return promise_error_transform<value_type>()(error_status);
}

return std::move(*get_context()->data());
if (has_multiple_callers) {
return *get_context()->data();
} else {
return std::move(*get_context()->data());
}
}

private:
Expand Down
2 changes: 2 additions & 0 deletions include/libcopp/coroutine/std_coroutine_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ class promise_caller_manager {

LIBCOPP_COPP_API size_t resume_callers();

LIBCOPP_COPP_API bool has_multiple_callers() const noexcept;

private:
// hash for handle_delegate
struct LIBCOPP_COPP_API_HEAD_ONLY handle_delegate_hash {
Expand Down
210 changes: 0 additions & 210 deletions include/libcopp/future/std_coroutine_generator.h

This file was deleted.

Loading

0 comments on commit e0143a1

Please sign in to comment.