Commit a1c28139 authored by Dan Melnic's avatar Dan Melnic Committed by Facebook Github Bot

Add folly::hardware_concurrency

Summary:
Add folly::hardware_concurrency

(Note: this ignores all push blocking failures!)

Reviewed By: yfeldblum

Differential Revision: D18342219

fbshipit-source-id: 806ef7b46e52896fa289a79854e45447929ab632
parent 7e195929
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <folly/executors/IOExecutor.h> #include <folly/executors/IOExecutor.h>
#include <folly/executors/IOThreadPoolExecutor.h> #include <folly/executors/IOThreadPoolExecutor.h>
#include <folly/executors/InlineExecutor.h> #include <folly/executors/InlineExecutor.h>
#include <folly/system/HardwareConcurrency.h>
using namespace folly; using namespace folly;
...@@ -86,7 +87,7 @@ Singleton<GlobalExecutor<IOExecutor>> gGlobalIOExecutor([] { ...@@ -86,7 +87,7 @@ Singleton<GlobalExecutor<IOExecutor>> gGlobalIOExecutor([] {
// Default global IO executor is an IOThreadPoolExecutor. // Default global IO executor is an IOThreadPoolExecutor.
[] { [] {
return std::make_unique<IOThreadPoolExecutor>( return std::make_unique<IOThreadPoolExecutor>(
std::thread::hardware_concurrency(), folly::hardware_concurrency(),
std::make_shared<NamedThreadFactory>("GlobalIOThreadPool")); std::make_shared<NamedThreadFactory>("GlobalIOThreadPool"));
}); });
}); });
......
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* 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/system/HardwareConcurrency.h>
#include <thread>
#include <folly/portability/Sched.h>
namespace folly {
unsigned int hardware_concurrency() noexcept {
#if defined(__linux__) && !defined(__ANDROID__)
cpu_set_t cpuset;
if (!sched_getaffinity(0, sizeof(cpuset), &cpuset)) {
auto count = CPU_COUNT(&cpuset);
if (count != 0) {
return count;
}
}
#endif
return std::thread::hardware_concurrency();
}
} // namespace folly
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* 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
namespace folly {
unsigned int hardware_concurrency() noexcept;
} // namespace folly
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