#include "event.h" | #include "event.h" | ||||
#include <assert.h> | #include <assert.h> | ||||
#include "scheduler.h" | #include "scheduler.h" | ||||
#include "awaitable.h" | |||||
#include "state.inl" | |||||
namespace resumef | namespace resumef | ||||
{ | { | ||||
future_t<bool> event_t::wait() const | future_t<bool> event_t::wait() const | ||||
{ | { | ||||
promise_t<bool> awaitable; | |||||
awaitable_t<bool> awaitable; | |||||
auto awaker = std::make_shared<detail::event_awaker>( | auto awaker = std::make_shared<detail::event_awaker>( | ||||
[st = awaitable._state](detail::event_impl * e) -> bool | [st = awaitable._state](detail::event_impl * e) -> bool | ||||
future_t<bool> event_t::wait_until_(const clock_type::time_point & tp) const | future_t<bool> event_t::wait_until_(const clock_type::time_point & tp) const | ||||
{ | { | ||||
promise_t<bool> awaitable; | |||||
awaitable_t<bool> awaitable; | |||||
auto awaker = std::make_shared<detail::event_awaker>( | auto awaker = std::make_shared<detail::event_awaker>( | ||||
[st = awaitable._state](detail::event_impl * e) -> bool | [st = awaitable._state](detail::event_impl * e) -> bool | ||||
future_t<intptr_t> event_t::wait_any_(std::vector<event_impl_ptr> && evts) | future_t<intptr_t> event_t::wait_any_(std::vector<event_impl_ptr> && evts) | ||||
{ | { | ||||
promise_t<intptr_t> awaitable; | |||||
awaitable_t<intptr_t> awaitable; | |||||
if (evts.size() <= 0) | if (evts.size() <= 0) | ||||
{ | { | ||||
future_t<intptr_t> event_t::wait_any_until_(const clock_type::time_point & tp, std::vector<event_impl_ptr> && evts) | future_t<intptr_t> event_t::wait_any_until_(const clock_type::time_point & tp, std::vector<event_impl_ptr> && evts) | ||||
{ | { | ||||
promise_t<intptr_t> awaitable; | |||||
awaitable_t<intptr_t> awaitable; | |||||
auto awaker = std::make_shared<detail::event_awaker>( | auto awaker = std::make_shared<detail::event_awaker>( | ||||
[st = awaitable._state, evts](detail::event_impl * e) -> bool | [st = awaitable._state, evts](detail::event_impl * e) -> bool | ||||
future_t<bool> event_t::wait_all_(std::vector<event_impl_ptr> && evts) | future_t<bool> event_t::wait_all_(std::vector<event_impl_ptr> && evts) | ||||
{ | { | ||||
promise_t<bool> awaitable; | |||||
awaitable_t<bool> awaitable; | |||||
if (evts.size() <= 0) | if (evts.size() <= 0) | ||||
{ | { | ||||
awaitable._state->set_value(false); | awaitable._state->set_value(false); | ||||
//则需要超时后,恢复已经等待的事件计数 | //则需要超时后,恢复已经等待的事件计数 | ||||
future_t<bool> event_t::wait_all_until_(const clock_type::time_point & tp, std::vector<event_impl_ptr> && evts) | future_t<bool> event_t::wait_all_until_(const clock_type::time_point & tp, std::vector<event_impl_ptr> && evts) | ||||
{ | { | ||||
promise_t<bool> awaitable; | |||||
awaitable_t<bool> awaitable; | |||||
if (evts.size() <= 0) | if (evts.size() <= 0) | ||||
{ | { | ||||
(void)this_scheduler()->timer()->add_handler(tp, | (void)this_scheduler()->timer()->add_handler(tp, |
//resumable_main_multi_thread(); | //resumable_main_multi_thread(); | ||||
//resumable_main_timer(); | //resumable_main_timer(); | ||||
//resumable_main_benchmark_mem(); | //resumable_main_benchmark_mem(); | ||||
resumable_main_mutex(); | |||||
//resumable_main_mutex(); | |||||
resumable_main_event(); | |||||
/* | /* | ||||
resumable_main_benchmark_mem(); | resumable_main_benchmark_mem(); | ||||
resumable_main_when_all(); | resumable_main_when_all(); | ||||
resumable_main_sleep(); | resumable_main_sleep(); | ||||
resumable_main_event(); | |||||
resumable_main_event_timeout(); | resumable_main_event_timeout(); | ||||
resumable_main_channel(); | resumable_main_channel(); | ||||
*/ | */ |
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> | <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> | ||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> | <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> | ||||
</ClCompile> | </ClCompile> | ||||
<ClCompile Include="..\librf\src\event.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\event.cpp" /> | |||||
<ClCompile Include="..\librf\src\mutex.cpp" /> | <ClCompile Include="..\librf\src\mutex.cpp" /> | ||||
<ClCompile Include="..\librf\src\rf_task.cpp" /> | <ClCompile Include="..\librf\src\rf_task.cpp" /> | ||||
<ClCompile Include="..\librf\src\scheduler.cpp" /> | <ClCompile Include="..\librf\src\scheduler.cpp" /> | ||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> | <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> | ||||
</ClCompile> | </ClCompile> | ||||
<ClCompile Include="..\tutorial\test_async_dynamic_go.cpp" /> | <ClCompile Include="..\tutorial\test_async_dynamic_go.cpp" /> | ||||
<ClCompile Include="..\tutorial\test_async_event.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_event.cpp" /> | |||||
<ClCompile Include="..\tutorial\test_async_event_timeout.cpp"> | <ClCompile Include="..\tutorial\test_async_event_timeout.cpp"> | ||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> | <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> | ||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> | <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> |