Format.h \
Format-inl.h \
futures/Deprecated.h \
+ futures/ThreadedExecutor.h \
futures/DrivableExecutor.h \
futures/Future-pre.h \
futures/helpers.h \
FileUtil.cpp \
FingerprintTables.cpp \
futures/detail/ThreadWheelTimekeeper.cpp \
+ futures/ThreadedExecutor.cpp \
futures/Future.cpp \
futures/InlineExecutor.cpp \
futures/ManualExecutor.cpp \
--- /dev/null
+/*
+ * Copyright 2015 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <folly/futures/ThreadedExecutor.h>
+
+#include <glog/logging.h>
+
+using namespace std;
+
+namespace folly { namespace futures {
+
+ThreadedExecutor::~ThreadedExecutor() {
+ lock_guard<mutex> lock(mutex_);
+ destructing_ = true;
+ for (auto& th : threads_) {
+ th.join();
+ }
+}
+
+void ThreadedExecutor::add(Func f) {
+ lock_guard<mutex> lock(mutex_);
+ CHECK(!destructing_);
+ threads_.emplace_back(std::move(f));
+}
+
+}}
--- /dev/null
+/*
+ * Copyright 2015 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <list>
+#include <mutex>
+#include <thread>
+#include <folly/Executor.h>
+
+namespace folly { namespace futures {
+
+/**
+ * Runs functions each in its own thread.
+ *
+ * Kind of simple. Suitable for a few types of strange cases.
+ */
+class ThreadedExecutor : public Executor {
+public:
+ ~ThreadedExecutor();
+ void add(Func f) override;
+private:
+ std::mutex mutex_;
+ std::list<std::thread> threads_;
+ bool destructing_ = false;
+};
+
+}}
--- /dev/null
+/*
+ * Copyright 2015 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <folly/futures/ThreadedExecutor.h>
+#include <folly/futures/Future.h>
+#include <folly/Conv.h>
+
+#include <gtest/gtest.h>
+
+using namespace std;
+using namespace folly;
+using namespace folly::futures;
+
+class ThreadedExecutorTest : public testing::Test {};
+
+TEST_F(ThreadedExecutorTest, example) {
+ ThreadedExecutor x;
+ auto ret = via(&x)
+ .then([&] { return 17; })
+ .then([&](int x) { return to<string>(x); })
+ .wait()
+ .getTry();
+ EXPECT_EQ("17", ret.value());
+}
../futures/test/CollectTest.cpp \
../futures/test/ContextTest.cpp \
../futures/test/CoreTest.cpp \
+ ../futures/test/ThreadedExecutorTest.cpp \
../futures/test/EnsureTest.cpp \
../futures/test/ExecutorTest.cpp \
../futures/test/FSMTest.cpp \