_lock(); | _lock(); | ||||
} | } | ||||
counted_ptr(counted_ptr&& cp) | |||||
counted_ptr(counted_ptr&& cp) noexcept | |||||
{ | { | ||||
std::swap(_p, cp._p); | std::swap(_p, cp._p); | ||||
} | } | ||||
return *this; | return *this; | ||||
} | } | ||||
counted_ptr& operator=(counted_ptr&& cp) | |||||
counted_ptr& operator=(counted_ptr&& cp) noexcept | |||||
{ | { | ||||
if (&cp != this) | if (&cp != this) | ||||
std::swap(_p, cp._p); | std::swap(_p, cp._p); |
_state->this_promise(this); | _state->this_promise(this); | ||||
#endif | #endif | ||||
} | } | ||||
promise_impl_t(promise_impl_t&& _Right) | |||||
promise_impl_t(promise_impl_t&& _Right) noexcept | |||||
: _state(std::move(_Right._state)) | : _state(std::move(_Right._state)) | ||||
{ | { | ||||
#if RESUMEF_ENABLE_MULT_SCHEDULER | #if RESUMEF_ENABLE_MULT_SCHEDULER | ||||
_state->this_promise(this); | _state->this_promise(this); | ||||
#endif | #endif | ||||
} | } | ||||
promise_impl_t & operator = (promise_impl_t&& _Right) | |||||
promise_impl_t & operator = (promise_impl_t&& _Right) noexcept | |||||
{ | { | ||||
if (this != _Right) | if (this != _Right) | ||||
{ | { |
_Ty const &operator*() const | _Ty const &operator*() const | ||||
{ | { | ||||
return *_Coro.promise()._CurrentValue; | |||||
return *this->_Coro.promise()._CurrentValue; | |||||
} | } | ||||
_Ty const *operator->() const | _Ty const *operator->() const | ||||
return _Al.allocate(_Size); | return _Al.allocate(_Size); | ||||
} | } | ||||
void operator delete(void *_Ptr, size_t _Size)_NOEXCEPT | |||||
void operator delete(void *_Ptr, size_t _Size) | |||||
{ | { | ||||
_Alloc_of_char_type _Al; | _Alloc_of_char_type _Al; | ||||
return _Al.deallocate(static_cast<char *>(_Ptr), _Size); | return _Al.deallocate(static_cast<char *>(_Ptr), _Size); |
#if !defined(_DISABLE_RESUMEF_GO_MACRO) | #if !defined(_DISABLE_RESUMEF_GO_MACRO) | ||||
#define go (*::resumef::this_scheduler()) + | #define go (*::resumef::this_scheduler()) + | ||||
#define GO (*::resumef::this_scheduler()) + [=]()->resumef::future_vt | |||||
#define GO (*::resumef::this_scheduler()) + [=]()mutable->resumef::future_vt | |||||
#endif | #endif | ||||
//-------------------------------------------------------------------------------------------------- | //-------------------------------------------------------------------------------------------------- |
{ | { | ||||
return std::move(sleep_until_(std::chrono::time_point_cast<std::chrono::system_clock::duration>(tp_), *this_scheduler())); | return std::move(sleep_until_(std::chrono::time_point_cast<std::chrono::system_clock::duration>(tp_), *this_scheduler())); | ||||
} | } | ||||
template <class Rep, class Period> | |||||
auto operator co_await(std::chrono::duration<Rep, Period> dt_) | |||||
{ | |||||
return sleep_for(dt_); | |||||
} | |||||
} | } |
task_list(const task_list& _Right) = delete; | task_list(const task_list& _Right) = delete; | ||||
task_list& operator=(const task_list& _Right) = delete; | task_list& operator=(const task_list& _Right) = delete; | ||||
task_list(task_list&& _Right) | |||||
task_list(task_list&& _Right) noexcept | |||||
{ | { | ||||
_M_header = _Right._M_header; | _M_header = _Right._M_header; | ||||
_Right._M_header = nullptr; | _Right._M_header = nullptr; | ||||
_Right._M_last = nullptr; | _Right._M_last = nullptr; | ||||
} | } | ||||
task_list& operator=(task_list&& _Right) | |||||
task_list& operator=(task_list&& _Right) noexcept | |||||
{ // assign by moving _Right | { // assign by moving _Right | ||||
if (this != std::addressof(_Right)) | if (this != std::addressof(_Right)) | ||||
{ // different, assign it | { // different, assign it |
template<class callee_t, class dummy_t = std::enable_if<!std::is_same<std::remove_cv_t<callee_t>, event_awaker_ptr>::value>> | template<class callee_t, class dummy_t = std::enable_if<!std::is_same<std::remove_cv_t<callee_t>, event_awaker_ptr>::value>> | ||||
auto wait(callee_t && awaker, dummy_t * dummy_ = nullptr) | auto wait(callee_t && awaker, dummy_t * dummy_ = nullptr) | ||||
{ | { | ||||
return wait_(std::make_shared<event_awaker>(std::forward<callee_t>(awaker))); | |||||
return wait_(std::make_shared<when_awaker>(std::forward<callee_t>(awaker))); | |||||
} | } | ||||
when_impl(const when_impl &) = delete; | when_impl(const when_impl &) = delete; |
resumef::sleep_for(100ms); //incorrect!!! | resumef::sleep_for(100ms); //incorrect!!! | ||||
co_await resumef::sleep_for(100ms); | co_await resumef::sleep_for(100ms); | ||||
std::cout << "timer after 100ms." << std::endl; | |||||
std::cout << "sleep_for 100ms." << std::endl; | |||||
co_await 100ms; | |||||
std::cout << "co_await 100ms." << std::endl; | |||||
try | try | ||||
{ | { |
int main(int argc, const char * argv[]) | int main(int argc, const char * argv[]) | ||||
{ | { | ||||
//resumable_main_sleep(); | |||||
resumable_main_sleep(); | |||||
return 0; | |||||
//resumable_main_resumable(); | //resumable_main_resumable(); | ||||
resumable_main_when_all(); | resumable_main_when_all(); |
<PreprocessorDefinitions>_DEBUG;_CONSOLE;RESUMEF_DEBUG_COUNTER=0;RESUMEF_ENABLE_MULT_SCHEDULER=0;%(PreprocessorDefinitions)</PreprocessorDefinitions> | <PreprocessorDefinitions>_DEBUG;_CONSOLE;RESUMEF_DEBUG_COUNTER=0;RESUMEF_ENABLE_MULT_SCHEDULER=0;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||||
<SDLCheck>true</SDLCheck> | <SDLCheck>true</SDLCheck> | ||||
<AdditionalIncludeDirectories>..\librf;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | <AdditionalIncludeDirectories>..\librf;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | ||||
<AdditionalOptions>/await</AdditionalOptions> | |||||
<AdditionalOptions>/await /permissive- </AdditionalOptions> | |||||
<MultiProcessorCompilation>true</MultiProcessorCompilation> | <MultiProcessorCompilation>true</MultiProcessorCompilation> | ||||
<LanguageStandard>stdcpp17</LanguageStandard> | |||||
<LanguageStandard>stdcpplatest</LanguageStandard> | |||||
<MinimalRebuild /> | <MinimalRebuild /> | ||||
<CLanguageStandard>c11</CLanguageStandard> | <CLanguageStandard>c11</CLanguageStandard> | ||||
<CppLanguageStandard>c++1y</CppLanguageStandard> | <CppLanguageStandard>c++1y</CppLanguageStandard> | ||||
<DisableLanguageExtensions>true</DisableLanguageExtensions> | |||||
</ClCompile> | </ClCompile> | ||||
<Link> | <Link> | ||||
<SubSystem>Console</SubSystem> | <SubSystem>Console</SubSystem> | ||||
<LanguageStandard>stdcpplatest</LanguageStandard> | <LanguageStandard>stdcpplatest</LanguageStandard> | ||||
<BufferSecurityCheck>false</BufferSecurityCheck> | <BufferSecurityCheck>false</BufferSecurityCheck> | ||||
<MultiProcessorCompilation>true</MultiProcessorCompilation> | <MultiProcessorCompilation>true</MultiProcessorCompilation> | ||||
<DisableLanguageExtensions>true</DisableLanguageExtensions> | |||||
</ClCompile> | </ClCompile> | ||||
<Link> | <Link> | ||||
<SubSystem>Console</SubSystem> | <SubSystem>Console</SubSystem> |