Commit c09fadd4 authored by Shai Szulanski's avatar Shai Szulanski Committed by Facebook GitHub Bot

Avoid bumping cancellation token refcount on moved-in tokens

Summary: Task forces a copy of the passed-in token even when it's an rvalue, which results in two unnecessary atomic operations on the shared state. Take by value to allow moving. AsyncGenerator already does this.

Reviewed By: yfeldblum

Differential Revision: D26991772

fbshipit-source-id: 4697e36626158155329306928cbd1e7e69b8bd01
parent 35271eac
......@@ -115,9 +115,9 @@ class TaskPromiseBase {
return ready_awaitable<const folly::CancellationToken&>{cancelToken_};
}
void setCancelToken(const folly::CancellationToken& cancelToken) noexcept {
void setCancelToken(folly::CancellationToken&& cancelToken) noexcept {
if (!hasCancelTokenOverride_) {
cancelToken_ = cancelToken;
cancelToken_ = std::move(cancelToken);
hasCancelTokenOverride_ = true;
}
}
......@@ -504,10 +504,9 @@ class FOLLY_NODISCARD TaskWithExecutor {
}
friend TaskWithExecutor co_withCancellation(
const folly::CancellationToken& cancelToken,
TaskWithExecutor&& task) noexcept {
folly::CancellationToken cancelToken, TaskWithExecutor&& task) noexcept {
DCHECK(task.coro_);
task.coro_.promise().setCancelToken(cancelToken);
task.coro_.promise().setCancelToken(std::move(cancelToken));
return std::move(task);
}
......@@ -621,9 +620,9 @@ class FOLLY_NODISCARD Task {
}
friend Task co_withCancellation(
const folly::CancellationToken& cancelToken, Task&& task) noexcept {
folly::CancellationToken cancelToken, Task&& task) noexcept {
DCHECK(task.coro_);
task.coro_.promise().setCancelToken(cancelToken);
task.coro_.promise().setCancelToken(std::move(cancelToken));
return std::move(task);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment