소스 검색

改进移动构造函数

增加sleep_for更简便的写法
tags/v2.9.7
tearshark 5 년 전
부모
커밋
34d0cb55aa
10개의 변경된 파일26개의 추가작업 그리고 14개의 파일을 삭제
  1. 2
    2
      librf/src/counted_ptr.h
  2. 2
    2
      librf/src/future.h
  3. 2
    2
      librf/src/generator.h
  4. 1
    1
      librf/src/scheduler.h
  5. 7
    0
      librf/src/sleep.h
  6. 2
    2
      librf/src/task_list.h
  7. 1
    1
      librf/src/when.h
  8. 3
    1
      tutorial/test_async_sleep.cpp
  9. 2
    1
      vs_proj/librf.cpp
  10. 4
    2
      vs_proj/librf.vcxproj

+ 2
- 2
librf/src/counted_ptr.h 파일 보기

@@ -17,7 +17,7 @@ namespace resumef
_lock();
}
counted_ptr(counted_ptr&& cp)
counted_ptr(counted_ptr&& cp) noexcept
{
std::swap(_p, cp._p);
}
@@ -32,7 +32,7 @@ namespace resumef
return *this;
}
counted_ptr& operator=(counted_ptr&& cp)
counted_ptr& operator=(counted_ptr&& cp) noexcept
{
if (&cp != this)
std::swap(_p, cp._p);

+ 2
- 2
librf/src/future.h 파일 보기

@@ -165,14 +165,14 @@ namespace resumef
_state->this_promise(this);
#endif
}
promise_impl_t(promise_impl_t&& _Right)
promise_impl_t(promise_impl_t&& _Right) noexcept
: _state(std::move(_Right._state))
{
#if RESUMEF_ENABLE_MULT_SCHEDULER
_state->this_promise(this);
#endif
}
promise_impl_t & operator = (promise_impl_t&& _Right)
promise_impl_t & operator = (promise_impl_t&& _Right) noexcept
{
if (this != _Right)
{

+ 2
- 2
librf/src/generator.h 파일 보기

@@ -101,7 +101,7 @@ namespace experimental {
_Ty const &operator*() const
{
return *_Coro.promise()._CurrentValue;
return *this->_Coro.promise()._CurrentValue;
}
_Ty const *operator->() const
@@ -166,7 +166,7 @@ namespace experimental {
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;
return _Al.deallocate(static_cast<char *>(_Ptr), _Size);

+ 1
- 1
librf/src/scheduler.h 파일 보기

@@ -104,7 +104,7 @@ namespace resumef
#if !defined(_DISABLE_RESUMEF_GO_MACRO)
#define go (*::resumef::this_scheduler()) +
#define GO (*::resumef::this_scheduler()) + [=]()->resumef::future_vt
#define GO (*::resumef::this_scheduler()) + [=]()mutable->resumef::future_vt
#endif
//--------------------------------------------------------------------------------------------------

+ 7
- 0
librf/src/sleep.h 파일 보기

@@ -36,4 +36,11 @@ namespace resumef
{
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 파일 보기

@@ -35,7 +35,7 @@ namespace resumef
task_list(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;
_Right._M_header = nullptr;
@@ -43,7 +43,7 @@ namespace resumef
_Right._M_last = nullptr;
}
task_list& operator=(task_list&& _Right)
task_list& operator=(task_list&& _Right) noexcept
{ // assign by moving _Right
if (this != std::addressof(_Right))
{ // different, assign it

+ 1
- 1
librf/src/when.h 파일 보기

@@ -37,7 +37,7 @@ namespace resumef
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)
{
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;

+ 3
- 1
tutorial/test_async_sleep.cpp 파일 보기

@@ -16,7 +16,9 @@ future_vt test_sleep_use_timer()
resumef::sleep_for(100ms); //incorrect!!!
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
{

+ 2
- 1
vs_proj/librf.cpp 파일 보기

@@ -22,7 +22,8 @@ extern void resumable_main_benchmark_mem();
int main(int argc, const char * argv[])
{
//resumable_main_sleep();
resumable_main_sleep();
return 0;
//resumable_main_resumable();
resumable_main_when_all();

+ 4
- 2
vs_proj/librf.vcxproj 파일 보기

@@ -105,12 +105,13 @@
<PreprocessorDefinitions>_DEBUG;_CONSOLE;RESUMEF_DEBUG_COUNTER=0;RESUMEF_ENABLE_MULT_SCHEDULER=0;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>..\librf;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>/await</AdditionalOptions>
<AdditionalOptions>/await /permissive- </AdditionalOptions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard>stdcpplatest</LanguageStandard>
<MinimalRebuild />
<CLanguageStandard>c11</CLanguageStandard>
<CppLanguageStandard>c++1y</CppLanguageStandard>
<DisableLanguageExtensions>true</DisableLanguageExtensions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -156,6 +157,7 @@
<LanguageStandard>stdcpplatest</LanguageStandard>
<BufferSecurityCheck>false</BufferSecurityCheck>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<DisableLanguageExtensions>true</DisableLanguageExtensions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>

Loading…
취소
저장