From 2622d2f39e85027b0b8baef693510ef4222818a1 Mon Sep 17 00:00:00 2001 From: Andrii Grynenko Date: Wed, 18 May 2016 22:57:40 -0700 Subject: [PATCH] Move fibers out of experimental Summary: folly::fibers have been used by mcrouter for more than 2 years, so not really experimental. Reviewed By: pavlo-fb Differential Revision: D3320595 fbshipit-source-id: 68188f92b71a4206d57222993848521ca5437ef5 --- folly/Makefile.am | 64 +++++++++---------- .../{experimental => }/fibers/AddTasks-inl.h | 0 folly/{experimental => }/fibers/AddTasks.h | 6 +- folly/{experimental => }/fibers/Baton-inl.h | 4 +- folly/{experimental => }/fibers/Baton.cpp | 2 +- folly/{experimental => }/fibers/Baton.h | 4 +- .../fibers/BoostContextCompatibility.h | 0 .../fibers/EventBaseLoopController-inl.h | 4 +- .../fibers/EventBaseLoopController.h | 2 +- folly/{experimental => }/fibers/Fiber-inl.h | 0 folly/{experimental => }/fibers/Fiber.cpp | 4 +- folly/{experimental => }/fibers/Fiber.h | 8 +-- .../fibers/FiberManager-inl.h | 8 +-- .../fibers/FiberManager.cpp | 4 +- .../{experimental => }/fibers/FiberManager.h | 10 +-- .../fibers/FiberManagerMap.cpp | 0 .../fibers/FiberManagerMap.h | 4 +- folly/{experimental => }/fibers/ForEach-inl.h | 2 +- folly/{experimental => }/fibers/ForEach.h | 2 +- .../{experimental => }/fibers/GenericBaton.h | 2 +- .../fibers/GuardPageAllocator.cpp | 0 .../fibers/GuardPageAllocator.h | 0 .../fibers/LoopController.h | 0 folly/{experimental => }/fibers/Promise-inl.h | 2 +- folly/{experimental => }/fibers/Promise.h | 4 +- folly/{experimental => }/fibers/README.md | 46 ++++++------- .../fibers/SimpleLoopController.h | 2 +- .../fibers/TimedMutex-inl.h | 0 folly/{experimental => }/fibers/TimedMutex.h | 2 +- .../fibers/TimeoutController.cpp | 0 .../fibers/TimeoutController.h | 2 +- folly/{experimental => }/fibers/WhenN-inl.h | 4 +- folly/{experimental => }/fibers/WhenN.h | 2 +- .../fibers/scripts/utils.gdb | 0 .../fibers/test/FibersTest.cpp | 14 ++-- .../fibers/test/FibersTestApp.cpp | 4 +- .../fibers/test/StackOverflow.cpp | 2 +- folly/{experimental => }/fibers/test/main.cpp | 0 folly/{experimental => }/fibers/traits.h | 0 folly/futures/Future-inl.h | 2 +- 40 files changed, 108 insertions(+), 108 deletions(-) rename folly/{experimental => }/fibers/AddTasks-inl.h (100%) rename folly/{experimental => }/fibers/AddTasks.h (95%) rename folly/{experimental => }/fibers/Baton-inl.h (96%) rename folly/{experimental => }/fibers/Baton.cpp (98%) rename folly/{experimental => }/fibers/Baton.h (98%) rename folly/{experimental => }/fibers/BoostContextCompatibility.h (100%) rename folly/{experimental => }/fibers/EventBaseLoopController-inl.h (96%) rename folly/{experimental => }/fibers/EventBaseLoopController.h (98%) rename folly/{experimental => }/fibers/Fiber-inl.h (100%) rename folly/{experimental => }/fibers/Fiber.cpp (98%) rename folly/{experimental => }/fibers/Fiber.h (97%) rename folly/{experimental => }/fibers/FiberManager-inl.h (98%) rename folly/{experimental => }/fibers/FiberManager.cpp (98%) rename folly/{experimental => }/fibers/FiberManager.h (98%) rename folly/{experimental => }/fibers/FiberManagerMap.cpp (100%) rename folly/{experimental => }/fibers/FiberManagerMap.h (87%) rename folly/{experimental => }/fibers/ForEach-inl.h (97%) rename folly/{experimental => }/fibers/ForEach.h (96%) rename folly/{experimental => }/fibers/GenericBaton.h (94%) rename folly/{experimental => }/fibers/GuardPageAllocator.cpp (100%) rename folly/{experimental => }/fibers/GuardPageAllocator.h (100%) rename folly/{experimental => }/fibers/LoopController.h (100%) rename folly/{experimental => }/fibers/Promise-inl.h (98%) rename folly/{experimental => }/fibers/Promise.h (96%) rename folly/{experimental => }/fibers/README.md (97%) rename folly/{experimental => }/fibers/SimpleLoopController.h (97%) rename folly/{experimental => }/fibers/TimedMutex-inl.h (100%) rename folly/{experimental => }/fibers/TimedMutex.h (99%) rename folly/{experimental => }/fibers/TimeoutController.cpp (100%) rename folly/{experimental => }/fibers/TimeoutController.h (97%) rename folly/{experimental => }/fibers/WhenN-inl.h (98%) rename folly/{experimental => }/fibers/WhenN.h (98%) rename folly/{experimental => }/fibers/scripts/utils.gdb (100%) rename folly/{experimental => }/fibers/test/FibersTest.cpp (99%) rename folly/{experimental => }/fibers/test/FibersTestApp.cpp (95%) rename folly/{experimental => }/fibers/test/StackOverflow.cpp (95%) rename folly/{experimental => }/fibers/test/main.cpp (100%) rename folly/{experimental => }/fibers/traits.h (100%) diff --git a/folly/Makefile.am b/folly/Makefile.am index bc7e42d4d38..1cc7a2ee193 100644 --- a/folly/Makefile.am +++ b/folly/Makefile.am @@ -96,32 +96,32 @@ nobase_follyinclude_HEADERS = \ experimental/EventCount.h \ experimental/Instructions.h \ experimental/bser/Bser.h \ - experimental/fibers/AddTasks.h \ - experimental/fibers/AddTasks-inl.h \ - experimental/fibers/Baton.h \ - experimental/fibers/Baton-inl.h \ - experimental/fibers/BoostContextCompatibility.h \ - experimental/fibers/EventBaseLoopController.h \ - experimental/fibers/EventBaseLoopController-inl.h \ - experimental/fibers/Fiber.h \ - experimental/fibers/Fiber-inl.h \ - experimental/fibers/FiberManager.h \ - experimental/fibers/FiberManager-inl.h \ - experimental/fibers/FiberManagerMap.h \ - experimental/fibers/ForEach.h \ - experimental/fibers/ForEach-inl.h \ - experimental/fibers/GenericBaton.h \ - experimental/fibers/GuardPageAllocator.h \ - experimental/fibers/LoopController.h \ - experimental/fibers/Promise.h \ - experimental/fibers/Promise-inl.h \ - experimental/fibers/SimpleLoopController.h \ - experimental/fibers/TimedMutex.h \ - experimental/fibers/TimedMutex-inl.h \ - experimental/fibers/TimeoutController.h \ - experimental/fibers/traits.h \ - experimental/fibers/WhenN.h \ - experimental/fibers/WhenN-inl.h \ + fibers/AddTasks.h \ + fibers/AddTasks-inl.h \ + fibers/Baton.h \ + fibers/Baton-inl.h \ + fibers/BoostContextCompatibility.h \ + fibers/EventBaseLoopController.h \ + fibers/EventBaseLoopController-inl.h \ + fibers/Fiber.h \ + fibers/Fiber-inl.h \ + fibers/FiberManager.h \ + fibers/FiberManager-inl.h \ + fibers/FiberManagerMap.h \ + fibers/ForEach.h \ + fibers/ForEach-inl.h \ + fibers/GenericBaton.h \ + fibers/GuardPageAllocator.h \ + fibers/LoopController.h \ + fibers/Promise.h \ + fibers/Promise-inl.h \ + fibers/SimpleLoopController.h \ + fibers/TimedMutex.h \ + fibers/TimedMutex-inl.h \ + fibers/TimeoutController.h \ + fibers/traits.h \ + fibers/WhenN.h \ + fibers/WhenN-inl.h \ experimental/FunctionScheduler.h \ experimental/FutureDAG.h \ experimental/io/FsUtil.h \ @@ -464,12 +464,12 @@ libfolly_la_SOURCES = \ experimental/bser/Dump.cpp \ experimental/bser/Load.cpp \ experimental/DynamicParser.cpp \ - experimental/fibers/Baton.cpp \ - experimental/fibers/Fiber.cpp \ - experimental/fibers/FiberManager.cpp \ - experimental/fibers/FiberManagerMap.cpp \ - experimental/fibers/GuardPageAllocator.cpp \ - experimental/fibers/TimeoutController.cpp \ + fibers/Baton.cpp \ + fibers/Fiber.cpp \ + fibers/FiberManager.cpp \ + fibers/FiberManagerMap.cpp \ + fibers/GuardPageAllocator.cpp \ + fibers/TimeoutController.cpp \ experimental/FunctionScheduler.cpp \ experimental/io/FsUtil.cpp \ experimental/JSONSchema.cpp \ diff --git a/folly/experimental/fibers/AddTasks-inl.h b/folly/fibers/AddTasks-inl.h similarity index 100% rename from folly/experimental/fibers/AddTasks-inl.h rename to folly/fibers/AddTasks-inl.h diff --git a/folly/experimental/fibers/AddTasks.h b/folly/fibers/AddTasks.h similarity index 95% rename from folly/experimental/fibers/AddTasks.h rename to folly/fibers/AddTasks.h index 1062b9b8b18..9e65fcce447 100644 --- a/folly/experimental/fibers/AddTasks.h +++ b/folly/fibers/AddTasks.h @@ -19,8 +19,8 @@ #include #include -#include -#include +#include +#include #include namespace folly { @@ -131,4 +131,4 @@ class TaskIterator { } } -#include +#include diff --git a/folly/experimental/fibers/Baton-inl.h b/folly/fibers/Baton-inl.h similarity index 96% rename from folly/experimental/fibers/Baton-inl.h rename to folly/fibers/Baton-inl.h index b4933ca1d7d..6ca2de93935 100644 --- a/folly/experimental/fibers/Baton-inl.h +++ b/folly/fibers/Baton-inl.h @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include +#include +#include namespace folly { namespace fibers { diff --git a/folly/experimental/fibers/Baton.cpp b/folly/fibers/Baton.cpp similarity index 98% rename from folly/experimental/fibers/Baton.cpp rename to folly/fibers/Baton.cpp index a378483aa39..7161f9fb97f 100644 --- a/folly/experimental/fibers/Baton.cpp +++ b/folly/fibers/Baton.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include #include namespace folly { diff --git a/folly/experimental/fibers/Baton.h b/folly/fibers/Baton.h similarity index 98% rename from folly/experimental/fibers/Baton.h rename to folly/fibers/Baton.h index c2ee7044fc9..e5b92d1bdeb 100644 --- a/folly/experimental/fibers/Baton.h +++ b/folly/fibers/Baton.h @@ -18,7 +18,7 @@ #include #include -#include +#include namespace folly { namespace fibers { @@ -188,4 +188,4 @@ class Baton { } } -#include +#include diff --git a/folly/experimental/fibers/BoostContextCompatibility.h b/folly/fibers/BoostContextCompatibility.h similarity index 100% rename from folly/experimental/fibers/BoostContextCompatibility.h rename to folly/fibers/BoostContextCompatibility.h diff --git a/folly/experimental/fibers/EventBaseLoopController-inl.h b/folly/fibers/EventBaseLoopController-inl.h similarity index 96% rename from folly/experimental/fibers/EventBaseLoopController-inl.h rename to folly/fibers/EventBaseLoopController-inl.h index 30848e2ad50..c9109c993f5 100644 --- a/folly/experimental/fibers/EventBaseLoopController-inl.h +++ b/folly/fibers/EventBaseLoopController-inl.h @@ -14,8 +14,8 @@ * limitations under the License. */ #include -#include -#include +#include +#include namespace folly { namespace fibers { diff --git a/folly/experimental/fibers/EventBaseLoopController.h b/folly/fibers/EventBaseLoopController.h similarity index 98% rename from folly/experimental/fibers/EventBaseLoopController.h rename to folly/fibers/EventBaseLoopController.h index eaedb45ebbd..4d4ca9984b3 100644 --- a/folly/experimental/fibers/EventBaseLoopController.h +++ b/folly/fibers/EventBaseLoopController.h @@ -15,7 +15,7 @@ */ #pragma once -#include +#include #include #include #include diff --git a/folly/experimental/fibers/Fiber-inl.h b/folly/fibers/Fiber-inl.h similarity index 100% rename from folly/experimental/fibers/Fiber-inl.h rename to folly/fibers/Fiber-inl.h diff --git a/folly/experimental/fibers/Fiber.cpp b/folly/fibers/Fiber.cpp similarity index 98% rename from folly/experimental/fibers/Fiber.cpp rename to folly/fibers/Fiber.cpp index 54f086d1eab..bbbc5b8e720 100644 --- a/folly/experimental/fibers/Fiber.cpp +++ b/folly/fibers/Fiber.cpp @@ -25,8 +25,8 @@ #include #include -#include -#include +#include +#include #include namespace folly { diff --git a/folly/experimental/fibers/Fiber.h b/folly/fibers/Fiber.h similarity index 97% rename from folly/experimental/fibers/Fiber.h rename to folly/fibers/Fiber.h index f68df6ce22b..543deef8962 100644 --- a/folly/experimental/fibers/Fiber.h +++ b/folly/fibers/Fiber.h @@ -18,15 +18,15 @@ #include #include +#include +#include #include #include #include #include #include -#include +#include #include -#include -#include namespace folly { namespace fibers { @@ -189,4 +189,4 @@ class Fiber { } } -#include +#include diff --git a/folly/experimental/fibers/FiberManager-inl.h b/folly/fibers/FiberManager-inl.h similarity index 98% rename from folly/experimental/fibers/FiberManager-inl.h rename to folly/fibers/FiberManager-inl.h index a4783c5c645..6b4e94a1f05 100644 --- a/folly/experimental/fibers/FiberManager-inl.h +++ b/folly/fibers/FiberManager-inl.h @@ -25,10 +25,10 @@ #ifdef __APPLE__ #include #endif -#include -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/folly/experimental/fibers/FiberManager.cpp b/folly/fibers/FiberManager.cpp similarity index 98% rename from folly/experimental/fibers/FiberManager.cpp rename to folly/fibers/FiberManager.cpp index 2592ee1c97f..727b7d7fec3 100644 --- a/folly/experimental/fibers/FiberManager.cpp +++ b/folly/fibers/FiberManager.cpp @@ -24,8 +24,8 @@ #include -#include -#include +#include +#include #include diff --git a/folly/experimental/fibers/FiberManager.h b/folly/fibers/FiberManager.h similarity index 98% rename from folly/experimental/fibers/FiberManager.h rename to folly/fibers/FiberManager.h index aa250a74a64..a617dd6bce5 100644 --- a/folly/experimental/fibers/FiberManager.h +++ b/folly/fibers/FiberManager.h @@ -32,11 +32,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include namespace folly { diff --git a/folly/experimental/fibers/FiberManagerMap.cpp b/folly/fibers/FiberManagerMap.cpp similarity index 100% rename from folly/experimental/fibers/FiberManagerMap.cpp rename to folly/fibers/FiberManagerMap.cpp diff --git a/folly/experimental/fibers/FiberManagerMap.h b/folly/fibers/FiberManagerMap.h similarity index 87% rename from folly/experimental/fibers/FiberManagerMap.h rename to folly/fibers/FiberManagerMap.h index 8d233a8a750..b210b735b18 100644 --- a/folly/experimental/fibers/FiberManagerMap.h +++ b/folly/fibers/FiberManagerMap.h @@ -15,8 +15,8 @@ */ #pragma once -#include -#include +#include +#include namespace folly { namespace fibers { diff --git a/folly/experimental/fibers/ForEach-inl.h b/folly/fibers/ForEach-inl.h similarity index 97% rename from folly/experimental/fibers/ForEach-inl.h rename to folly/fibers/ForEach-inl.h index 85333b394b9..4c6df91a4e2 100644 --- a/folly/experimental/fibers/ForEach-inl.h +++ b/folly/fibers/ForEach-inl.h @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include +#include namespace folly { namespace fibers { diff --git a/folly/experimental/fibers/ForEach.h b/folly/fibers/ForEach.h similarity index 96% rename from folly/experimental/fibers/ForEach.h rename to folly/fibers/ForEach.h index ecbb63c0d52..f3e1c290c5c 100644 --- a/folly/experimental/fibers/ForEach.h +++ b/folly/fibers/ForEach.h @@ -41,4 +41,4 @@ inline void forEach(InputIterator first, InputIterator last, F&& f); } } // folly::fibers -#include +#include diff --git a/folly/experimental/fibers/GenericBaton.h b/folly/fibers/GenericBaton.h similarity index 94% rename from folly/experimental/fibers/GenericBaton.h rename to folly/fibers/GenericBaton.h index c87b58487dc..cf61ab6d78b 100644 --- a/folly/experimental/fibers/GenericBaton.h +++ b/folly/fibers/GenericBaton.h @@ -17,7 +17,7 @@ #include -#include +#include namespace folly { namespace fibers { diff --git a/folly/experimental/fibers/GuardPageAllocator.cpp b/folly/fibers/GuardPageAllocator.cpp similarity index 100% rename from folly/experimental/fibers/GuardPageAllocator.cpp rename to folly/fibers/GuardPageAllocator.cpp diff --git a/folly/experimental/fibers/GuardPageAllocator.h b/folly/fibers/GuardPageAllocator.h similarity index 100% rename from folly/experimental/fibers/GuardPageAllocator.h rename to folly/fibers/GuardPageAllocator.h diff --git a/folly/experimental/fibers/LoopController.h b/folly/fibers/LoopController.h similarity index 100% rename from folly/experimental/fibers/LoopController.h rename to folly/fibers/LoopController.h diff --git a/folly/experimental/fibers/Promise-inl.h b/folly/fibers/Promise-inl.h similarity index 98% rename from folly/experimental/fibers/Promise-inl.h rename to folly/fibers/Promise-inl.h index a50d81c7de6..2adaf781ab0 100644 --- a/folly/experimental/fibers/Promise-inl.h +++ b/folly/fibers/Promise-inl.h @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include +#include namespace folly { namespace fibers { diff --git a/folly/experimental/fibers/Promise.h b/folly/fibers/Promise.h similarity index 96% rename from folly/experimental/fibers/Promise.h rename to folly/fibers/Promise.h index 4dee6099c22..807898ef404 100644 --- a/folly/experimental/fibers/Promise.h +++ b/folly/fibers/Promise.h @@ -15,7 +15,7 @@ */ #pragma once -#include +#include #include namespace folly { @@ -101,4 +101,4 @@ class Promise { } } -#include +#include diff --git a/folly/experimental/fibers/README.md b/folly/fibers/README.md similarity index 97% rename from folly/experimental/fibers/README.md rename to folly/fibers/README.md index a691d56b3d4..3dfdef4adb6 100644 --- a/folly/experimental/fibers/README.md +++ b/folly/fibers/README.md @@ -15,13 +15,13 @@ fiberManager.addTask([&]() { std::cout << "Task 1: start" << std::endl; baton.wait(); - std::cout << "Task 1: after baton.wait()" << std::endl; + std::cout << "Task 1: after baton.wait()" << std::endl; }); fiberManager.addTask([&]() { std::cout << "Task 2: start" << std::endl; baton.post(); - std::cout << "Task 2: after baton.post()" << std::endl; + std::cout << "Task 2: after baton.post()" << std::endl; }); evb.loop(); @@ -76,7 +76,7 @@ fiberManager.addTask([&]() { std::cout << "Task: start" << std::endl; baton.wait(); - std::cout << "Task: after baton.wait()" << std::endl; + std::cout << "Task: after baton.wait()" << std::endl; }); evb.loop(); @@ -100,7 +100,7 @@

