瀏覽代碼

处理一些特殊情况下可能导致崩溃的问题

tags/2.9.10
tearshark 4 年之前
父節點
當前提交
ec2dbb9738
共有 3 個文件被更改,包括 34 次插入9 次删除
  1. 10
    0
      librf/src/generator.h
  2. 3
    0
      librf/src/promise.h
  3. 21
    9
      librf/src/promise.inl

+ 10
- 0
librf/src/generator.h 查看文件

@@ -158,11 +158,13 @@ namespace resumef
void set_exception(std::exception_ptr e)
{
(void)e;
//ref_state()->set_exception(std::move(e));
std::terminate();
}
#if defined(__clang__) || defined(__GNUC__)
void unhandled_exception()
{
//this->ref_state()->set_exception(std::current_exception());
std::terminate();
}
#endif
@@ -193,6 +195,14 @@ namespace resumef
return _state.get();
#endif
}
//counted_ptr<state_type> ref_state() noexcept
//{
// return { get_state() };
//}
state_type* ref_state() noexcept
{
return get_state();
}
using _Alloc_char = typename std::allocator_traits<_Alloc>::template rebind_alloc<char>;
static_assert(std::is_same_v<char*, typename std::allocator_traits<_Alloc_char>::pointer>,

+ 3
- 0
librf/src/promise.h 查看文件

@@ -24,6 +24,9 @@ namespace resumef
promise_impl_t& operator = (const promise_impl_t&) = delete;

auto get_state() noexcept->state_type*;
// 如果去掉了调度器,则ref_state()实现为返回counted_ptr<>,以便于处理一些意外情况
// auto ref_state() noexcept->counted_ptr<state_type>;
auto ref_state() noexcept->state_type*;

suspend_on_initial initial_suspend() noexcept;
suspend_on_final final_suspend() noexcept;

+ 21
- 9
librf/src/promise.inl 查看文件

@@ -35,7 +35,7 @@ namespace resumef
inline void await_suspend(coroutine_handle<_PromiseT> handler) noexcept
{
_PromiseT& promise = handler.promise();
auto* _state = promise.get_state();
auto _state = promise.ref_state();
_state->promise_final_suspend(handler);
}
inline void await_resume() noexcept
@@ -70,14 +70,14 @@ namespace resumef
template <typename _Ty>
inline void promise_impl_t<_Ty>::set_exception(std::exception_ptr e)
{
this->get_state()->set_exception(std::move(e));
this->ref_state()->set_exception(std::move(e));
}

#if defined(__clang__) || defined(__GNUC__)
template <typename _Ty>
inline void promise_impl_t<_Ty>::unhandled_exception()
{
this->get_state()->set_exception(std::current_exception());
this->ref_state()->set_exception(std::current_exception());
}
#endif

@@ -113,6 +113,18 @@ namespace resumef
#endif
}

// 如果去掉了调度器,则ref_state()实现为返回counted_ptr<>,以便于处理一些意外情况
//template <typename _Ty>
//auto promise_impl_t<_Ty>::ref_state() noexcept -> counted_ptr<state_type>
//{
// return { get_state() };
//}
template <typename _Ty>
auto promise_impl_t<_Ty>::ref_state() noexcept -> state_type*
{
return get_state();
}

template <typename _Ty>
void* promise_impl_t<_Ty>::operator new(size_t _Size)
{
@@ -172,38 +184,38 @@ namespace resumef
template<class U>
inline void promise_t<_Ty>::return_value(U&& val)
{
this->get_state()->set_value(std::forward<U>(val));
this->ref_state()->set_value(std::forward<U>(val));
}

template<class _Ty>
template<class U>
inline suspend_always promise_t<_Ty>::yield_value(U&& val)
{
this->get_state()->promise_yield_value(this, std::forward<U>(val));
this->ref_state()->promise_yield_value(this, std::forward<U>(val));
return {};
}

template<class _Ty>
inline void promise_t<_Ty&>::return_value(_Ty& val)
{
this->get_state()->set_value(val);
this->ref_state()->set_value(val);
}

template<class _Ty>
inline suspend_always promise_t<_Ty&>::yield_value(_Ty& val)
{
this->get_state()->promise_yield_value(this, val);
this->ref_state()->promise_yield_value(this, val);
return {};
}

inline void promise_t<void>::return_void()
{
this->get_state()->set_value();
this->ref_state()->set_value();
}

inline suspend_always promise_t<void>::yield_value()
{
this->get_state()->promise_yield_value(this);
this->ref_state()->promise_yield_value(this);
return {};
}
}

Loading…
取消
儲存