/*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2014-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#ifdef __APPLE__
#include <folly/ThreadLocal.h>
#endif
+#include <folly/Try.h>
#include <folly/fibers/Baton.h>
#include <folly/fibers/Fiber.h>
#include <folly/fibers/LoopController.h>
#include <folly/fibers/Promise.h>
-#include <folly/Try.h>
namespace folly {
namespace fibers {
namespace {
inline FiberManager::Options preprocessOptions(FiberManager::Options opts) {
-#ifdef FOLLY_SANITIZE_ADDRESS
- /* ASAN needs a lot of extra stack space.
+#if defined(FOLLY_SANITIZE_ADDRESS) || defined(UNDEFINED_SANITIZER) || \
+ defined(FOLLY_SANITIZE_THREAD)
+ /* Sanitizers need a lot of extra stack space.
16x is a conservative estimate, 8x also worked with tests
where it mattered. Note that overallocating here does not necessarily
increase RSS, since unused memory is pretty much free. */
return opts;
}
-} // anonymous
+} // namespace
inline void FiberManager::ensureLoopScheduled() {
if (isLoopScheduled_) {
DCHECK(fiber->asanMainStackBase_);
DCHECK(fiber->asanMainStackSize_);
- // Release fake stack if fiber is completed
- auto saveFakeStackPtr =
- fiber->state_ == Fiber::INVALID ? nullptr : &fiber->asanFakeStack_;
registerStartSwitchStackWithAsan(
- saveFakeStackPtr, fiber->asanMainStackBase_, fiber->asanMainStackSize_);
+ &fiber->asanFakeStack_,
+ fiber->asanMainStackBase_,
+ fiber->asanMainStackSize_);
SCOPE_EXIT {
registerFinishSwitchStackWithAsan(
fiber->asanFakeStack_,
}
}
-inline bool FiberManager::loopUntilNoReady() {
+inline void FiberManager::loopUntilNoReady() {
+ return loopController_->runLoop();
+}
+
+inline void FiberManager::loopUntilNoReadyImpl() {
#ifndef _WIN32
if (UNLIKELY(!alternateSignalStackRegistered_)) {
registerAlternateSignalStack();
}
}
readyFibers_.splice(readyFibers_.end(), yieldedFibers_);
-
- return fibersActive_ > 0;
}
// We need this to be in a struct, not inlined in addTask, because clang crashes
auto currentFm = getFiberManagerUnsafe();
if (currentFm && currentFm->currentFiber_ &&
currentFm->localType_ == localType_) {
- return folly::make_unique<RemoteTask>(
+ return std::make_unique<RemoteTask>(
std::forward<F>(func), currentFm->currentFiber_->localData_);
}
- return folly::make_unique<RemoteTask>(std::forward<F>(func));
+ return std::make_unique<RemoteTask>(std::forward<F>(func));
}();
auto insertHead = [&]() {
return remoteTaskQueue_.insertHead(task.release());
return Promise<Result, BatonT>::await(std::forward<F>(func));
}
-}
-}
+} // namespace fibers
+} // namespace folly