fibers::Baton is the core synchronization primitive which is used to suspend a fiber-task and notify when the task may be resumed. fibers::Baton supports two basic operations: wait() and post(). Calling wait() on a Baton will suspend current fiber-task until post() is called on the same Baton.

-

Please refer to Baton for more detailed documentation.

+

Please refer to Baton for more detailed documentation.

NOTE: fibers::Baton is the only native synchronization primitive of folly::fibers library. All other synchronization primitives provided by folly::fibers are built on top of fibers::Baton.
@@ -116,7 +116,7 @@ ... Response response; fibers::Baton baton; - + asyncCall(request, [&](Response r) mutable { response = std::move(r); baton.post(); @@ -175,7 +175,7 @@ ... } -

Please refer to await for more detailed documentation.

+

Please refer to await for more detailed documentation.

NOTE: most of your code written with folly::fibers, won't be using fibers::Baton or fibers::await. These primitives should only be used to integrate with other asynchronous API which are not fibers-compatible.
@@ -190,7 +190,7 @@
fiberManager.addTask([]() {
   ...
   auto response = asyncCallFuture(request).get();
-  
+
   // Now response holds response returned by the async call
   ...
 }
@@ -229,7 +229,7 @@
...
 Context context;
- 
+
 asyncCall(request, [request, context](Response response) mutable {
   doSomething(request, response, context);
 });
@@ -242,7 +242,7 @@
   Context context;
 
   auto response = fiberCall(request);
- 
+
   doSomething(request, response, context);
   ...
 });
