Browse Source

改进移动构造函数

增加sleep_for更简便的写法
tags/v2.9.7
tearshark 5 years ago
parent
commit
34d0cb55aa

+ 2
- 2
librf/src/counted_ptr.h View File

_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);

+ 2
- 2
librf/src/future.h View File

_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)
{ {

+ 2
- 2
librf/src/generator.h View File

_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);

+ 1
- 1
librf/src/scheduler.h View File

#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
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

+ 7
- 0
librf/src/sleep.h View File

{ {
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_);
}
} }

+ 2
- 2
librf/src/task_list.h View File

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

+ 1
- 1
librf/src/when.h View File

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;

+ 3
- 1
tutorial/test_async_sleep.cpp View File

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
{ {

+ 2
- 1
vs_proj/librf.cpp View File

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();

+ 4
- 2
vs_proj/librf.vcxproj View File

<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>

Loading…
Cancel
Save