@@ -3,6 +3,9 @@ | |||
namespace resumef | |||
{ | |||
struct suspend_on_initial; | |||
struct suspend_on_final; | |||
template <typename _Ty> | |||
struct promise_impl_t | |||
{ | |||
@@ -20,8 +23,8 @@ namespace resumef | |||
promise_impl_t(const promise_impl_t&) = delete; | |||
promise_impl_t & operator = (const promise_impl_t&) = delete; | |||
auto initial_suspend() noexcept; | |||
auto final_suspend() noexcept; | |||
suspend_on_initial initial_suspend() noexcept; | |||
suspend_on_final final_suspend() noexcept; | |||
void set_exception(std::exception_ptr e); | |||
future_type get_return_object(); | |||
void cancellation_requested(); |
@@ -43,15 +43,15 @@ namespace resumef | |||
}; | |||
template <typename _Ty> | |||
inline auto promise_impl_t<_Ty>::initial_suspend() noexcept | |||
inline suspend_on_initial promise_impl_t<_Ty>::initial_suspend() noexcept | |||
{ | |||
return suspend_on_initial{ _state.get() }; | |||
return { _state.get() }; | |||
} | |||
template <typename _Ty> | |||
inline auto promise_impl_t<_Ty>::final_suspend() noexcept | |||
inline suspend_on_final promise_impl_t<_Ty>::final_suspend() noexcept | |||
{ | |||
return suspend_on_final{ _state.get() }; | |||
return { _state.get() }; | |||
} | |||
template <typename _Ty> |
@@ -1,6 +1,4 @@ | |||
#pragma once | |||
#include "_awaker.h" | |||
#if RESUMEF_USE_BOOST_ANY | |||
#include <boost/any.hpp> | |||
namespace resumef | |||
@@ -17,6 +15,11 @@ namespace resumef | |||
} | |||
#endif | |||
#include "_awaker.h" | |||
#include "promise.h" | |||
#include "promise.inl" | |||
//纠结过when_any的返回值,是选用index + std::any,还是选用std::variant<>。最终选择了std::any。 | |||
//std::variant<>存在第一个元素不能默认构造的问题,需要使用std::monostate来占位,导致下标不是从0开始。 | |||
//而且,std::variant<>里面存在类型重复的问题,好几个操作都是病态的 | |||
@@ -193,7 +196,7 @@ namespace resumef | |||
template<class _Tup, class _Iter> | |||
future_t<_Tup> when_all_range(size_t count, const std::shared_ptr<_Tup> & vals, scheduler_t& s, _Iter begin, _Iter end) | |||
{ | |||
promise_t<_Tup> awaitable; | |||
awaitable_t<_Tup> awaitable; | |||
when_impl_ptr _event = std::make_shared<when_impl>(count); | |||
auto awaker = std::make_shared<when_awaker>( | |||
@@ -314,7 +317,7 @@ namespace resumef | |||
template<class... _Fty> | |||
future_t<when_any_pair> when_any_count(size_t count, const when_any_result_ptr & val_ptr, scheduler_t & s, _Fty&&... f) | |||
{ | |||
promise_t<when_any_pair> awaitable; | |||
awaitable_t<when_any_pair> awaitable; | |||
when_impl_ptr _event = std::make_shared<when_impl>(count); | |||
auto awaker = std::make_shared<when_awaker>( | |||
@@ -347,7 +350,7 @@ namespace resumef | |||
template<class _Iter> | |||
future_t<when_any_pair> when_any_range(size_t count, const when_any_result_ptr & val_ptr, scheduler_t & s, _Iter begin, _Iter end) | |||
{ | |||
promise_t<when_any_pair> awaitable; | |||
awaitable_t<when_any_pair> awaitable; | |||
when_impl_ptr _event = std::make_shared<when_impl>(count); | |||
auto awaker = std::make_shared<when_awaker>( |
@@ -23,6 +23,7 @@ extern void resumable_main_channel_mult_thread(); | |||
extern void resumable_main_when_all(); | |||
extern void resumable_main_benchmark_mem(); | |||
extern void benchmark_main_channel_passing_next(); | |||
extern void resumable_main_benchmark_asio_server(); | |||
extern void resumable_main_benchmark_asio_client(intptr_t nNum); | |||
@@ -47,7 +48,9 @@ int main(int argc, const char* argv[]) | |||
//resumable_main_event_timeout(); | |||
//resumable_main_channel(); | |||
//resumable_main_channel_mult_thread(); //测试失败! | |||
resumable_main_sleep(); | |||
//resumable_main_sleep(); | |||
//resumable_main_when_all(); | |||
benchmark_main_channel_passing_next(); | |||
/* | |||
if (argc > 1) | |||
@@ -55,7 +58,6 @@ int main(int argc, const char* argv[]) | |||
else | |||
resumable_main_benchmark_asio_server(); | |||
resumable_main_when_all(); | |||
*/ | |||
return 0; |
@@ -187,12 +187,7 @@ | |||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> | |||
</ClCompile> | |||
<ClCompile Include="..\benchmark\benchmark_async_mem.cpp" /> | |||
<ClCompile Include="..\benchmark\benchmark_channel_passing_next.cpp"> | |||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> | |||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> | |||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> | |||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> | |||
</ClCompile> | |||
<ClCompile Include="..\benchmark\benchmark_channel_passing_next.cpp" /> | |||
<ClCompile Include="..\librf\src\event.cpp" /> | |||
<ClCompile Include="..\librf\src\mutex.cpp" /> | |||
<ClCompile Include="..\librf\src\rf_task.cpp" /> | |||
@@ -200,12 +195,7 @@ | |||
<ClCompile Include="..\librf\src\sleep.cpp" /> | |||
<ClCompile Include="..\librf\src\state.cpp" /> | |||
<ClCompile Include="..\librf\src\timer.cpp" /> | |||
<ClCompile Include="..\librf\src\when.cpp"> | |||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> | |||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> | |||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> | |||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> | |||
</ClCompile> | |||
<ClCompile Include="..\librf\src\when.cpp" /> | |||
<ClCompile Include="..\tutorial\test_async_cb.cpp" /> | |||
<ClCompile Include="..\tutorial\test_async_channel.cpp" /> | |||
<ClCompile Include="..\tutorial\test_async_channel_mult_thread.cpp" /> | |||
@@ -221,12 +211,7 @@ | |||
<ClCompile Include="..\tutorial\test_async_sleep.cpp" /> | |||
<ClCompile Include="..\tutorial\test_async_suspend_always.cpp" /> | |||
<ClCompile Include="..\tutorial\test_async_timer.cpp" /> | |||
<ClCompile Include="..\tutorial\test_async_when_all.cpp"> | |||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> | |||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> | |||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> | |||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> | |||
</ClCompile> | |||
<ClCompile Include="..\tutorial\test_async_when_all.cpp" /> | |||
<ClCompile Include="..\tutorial\test_async_yield_return.cpp" /> | |||
<ClCompile Include="librf.cpp"> | |||
<BasicRuntimeChecks Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Default</BasicRuntimeChecks> |