@@ -308,10 +308,10 @@

First fiber-task will grab a lock and then suspend waiting on a fibers::Baton. Then second fiber-task will be run and it will try to grab a lock. Unlike system threads, fiber-task can be only suspended explicitly, so the whole system thread will be blocked waiting on the lock, and we end up with a dead-lock.

-

There're generally two ways we can solve this problem. Ideally we would re-design the program to never not hold any locks when fiber-task is suspended. However if we are absolutely sure we need that lock - folly::fibers library provides some fiber-task-aware lock implementations (e.g. -TimedMutex).

APIs

fibers::Baton #

+

There're generally two ways we can solve this problem. Ideally we would re-design the program to never not hold any locks when fiber-task is suspended. However if we are absolutely sure we need that lock - folly::fibers library provides some fiber-task-aware lock implementations (e.g. +TimedMutex).

APIs

fibers::Baton #

-

All of the features of folly::fibers library are actually built on top a single synchronization primitive called Baton. fibers::Baton is a fiber-specific version of folly::Baton. It only supports two basic operations: wait() and post(). Whenever wait() is called on the Baton, the current thread or fiber-task is suspended, until post() is called on the same Baton. wait() does not suspend the thread or fiber-task if post() was already called on the Baton. Please refer to Baton for more detailed documentation.

