mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-20 14:59:27 +00:00
fix: limit warning issue (#5807)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
This commit is contained in:
@@ -18,7 +18,9 @@
|
|||||||
#include "struct_smart_holder.h"
|
#include "struct_smart_holder.h"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <cstdint>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <limits>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
@@ -274,8 +276,10 @@ struct internals {
|
|||||||
registered_exception_translators.push_front(&translate_exception);
|
registered_exception_translators.push_front(&translate_exception);
|
||||||
#ifdef Py_GIL_DISABLED
|
#ifdef Py_GIL_DISABLED
|
||||||
// Scale proportional to the number of cores. 2x is a heuristic to reduce contention.
|
// Scale proportional to the number of cores. 2x is a heuristic to reduce contention.
|
||||||
auto num_shards
|
// Make sure the number isn't unreasonable by limiting it to 16 bits (65K)
|
||||||
= static_cast<size_t>(round_up_to_next_pow2(2 * std::thread::hardware_concurrency()));
|
auto num_shards = static_cast<std::uint16_t>(
|
||||||
|
std::min<std::size_t>(round_up_to_next_pow2(2 * std::thread::hardware_concurrency()),
|
||||||
|
std::numeric_limits<std::uint16_t>::max()));
|
||||||
if (num_shards == 0) {
|
if (num_shards == 0) {
|
||||||
num_shards = 1;
|
num_shards = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user