Commit 056e121f authored by Chad Austin's avatar Chad Austin Committed by Facebook Github Bot

clang-format folly/executors/

Summary:
Run clang-format across folly/executors/.

```
find . \( -iname '*.cpp' -o -iname '*.h' \) -exec clang-format -i {} \;
```

Reviewed By: yfeldblum

Differential Revision: D8843064

fbshipit-source-id: 0a3c82083eebf2c684a4ab2e12067f0f742bf1d4
parent 1d2790bc
......@@ -45,10 +45,11 @@ class FutureExecutor : public ExecutorImpl {
using T = typename invoke_result_t<F>::value_type;
folly::Promise<T> promise;
auto future = promise.getFuture();
ExecutorImpl::add(
[ promise = std::move(promise), func = std::move(func) ]() mutable {
func().then([promise = std::move(promise)](
folly::Try<T> && t) mutable { promise.setTry(std::move(t)); });
ExecutorImpl::add([promise = std::move(promise),
func = std::move(func)]() mutable {
func().then([promise = std::move(promise)](folly::Try<T>&& t) mutable {
promise.setTry(std::move(t));
});
});
return future;
}
......@@ -70,7 +71,7 @@ class FutureExecutor : public ExecutorImpl {
folly::Promise<T> promise;
auto future = promise.getFuture();
ExecutorImpl::add(
[ promise = std::move(promise), func = std::move(func) ]() mutable {
[promise = std::move(promise), func = std::move(func)]() mutable {
promise.setWith(std::move(func));
});
return future;
......
......@@ -92,7 +92,7 @@ void IOThreadPoolExecutor::add(
auto ioThread = pickThread();
auto task = Task(std::move(func), expiration, std::move(expireCallback));
auto wrappedFunc = [ ioThread, task = std::move(task) ]() mutable {
auto wrappedFunc = [ioThread, task = std::move(task)]() mutable {
runTask(ioThread, std::move(task));
ioThread->pendingTasks--;
};
......
......@@ -27,15 +27,15 @@
#include <folly/synchronization/LifoSem.h>
namespace folly {
/// A ManualExecutor only does work when you turn the crank, by calling
/// run() or indirectly with makeProgress() or waitFor().
///
/// The clock for a manual executor starts at 0 and advances only when you
/// ask it to. i.e. time is also under manual control.
///
/// NB No attempt has been made to make anything other than add and schedule
/// threadsafe.
class ManualExecutor : public DrivableExecutor,
/// A ManualExecutor only does work when you turn the crank, by calling
/// run() or indirectly with makeProgress() or waitFor().
///
/// The clock for a manual executor starts at 0 and advances only when you
/// ask it to. i.e. time is also under manual control.
///
/// NB No attempt has been made to make anything other than add and schedule
/// threadsafe.
class ManualExecutor : public DrivableExecutor,
public ScheduledExecutor,
public SequencedExecutor {
public:
......@@ -72,7 +72,8 @@ namespace folly {
}
/// makeProgress until this Future is ready.
template <class F> void waitFor(F const& f) {
template <class F>
void waitFor(F const& f) {
// TODO(5427828)
#if 0
while (!f.isReady())
......@@ -82,7 +83,6 @@ namespace folly {
run();
}
#endif
}
void scheduleAt(Func&& f, TimePoint const& t) override {
......@@ -103,7 +103,9 @@ namespace folly {
/// this is a noop.
void advanceTo(TimePoint const& t);
TimePoint now() override { return now_; }
TimePoint now() override {
return now_;
}
/// Flush the function queue. Destroys all stored functions without
/// executing them. Returns number of removed functions.
......@@ -132,9 +134,7 @@ namespace folly {
size_t ordinal;
Func mutable func;
ScheduledFunc(TimePoint const& t, Func&& f)
: time(t), func(std::move(f))
{
ScheduledFunc(TimePoint const& t, Func&& f) : time(t), func(std::move(f)) {
static size_t seq = 0;
ordinal = seq++;
}
......@@ -154,6 +154,6 @@ namespace folly {
};
std::priority_queue<ScheduledFunc> scheduledFuncs_;
TimePoint now_ = TimePoint::min();
};
};
} // namespace folly
} // namespace folly
......@@ -24,8 +24,8 @@
#include <folly/lang/Exception.h>
namespace folly {
// An executor that supports timed scheduling. Like RxScheduler.
class ScheduledExecutor : public virtual Executor {
// An executor that supports timed scheduling. Like RxScheduler.
class ScheduledExecutor : public virtual Executor {
public:
// Reality is that better than millisecond resolution is very hard to
// achieve. However, we reserve the right to be incredible.
......@@ -37,7 +37,9 @@ namespace folly {
void add(Func) override = 0;
/// Alias for add() (for Rx consistency)
void schedule(Func&& a) { add(std::move(a)); }
void schedule(Func&& a) {
add(std::move(a));
}
/// Schedule a Func to be executed after dur time has elapsed
/// Expect millisecond resolution at best.
......@@ -55,5 +57,5 @@ namespace folly {
virtual TimePoint now() {
return std::chrono::steady_clock::now();
}
};
} // namespace folly
};
} // namespace folly
......@@ -16,7 +16,6 @@
#include <folly/executors/SerialExecutor.h>
#include <glog/logging.h>
#include <folly/ExceptionString.h>
......
......@@ -76,8 +76,7 @@ class SerialExecutor : public SequencedExecutor {
};
using UniquePtr = std::unique_ptr<SerialExecutor, Deleter>;
[[deprecated("Replaced by create")]]
static UniquePtr createUnique(
[[deprecated("Replaced by create")]] static UniquePtr createUnique(
std::shared_ptr<Executor> parent = getCPUExecutor());
/**
......
......@@ -96,7 +96,7 @@ void ThreadedExecutor::controlLaunchEnqueuedTasks() {
with_unique_lock(enqueuedm_, [&] { std::swap(enqueuedt, enqueued_); });
for (auto& f : enqueuedt) {
auto th = threadFactory_->newThread(
[ this, f = std::move(f) ]() mutable { work(f); });
[this, f = std::move(f)]() mutable { work(f); });
auto id = th.get_id();
running_[id] = std::move(th);
}
......
......@@ -30,7 +30,10 @@ TEST(ManualExecutor, runIsStable) {
ManualExecutor x;
size_t count = 0;
auto f1 = [&]() { count++; };
auto f2 = [&]() { x.add(f1); x.add(f1); };
auto f2 = [&]() {
x.add(f1);
x.add(f1);
};
x.add(f2);
x.run();
EXPECT_EQ(count, 0);
......@@ -52,14 +55,14 @@ TEST(ManualExecutor, drainIsNotStable) {
TEST(ManualExecutor, scheduleDur) {
ManualExecutor x;
size_t count = 0;
std::chrono::milliseconds dur {10};
x.schedule([&]{ count++; }, dur);
std::chrono::milliseconds dur{10};
x.schedule([&] { count++; }, dur);
EXPECT_EQ(count, 0);
x.run();
EXPECT_EQ(count, 0);
x.advance(dur/2);
x.advance(dur / 2);
EXPECT_EQ(count, 0);
x.advance(dur/2);
x.advance(dur / 2);
EXPECT_EQ(count, 1);
}
......@@ -114,7 +117,7 @@ TEST(ManualExecutor, clockStartsAt0) {
TEST(ManualExecutor, scheduleAbs) {
ManualExecutor x;
size_t count = 0;
x.scheduleAt([&]{ count++; }, x.now() + std::chrono::milliseconds(10));
x.scheduleAt([&] { count++; }, x.now() + std::chrono::milliseconds(10));
EXPECT_EQ(count, 0);
x.advance(std::chrono::milliseconds(10));
EXPECT_EQ(count, 1);
......@@ -123,7 +126,7 @@ TEST(ManualExecutor, scheduleAbs) {
TEST(ManualExecutor, advanceTo) {
ManualExecutor x;
size_t count = 0;
x.scheduleAt([&]{ count++; }, std::chrono::steady_clock::now());
x.scheduleAt([&] { count++; }, std::chrono::steady_clock::now());
EXPECT_EQ(count, 0);
x.advanceTo(std::chrono::steady_clock::now());
EXPECT_EQ(count, 1);
......@@ -133,7 +136,7 @@ TEST(ManualExecutor, advanceBack) {
ManualExecutor x;
size_t count = 0;
x.advance(std::chrono::microseconds(5));
x.schedule([&]{ count++; }, std::chrono::microseconds(6));
x.schedule([&] { count++; }, std::chrono::microseconds(6));
EXPECT_EQ(count, 0);
x.advanceTo(x.now() - std::chrono::microseconds(1));
EXPECT_EQ(count, 0);
......@@ -143,7 +146,7 @@ TEST(ManualExecutor, advanceNeg) {
ManualExecutor x;
size_t count = 0;
x.advance(std::chrono::microseconds(5));
x.schedule([&]{ count++; }, std::chrono::microseconds(6));
x.schedule([&] { count++; }, std::chrono::microseconds(6));
EXPECT_EQ(count, 0);
x.advance(std::chrono::microseconds(-1));
EXPECT_EQ(count, 0);
......@@ -154,9 +157,9 @@ TEST(ManualExecutor, waitForDoesNotDeadlock) {
folly::Baton<> baton;
auto f = makeFuture()
.via(&east)
.then([](Try<Unit>){ return makeFuture(); })
.then([](Try<Unit>) { return makeFuture(); })
.via(&west);
std::thread t([&]{
std::thread t([&] {
baton.post();
west.waitFor(f);
});
......@@ -168,9 +171,10 @@ TEST(ManualExecutor, waitForDoesNotDeadlock) {
TEST(ManualExecutor, getViaDoesNotDeadlock) {
ManualExecutor east, west;
folly::Baton<> baton;
auto f = makeFuture().via(&east).then([](Try<Unit>) {
return makeFuture();
}).via(&west);
auto f = makeFuture()
.via(&east)
.then([](Try<Unit>) { return makeFuture(); })
.via(&west);
std::thread t([&] {
baton.post();
f.getVia(&west);
......@@ -196,8 +200,8 @@ TEST(ManualExecutor, clear) {
TEST(Executor, InlineExecutor) {
InlineExecutor x;
size_t counter = 0;
x.add([&]{
x.add([&]{
x.add([&] {
x.add([&] {
EXPECT_EQ(counter, 0);
counter++;
});
......@@ -210,8 +214,8 @@ TEST(Executor, InlineExecutor) {
TEST(Executor, QueuedImmediateExecutor) {
QueuedImmediateExecutor x;
size_t counter = 0;
x.add([&]{
x.add([&]{
x.add([&] {
x.add([&] {
EXPECT_EQ(1, counter);
counter++;
});
......@@ -226,10 +230,12 @@ TEST(Executor, Runnable) {
size_t counter = 0;
struct Runnable {
std::function<void()> fn;
void operator()() { fn(); }
void operator()() {
fn();
}
};
Runnable f;
f.fn = [&]{ counter++; };
f.fn = [&] { counter++; };
x.add(f);
EXPECT_EQ(counter, 1);
}
......@@ -247,7 +253,9 @@ TEST(Executor, ThrowableThen) {
class CrappyExecutor : public Executor {
public:
void add(Func /* f */) override { throw std::runtime_error("bad"); }
void add(Func /* f */) override {
throw std::runtime_error("bad");
}
};
TEST(Executor, CrappyExecutor) {
......
......@@ -35,7 +35,7 @@ class NamedThreadFactory : public ThreadFactory {
std::thread newThread(Func&& func) override {
auto name = folly::to<std::string>(prefix_, suffix_++);
return std::thread(
[ func = std::move(func), name = std::move(name) ]() mutable {
[func = std::move(func), name = std::move(name)]() mutable {
folly::setThreadName(name);
func();
});
......
......@@ -43,7 +43,7 @@ class PriorityThreadFactory : public ThreadFactory {
std::thread newThread(Func&& func) override {
int priority = priority_;
return factory_->newThread([ priority, func = std::move(func) ]() mutable {
return factory_->newThread([priority, func = std::move(func)]() mutable {
if (setpriority(PRIO_PROCESS, 0, priority) != 0) {
LOG(ERROR) << "setpriority failed (are you root?) with error " << errno,
strerror(errno);
......
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