+

All of the features of folly::fibers library are actually built on top a single synchronization primitive called Baton. fibers::Baton is a fiber-specific version of folly::Baton. It only supports two basic operations: wait() and post(). Whenever wait() is called on the Baton, the current thread or fiber-task is suspended, until post() is called on the same Baton. wait() does not suspend the thread or fiber-task if post() was already called on the Baton. Please refer to Baton for more detailed documentation.

Baton is thread-safe, so wait() and post() can be (and should be :) ) called from different threads or fiber-tasks.

@@ -410,7 +410,7 @@ }); auto future2 = fiberManager.addTaskRemoteFuture([]() { ... - }); + }); auto result1 = future1.get(); auto result2 = future2.get(); @@ -423,21 +423,21 @@

All the listed synchronization primitives are built using fiber::Baton. Please check their source code for detailed documentation.

-

await

+

await

-

collectN

+

collectN

-

collectAny

+

collectAny

-

collectN

+

collectN

-

forEach

+

forEach

-

addTasks

+

addTasks

-

TimedMutex

+

TimedMutex

-

TimedRWMutex

Fiber stacks

Similarly to system threads, every fiber-task has some stack space assigned to it. Stack usage goes up with the number of nested function calls and objects allocated on the stack. folly::fibers implementation only supports fiber-tasks with fixed stack size. If you want to have many fiber-tasks running concurrently - you need to reduce the amount of stack assigned to each fiber-task, otherwise you may run out of memory.

