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 @@ ...@@ -26,7 +26,6 @@
#include <folly/experimental/coro/Utils.h> #include <folly/experimental/coro/Utils.h>
#include <folly/experimental/coro/ViaIfAsync.h> #include <folly/experimental/coro/ViaIfAsync.h>
#include <folly/experimental/coro/WithCancellation.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/Malloc.h>
#include <folly/experimental/coro/detail/ManualLifetime.h> #include <folly/experimental/coro/detail/ManualLifetime.h>
...@@ -51,8 +50,9 @@ class AsyncGeneratorPromise { ...@@ -51,8 +50,9 @@ class AsyncGeneratorPromise {
bool await_ready() noexcept { return false; } bool await_ready() noexcept { return false; }
auto await_suspend( auto await_suspend(
std::experimental::coroutine_handle<AsyncGeneratorPromise> h) noexcept { std::experimental::coroutine_handle<AsyncGeneratorPromise> h) noexcept {
return symmetricTransferMaybeReschedule( auto& promise = h.promise();
h.promise().continuation_, h.promise().clearContext()); promise.clearContext();
return promise.continuation_;
} }
void await_resume() noexcept {} void await_resume() noexcept {}
}; };
...@@ -211,12 +211,10 @@ class AsyncGeneratorPromise { ...@@ -211,12 +211,10 @@ class AsyncGeneratorPromise {
bool hasValue() const noexcept { return state_ == State::VALUE; } bool hasValue() const noexcept { return state_ == State::VALUE; }
private: private:
folly::Executor::KeepAlive<> clearContext() noexcept { void clearContext() noexcept {
auto executor = std::exchange(executor_, {}); executor_ = {};
cancelToken_ = {}; cancelToken_ = {};
hasCancelTokenOverride_ = false; hasCancelTokenOverride_ = false;
return executor;
} }
enum class State : std::uint8_t { enum class State : std::uint8_t {
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include <folly/experimental/coro/Utils.h> #include <folly/experimental/coro/Utils.h>
#include <folly/experimental/coro/ViaIfAsync.h> #include <folly/experimental/coro/ViaIfAsync.h>
#include <folly/experimental/coro/WithCancellation.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/InlineTask.h>
#include <folly/experimental/coro/detail/Malloc.h> #include <folly/experimental/coro/detail/Malloc.h>
#include <folly/experimental/coro/detail/Traits.h> #include <folly/experimental/coro/detail/Traits.h>
...@@ -78,11 +77,9 @@ class TaskPromiseBase { ...@@ -78,11 +77,9 @@ class TaskPromiseBase {
bool await_ready() noexcept { return false; } bool await_ready() noexcept { return false; }
template <typename Promise> template <typename Promise>
auto await_suspend( std::experimental::coroutine_handle<> await_suspend(
std::experimental::coroutine_handle<Promise> coro) noexcept { std::experimental::coroutine_handle<Promise> coro) noexcept {
TaskPromiseBase& promise = coro.promise(); return coro.promise().continuation_;
return symmetricTransferMaybeReschedule(
promise.continuation_, promise.executor_);
} }
[[noreturn]] void await_resume() noexcept { folly::assume_unreachable(); } [[noreturn]] void await_resume() noexcept { folly::assume_unreachable(); }
...@@ -563,10 +560,10 @@ class FOLLY_NODISCARD Task { ...@@ -563,10 +560,10 @@ class FOLLY_NODISCARD Task {
bool await_ready() noexcept { return false; } bool await_ready() noexcept { return false; }
auto await_suspend( handle_t await_suspend(
std::experimental::coroutine_handle<> continuation) noexcept { std::experimental::coroutine_handle<> continuation) noexcept {
coro_.promise().continuation_ = continuation; coro_.promise().continuation_ = continuation;
return symmetricTransferMaybeReschedule(coro_, coro_.promise().executor_); return coro_;
} }
T await_resume() { return await_resume_try().value(); } T await_resume() { return await_resume_try().value(); }
......
...@@ -42,48 +42,6 @@ class UnsafeResumeInlineSemiAwaitable { ...@@ -42,48 +42,6 @@ class UnsafeResumeInlineSemiAwaitable {
Awaitable awaitable_; 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 detail
} // namespace coro } // namespace coro
} // namespace folly } // 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