Fix incorrect usages of folly::Synchronized
[folly.git] / folly / fibers / FiberManagerInternal-inl.h
index 4c8878ba202a011e36f66d94c72cb6dc63945e47..e8b36ccb4f2edbf869d881d76c9f9ec70d47af9a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 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 {
@@ -37,8 +37,9 @@ 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. */
@@ -47,7 +48,7 @@ inline FiberManager::Options preprocessOptions(FiberManager::Options opts) {
   return opts;
 }
 
-} // anonymous
+} // namespace
 
 inline void FiberManager::ensureLoopScheduled() {
   if (isLoopScheduled_) {
@@ -85,11 +86,10 @@ inline void FiberManager::deactivateFiber(Fiber* fiber) {
   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_,
@@ -185,7 +185,11 @@ inline void FiberManager::runReadyFiber(Fiber* fiber) {
   }
 }
 
-inline bool FiberManager::loopUntilNoReady() {
+inline void FiberManager::loopUntilNoReady() {
+  return loopController_->runLoop();
+}
+
+inline void FiberManager::loopUntilNoReadyImpl() {
 #ifndef _WIN32
   if (UNLIKELY(!alternateSignalStackRegistered_)) {
     registerAlternateSignalStack();
@@ -243,8 +247,6 @@ inline bool FiberManager::loopUntilNoReady() {
     }
   }
   readyFibers_.splice(readyFibers_.end(), yieldedFibers_);
-
-  return fibersActive_ > 0;
 }
 
 // We need this to be in a struct, not inlined in addTask, because clang crashes
@@ -312,10 +314,10 @@ void FiberManager::addTaskRemote(F&& func) {
     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());
@@ -539,5 +541,5 @@ typename FirstArgOf<F>::type::value_type inline await(F&& func) {
 
   return Promise<Result, BatonT>::await(std::forward<F>(func));
 }
-}
-}
+} // namespace fibers
+} // namespace folly