Commit 811c6c33 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Apply clang-format to folly/fibers/

Summary:
[Folly] Apply `clang-format` to `folly/fibers/`

With some manual rearrangement in the places where `clang-format` does awkward things, with the result that `clang-format` over `folly/fibers/` becomes a no-op.

Reviewed By: igorsugak

Differential Revision: D5178118

fbshipit-source-id: ae65ff1902666ba9106e18f916bb1d10e6406bf4
parent 146c24b7
...@@ -19,9 +19,9 @@ ...@@ -19,9 +19,9 @@
#include <vector> #include <vector>
#include <folly/Optional.h> #include <folly/Optional.h>
#include <folly/Try.h>
#include <folly/fibers/FiberManagerInternal.h> #include <folly/fibers/FiberManagerInternal.h>
#include <folly/fibers/Promise.h> #include <folly/fibers/Promise.h>
#include <folly/Try.h>
namespace folly { namespace folly {
namespace fibers { namespace fibers {
......
...@@ -154,7 +154,7 @@ class Baton { ...@@ -154,7 +154,7 @@ class Baton {
PreBlockAttempts = 300, PreBlockAttempts = 300,
}; };
explicit Baton(intptr_t state) : waitingFiber_(state){} explicit Baton(intptr_t state) : waitingFiber_(state) {}
void postHelper(intptr_t new_value); void postHelper(intptr_t new_value);
void postThread(); void postThread();
......
...@@ -107,7 +107,6 @@ class EventBaseLoopController : public LoopController { ...@@ -107,7 +107,6 @@ class EventBaseLoopController : public LoopController {
friend class FiberManager; friend class FiberManager;
}; };
} }
} // folly::fibers } // folly::fibers
......
...@@ -254,8 +254,9 @@ static AsanStartSwitchStackFuncPtr getStartSwitchStackFunc() { ...@@ -254,8 +254,9 @@ static AsanStartSwitchStackFuncPtr getStartSwitchStackFunc() {
} }
// Check whether we can find a dynamically linked enter function // Check whether we can find a dynamically linked enter function
if (nullptr != (fn = (AsanStartSwitchStackFuncPtr)dlsym( if (nullptr !=
RTLD_DEFAULT, "__sanitizer_start_switch_fiber"))) { (fn = (AsanStartSwitchStackFuncPtr)dlsym(
RTLD_DEFAULT, "__sanitizer_start_switch_fiber"))) {
return fn; return fn;
} }
...@@ -272,8 +273,9 @@ static AsanFinishSwitchStackFuncPtr getFinishSwitchStackFunc() { ...@@ -272,8 +273,9 @@ static AsanFinishSwitchStackFuncPtr getFinishSwitchStackFunc() {
} }
// Check whether we can find a dynamically linked exit function // Check whether we can find a dynamically linked exit function
if (nullptr != (fn = (AsanFinishSwitchStackFuncPtr)dlsym( if (nullptr !=
RTLD_DEFAULT, "__sanitizer_finish_switch_fiber"))) { (fn = (AsanFinishSwitchStackFuncPtr)dlsym(
RTLD_DEFAULT, "__sanitizer_finish_switch_fiber"))) {
return fn; return fn;
} }
...@@ -290,8 +292,9 @@ static AsanUnpoisonMemoryRegionFuncPtr getUnpoisonMemoryRegionFunc() { ...@@ -290,8 +292,9 @@ static AsanUnpoisonMemoryRegionFuncPtr getUnpoisonMemoryRegionFunc() {
} }
// Check whether we can find a dynamically linked unpoison function // Check whether we can find a dynamically linked unpoison function
if (nullptr != (fn = (AsanUnpoisonMemoryRegionFuncPtr)dlsym( if (nullptr !=
RTLD_DEFAULT, "__asan_unpoison_memory_region"))) { (fn = (AsanUnpoisonMemoryRegionFuncPtr)dlsym(
RTLD_DEFAULT, "__asan_unpoison_memory_region"))) {
return fn; return fn;
} }
......
...@@ -16,4 +16,5 @@ ...@@ -16,4 +16,5 @@
#pragma once #pragma once
#include <folly/fibers/FiberManagerInternal.h> #include <folly/fibers/FiberManagerInternal.h>
#include <folly/fibers/FiberManager-inl.h> #include <folly/fibers/FiberManager-inl.h>
...@@ -25,11 +25,11 @@ ...@@ -25,11 +25,11 @@
#ifdef __APPLE__ #ifdef __APPLE__
#include <folly/ThreadLocal.h> #include <folly/ThreadLocal.h>
#endif #endif
#include <folly/Try.h>
#include <folly/fibers/Baton.h> #include <folly/fibers/Baton.h>
#include <folly/fibers/Fiber.h> #include <folly/fibers/Fiber.h>
#include <folly/fibers/LoopController.h> #include <folly/fibers/LoopController.h>
#include <folly/fibers/Promise.h> #include <folly/fibers/Promise.h>
#include <folly/Try.h>
namespace folly { namespace folly {
namespace fibers { namespace fibers {
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
*/ */
#pragma once #pragma once
#include <folly/fibers/traits.h>
#include <folly/Try.h> #include <folly/Try.h>
#include <folly/fibers/traits.h>
namespace folly { namespace folly {
namespace fibers { namespace fibers {
......
...@@ -330,21 +330,20 @@ TEST(FiberManager, awaitThrow) { ...@@ -330,21 +330,20 @@ TEST(FiberManager, awaitThrow) {
getFiberManager(evb) getFiberManager(evb)
.addTaskFuture([&] { .addTaskFuture([&] {
EXPECT_THROW( EXPECT_THROW(
await([](Promise<int> p) { await([](Promise<int> p) {
p.setValue(42); p.setValue(42);
throw ExpectedException(); throw ExpectedException();
}), }),
ExpectedException ExpectedException);
);
EXPECT_THROW( EXPECT_THROW(
await([&](Promise<int> p) { await([&](Promise<int> p) {
evb.runInEventBaseThread([p = std::move(p)]() mutable { evb.runInEventBaseThread([p = std::move(p)]() mutable {
p.setValue(42); p.setValue(42);
}); });
throw ExpectedException(); throw ExpectedException();
}), }),
ExpectedException); ExpectedException);
}) })
.waitVia(&evb); .waitVia(&evb);
} }
...@@ -1649,20 +1648,20 @@ folly::Future<std::vector<std::string>> doubleBatchInnerDispatch( ...@@ -1649,20 +1648,20 @@ folly::Future<std::vector<std::string>> doubleBatchInnerDispatch(
std::vector<int>, std::vector<int>,
std::vector<std::string>, std::vector<std::string>,
ExecutorT> ExecutorT>
batchDispatcher(executor, [=](std::vector<std::vector<int>>&& batch) { batchDispatcher(executor, [=](std::vector<std::vector<int>>&& batch) {
std::vector<std::vector<std::string>> results; std::vector<std::vector<std::string>> results;
int numberOfElements = 0; int numberOfElements = 0;
for (auto& unit : batch) { for (auto& unit : batch) {
numberOfElements += unit.size(); numberOfElements += unit.size();
std::vector<std::string> result; std::vector<std::string> result;
for (auto& element : unit) { for (auto& element : unit) {
result.push_back(folly::to<std::string>(element)); result.push_back(folly::to<std::string>(element));
} }
results.push_back(std::move(result)); results.push_back(std::move(result));
} }
EXPECT_EQ(totalNumberOfElements, numberOfElements); EXPECT_EQ(totalNumberOfElements, numberOfElements);
return results; return results;
}); });
return batchDispatcher.add(std::move(input)); return batchDispatcher.add(std::move(input));
} }
...@@ -1675,38 +1674,39 @@ void doubleBatchOuterDispatch( ...@@ -1675,38 +1674,39 @@ void doubleBatchOuterDispatch(
ExecutorT& executor, ExecutorT& executor,
int totalNumberOfElements, int totalNumberOfElements,
int index) { int index) {
thread_local BatchDispatcher<int, std::string, ExecutorT> thread_local BatchDispatcher<int, std::string, ExecutorT> batchDispatcher(
batchDispatcher(executor, [=, &executor](std::vector<int>&& batch) { executor, [=, &executor](std::vector<int>&& batch) {
EXPECT_EQ(totalNumberOfElements, batch.size()); EXPECT_EQ(totalNumberOfElements, batch.size());
std::vector<std::string> results; std::vector<std::string> results;
std::vector<folly::Future<std::vector<std::string>>> std::vector<folly::Future<std::vector<std::string>>>
innerDispatchResultFutures; innerDispatchResultFutures;
std::vector<int> group; std::vector<int> group;
for (auto unit : batch) { for (auto unit : batch) {
group.push_back(unit); group.push_back(unit);
if (group.size() == 5) { if (group.size() == 5) {
auto localGroup = group; auto localGroup = group;
group.clear(); group.clear();
innerDispatchResultFutures.push_back(doubleBatchInnerDispatch( innerDispatchResultFutures.push_back(doubleBatchInnerDispatch(
executor, totalNumberOfElements, localGroup)); executor, totalNumberOfElements, localGroup));
}
}
folly::collectAll(
innerDispatchResultFutures.begin(), innerDispatchResultFutures.end())
.then([&](
std::vector<Try<std::vector<std::string>>> innerDispatchResults) {
for (auto& unit : innerDispatchResults) {
for (auto& element : unit.value()) {
results.push_back(element);
}
} }
}) }
.get();
return results; folly::collectAll(
}); innerDispatchResultFutures.begin(),
innerDispatchResultFutures.end())
.then([&](std::vector<Try<std::vector<std::string>>>
innerDispatchResults) {
for (auto& unit : innerDispatchResults) {
for (auto& element : unit.value()) {
results.push_back(element);
}
}
})
.get();
return results;
});
auto indexCopy = index; auto indexCopy = index;
auto result = batchDispatcher.add(std::move(indexCopy)); auto result = batchDispatcher.add(std::move(indexCopy));
...@@ -2139,7 +2139,7 @@ TEST(TimedMutex, ThreadFiberDeadlockRace) { ...@@ -2139,7 +2139,7 @@ TEST(TimedMutex, ThreadFiberDeadlockRace) {
*/ */
#ifndef FOLLY_SANITIZE_ADDRESS #ifndef FOLLY_SANITIZE_ADDRESS
TEST(FiberManager, recordStack) { TEST(FiberManager, recordStack) {
std::thread([] { auto f = [] {
folly::fibers::FiberManager::Options opts; folly::fibers::FiberManager::Options opts;
opts.recordStackEvery = 1; opts.recordStackEvery = 1;
...@@ -2165,6 +2165,7 @@ TEST(FiberManager, recordStack) { ...@@ -2165,6 +2165,7 @@ TEST(FiberManager, recordStack) {
// Check that we properly accounted fiber stack usage. // Check that we properly accounted fiber stack usage.
EXPECT_LT(n * sizeof(int), fm.stackHighWatermark()); EXPECT_LT(n * sizeof(int), fm.stackHighWatermark());
}).join(); };
std::thread(f).join();
} }
#endif #endif
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