+

TimedRWMutex

Fiber stacks

Similarly to system threads, every fiber-task has some stack space assigned to it. Stack usage goes up with the number of nested function calls and objects allocated on the stack. folly::fibers implementation only supports fiber-tasks with fixed stack size. If you want to have many fiber-tasks running concurrently - you need to reduce the amount of stack assigned to each fiber-task, otherwise you may run out of memory.

Selecting stack size #

@@ -470,7 +470,7 @@
NOTE: folly::fibers doesn't support killing fiber-tasks in-flight (for similar reasons you can't kill a thread). If fibers::FiberManager has any outstanding fiber-tasks, when folly::EventBase is being destroyed, it will keep running the event loop until all those tasks are finished.

GDB integration

folly::fibers provide some GDB extensions which can be very useful for debugging. To load them simply the following in dbg console:

-
source 'folly/experimental/fibers/scripts/utils.gdb'
+
source 'folly/fibers/scripts/utils.gdb'

Show all FiberManagers #

@@ -541,7 +541,7 @@ #6 at 0x415e9a in FiberManager_collectAll_Test::TestBody()::{lambda()#1}::operator()() const::{lambda()#1}::operator()() const::{lambda()#1}::operator()( ) const + 36 in section .text of /mnt/fio0/andrii/fbsource/fbcode/buck-out/gen/folly/experimental/fibers/fibers-test #7 at 0x42faf9 in std::_Function_handler<int (), FiberManager_collectAll_Test::TestBody()::{lambda()#1}::operator()() const::{lambda()#1}::operator()() c -onst::{lambda()#1}>::_M_invoke(std::_Any_data const&) + 32 in section .text of /mnt/fio0/andrii/fbsource/fbcode/buck-out/gen/folly/experimental/fibers/fibers +onst::{lambda()#1}>::_M_invoke(std::_Any_data const&) + 32 in section .text of /mnt/fio0/andrii/fbsource/fbcode/buck-out/gen/folly/fibers/fibers -test #8 at 0x479d5c in std::function<int ()>::operator()() const + 50 in section .text of /mnt/fio0/andrii/fbsource/fbcode/buck-out/gen/folly/experimental/fib ers/fibers-test diff --git a/folly/experimental/fibers/SimpleLoopController.h b/folly/fibers/SimpleLoopController.h similarity index 97% rename from folly/experimental/fibers/SimpleLoopController.h rename to folly/fibers/SimpleLoopController.h index 94ae9a7702c..8c728bd6e5d 100644 --- a/folly/experimental/fibers/SimpleLoopController.h +++ b/folly/fibers/SimpleLoopController.h @@ -17,7 +17,7 @@ #include -#include +#include namespace folly { namespace fibers { diff --git a/folly/experimental/fibers/TimedMutex-inl.h b/folly/fibers/TimedMutex-inl.h similarity index 100% rename from folly/experimental/fibers/TimedMutex-inl.h rename to folly/fibers/TimedMutex-inl.h diff --git a/folly/experimental/fibers/TimedMutex.h b/folly/fibers/TimedMutex.h similarity index 99% rename from folly/experimental/fibers/TimedMutex.h rename to folly/fibers/TimedMutex.h index a697b2f5cb7..e21f246cca4 100644 --- a/folly/experimental/fibers/TimedMutex.h +++ b/folly/fibers/TimedMutex.h @@ -17,7 +17,7 @@ #include -#include +#include namespace folly { namespace fibers { diff --git a/folly/experimental/fibers/TimeoutController.cpp b/folly/fibers/TimeoutController.cpp similarity index 100% rename from folly/experimental/fibers/TimeoutController.cpp rename to folly/fibers/TimeoutController.cpp diff --git a/folly/experimental/fibers/TimeoutController.h b/folly/fibers/TimeoutController.h similarity index 97% rename from folly/experimental/fibers/TimeoutController.h rename to folly/fibers/TimeoutController.h index 0f2dced9ce4..4b06009409c 100644 --- a/folly/experimental/fibers/TimeoutController.h +++ b/folly/fibers/TimeoutController.h @@ -24,7 +24,7 @@ #include -#include +#include namespace folly { namespace fibers { diff --git a/folly/experimental/fibers/WhenN-inl.h b/folly/fibers/WhenN-inl.h similarity index 98% rename from folly/experimental/fibers/WhenN-inl.h rename to folly/fibers/WhenN-inl.h index 6bb280489f9..4c49da8c289 100644 --- a/folly/experimental/fibers/WhenN-inl.h +++ b/folly/fibers/WhenN-inl.h @@ -15,8 +15,8 @@ */ #include -#include -#include +#include +#include namespace folly { namespace fibers { diff --git a/folly/experimental/fibers/WhenN.h b/folly/fibers/WhenN.h similarity index 98% rename from folly/experimental/fibers/WhenN.h rename to folly/fibers/WhenN.h index a12e12f2da0..6f54babad41 100644 --- a/folly/experimental/fibers/WhenN.h +++ b/folly/fibers/WhenN.h @@ -136,4 +136,4 @@ typename std::enable_if< } } -#include +#include diff --git a/folly/experimental/fibers/scripts/utils.gdb b/folly/fibers/scripts/utils.gdb similarity index 100% rename from folly/experimental/fibers/scripts/utils.gdb rename to folly/fibers/scripts/utils.gdb diff --git a/folly/experimental/fibers/test/FibersTest.cpp b/folly/fibers/test/FibersTest.cpp similarity index 99% rename from folly/experimental/fibers/test/FibersTest.cpp rename to folly/fibers/test/FibersTest.cpp index f4db1f6fc2a..e5762af141b 100644 --- a/folly/experimental/fibers/test/FibersTest.cpp +++ b/folly/fibers/test/FibersTest.cpp @@ -23,13 +23,13 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include using namespace folly::fibers; diff --git a/folly/experimental/fibers/test/FibersTestApp.cpp b/folly/fibers/test/FibersTestApp.cpp similarity index 95% rename from folly/experimental/fibers/test/FibersTestApp.cpp rename to folly/fibers/test/FibersTestApp.cpp index 44617ac7577..96a7df476f7 100644 --- a/folly/experimental/fibers/test/FibersTestApp.cpp +++ b/folly/fibers/test/FibersTestApp.cpp @@ -18,8 +18,8 @@ #include -#include -#include +#include +#include using namespace folly::fibers; diff --git a/folly/experimental/fibers/test/StackOverflow.cpp b/folly/fibers/test/StackOverflow.cpp similarity index 95% rename from folly/experimental/fibers/test/StackOverflow.cpp rename to folly/fibers/test/StackOverflow.cpp index d8462e1ea36..8cbd4d09f69 100644 --- a/folly/experimental/fibers/test/StackOverflow.cpp +++ b/folly/fibers/test/StackOverflow.cpp @@ -13,8 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include #include +#include #include void f(int* p) { diff --git a/folly/experimental/fibers/test/main.cpp b/folly/fibers/test/main.cpp similarity index 100% rename from folly/experimental/fibers/test/main.cpp rename to folly/fibers/test/main.cpp diff --git a/folly/experimental/fibers/traits.h b/folly/fibers/traits.h similarity index 100% rename from folly/experimental/fibers/traits.h rename to folly/fibers/traits.h diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h index aebe58b6521..094ccdc0ece 100644 --- a/folly/futures/Future-inl.h +++ b/folly/futures/Future-inl.h @@ -32,7 +32,7 @@ #define FOLLY_FUTURE_USING_FIBER 0 #else #define FOLLY_FUTURE_USING_FIBER 1 -#include +#include #endif namespace folly {