Skip to content

Commit

Permalink
Add 2 ACC specific attributes to Lazy
Browse files Browse the repository at this point in the history
Add 2 ACC specific attributes to Lazy: [[ACC::coro_only_destroy_when_complete]]
and [[ACC::elideable_after_await]]. This is transparent to all other
non-ACC users.
  • Loading branch information
ChuanqiXu9 committed Sep 18, 2023
1 parent 1527007 commit 0e21867
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions async_simple/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@
#endif // __SANITIZE_ADDRESS__
#endif // __GNUC__

#if defined(__alibaba_clang__) && \
__has_cpp_attribute(ACC::coro_only_destroy_when_complete)
#define CORO_ONLY_DESTROY_WHEN_DONE [[ACC::coro_only_destroy_when_complete]]
#else
#define CORO_ONLY_DESTROY_WHEN_DONE
#endif

#if defined(__alibaba_clang__) && \
__has_cpp_attribute(ACC::elideable_after_await)
#define ELIDEABLE_AFTER_AWAIT [[ACC::elideable_after_await]]
#else
#define ELIDEABLE_AFTER_AWAIT
#endif

namespace async_simple {
// Different from assert, logicAssert is meaningful in
// release mode. logicAssert should be used in case that
Expand Down
3 changes: 2 additions & 1 deletion async_simple/coro/Lazy.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ class LazyBase {
// should implement `coAwait(Executor*)` member method. Then the caller would
// pass its executor instance to the awaitable.
template <typename T = void>
class [[nodiscard]] Lazy : public detail::LazyBase<T, /*reschedule=*/false> {
class [[nodiscard]] CORO_ONLY_DESTROY_WHEN_DONE ELIDEABLE_AFTER_AWAIT Lazy
: public detail::LazyBase<T, /*reschedule=*/false> {
using Base = detail::LazyBase<T, false>;

public:
Expand Down

2 comments on commit 0e21867

@RainMark
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是什么内部高级优化

@ChuanqiXu9
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是什么内部高级优化

一个减少 coroutine destroy 函数生成的代码,另一个尝试减少协程的动态分配,都还在实验中。

Please sign in to comment.