Commit 11de2a3f authored by Lewis Baker's avatar Lewis Baker Committed by Facebook GitHub Bot

Remove workaround for TSAN symmetric-transfer bug

Summary:
Removes the symmetricTransferMaybeReschedule() helper functions as
the workarounds are no longer required now that clang fixes have been
merged.

Reviewed By: andriigrynenko

Differential Revision: D24554145

fbshipit-source-id: ce3a6b6a8ead63b98e605c21d6555950b3b55c9a
parent 0c20854f
......@@ -26,7 +26,6 @@
#include <folly/experimental/coro/Utils.h>
#include <folly/experimental/coro/ViaIfAsync.h>
#include <folly/experimental/coro/WithCancellation.h>
#include <folly/experimental/coro/detail/Helpers.h>
#include <folly/experimental/coro/detail/Malloc.h>
#include <folly/experimental/coro/detail/ManualLifetime.h>
......@@ -51,8 +50,9 @@ class AsyncGeneratorPromise {
bool await_ready() noexcept { return false; }
auto await_suspend(
std::experimental::coroutine_handle<AsyncGeneratorPromise> h) noexcept {
return symmetricTransferMaybeReschedule(
h.promise().continuation_, h.promise().clearContext());
auto& promise = h.promise();
promise.clearContext();
return promise.continuation_;
}
void await_resume() noexcept {}
};
......@@ -211,12 +211,10 @@ class AsyncGeneratorPromise {
bool hasValue() const noexcept { return state_ == State::VALUE; }
private:
folly::Executor::KeepAlive<> clearContext() noexcept {
auto executor = std::exchange(executor_, {});
void clearContext() noexcept {
executor_ = {};
cancelToken_ = {};
hasCancelTokenOverride_ = false;
return executor;
}
enum class State : std::uint8_t {
......
......@@ -35,7 +35,6 @@
#include <folly/experimental/coro/Utils.h>
#include <folly/experimental/coro/ViaIfAsync.h>
#include <folly/experimental/coro/WithCancellation.h>
#include <folly/experimental/coro/detail/Helpers.h>
#include <folly/experimental/coro/detail/InlineTask.h>
#include <folly/experimental/coro/detail/Malloc.h>
#include <folly/experimental/coro/detail/Traits.h>
......@@ -78,11 +77,9 @@ class TaskPromiseBase {
bool await_ready() noexcept { return false; }
template <typename Promise>
auto await_suspend(
std::experimental::coroutine_handle<> await_suspend(
std::experimental::coroutine_handle<Promise> coro) noexcept {
TaskPromiseBase& promise = coro.promise();
return symmetricTransferMaybeReschedule(
promise.continuation_, promise.executor_);
return coro.promise().continuation_;
}
[[noreturn]] void await_resume() noexcept { folly::assume_unreachable(); }
......@@ -563,10 +560,10 @@ class FOLLY_NODISCARD Task {
bool await_ready() noexcept { return false; }
auto await_suspend(
handle_t await_suspend(
std::experimental::coroutine_handle<> continuation) noexcept {
coro_.promise().continuation_ = continuation;
return symmetricTransferMaybeReschedule(coro_, coro_.promise().executor_);
return coro_;
}
T await_resume() { return await_resume_try().value(); }
......
......@@ -42,48 +42,6 @@ class UnsafeResumeInlineSemiAwaitable {
Awaitable awaitable_;
};
class NestingCounter {
public:
struct GuardDestructor {
void operator()(NestingCounter* counter) { --counter->counter_; }
};
using Guard = std::unique_ptr<NestingCounter, GuardDestructor>;
Guard guard() {
const size_t maxNestingDepth = 128;
if (counter_ + 1 == maxNestingDepth) {
return nullptr;
}
++counter_;
return Guard{this};
}
private:
size_t counter_{0};
};
using NestingCounterSingleton = SingletonThreadLocal<NestingCounter>;
template <typename Promise>
FOLLY_ALWAYS_INLINE folly::conditional_t<
kIsSanitizeThread,
void,
std::experimental::coroutine_handle<Promise>>
symmetricTransferMaybeReschedule(
std::experimental::coroutine_handle<Promise> ch,
const Executor::KeepAlive<>& ex) {
if constexpr (kIsSanitizeThread) {
if (auto nestingGuard = NestingCounterSingleton::get().guard()) {
ch.resume();
} else {
copy(ex).add([ch, rctx = RequestContext::saveContext()](
Executor::KeepAlive<>&&) mutable {
RequestContextScopeGuard guard(std::move(rctx));
ch.resume();
});
}
} else {
return ch;
}
}
} // namespace detail
} // namespace coro
} // namespace folly
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