Ports: Make libuv retrieve the CPU count via sysconf()

This is better than hardcoding it to 0.
This new implementation is a direct copy of the IBM i implementation.

Neovim uses this count to determine how many threads to spawn in
`vim.pack`. Previously, it spawned 0 threads and got stuck when
downloading plugins.
This commit is contained in:
Sönke Holz
2026-04-03 01:27:12 +02:00
committed by Lucas Chollet
parent 4a70dfc2db
commit a1857bb779

View File

@@ -5,8 +5,8 @@ Subject: [PATCH] build: Add platform-specific stubs and implementations
---
CMakeLists.txt | 2 +
src/unix/serenity-core.c | 116 +++++++++++++++++++++++++++++++++++++++
2 files changed, 118 insertions(+)
src/unix/serenity-core.c | 140 +++++++++++++++++++++++++++++++++++++++
2 files changed, 142 insertions(+)
create mode 100644 src/unix/serenity-core.c
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -27,10 +27,10 @@ index c8425957cbd4d4ba28f0c0135b8c49f00c5dd507..4684ee906aa7d477b44ca4ed7cd43cf3
diff --git a/src/unix/serenity-core.c b/src/unix/serenity-core.c
new file mode 100644
index 0000000000000000000000000000000000000000..48fa813c57c5c420bee46ea78aa674c7be4aee73
index 0000000000000000000000000000000000000000..462a0d58a688945192475a51101161edb62b0739
--- /dev/null
+++ b/src/unix/serenity-core.c
@@ -0,0 +1,116 @@
@@ -0,0 +1,140 @@
+#include "uv.h"
+#include "internal.h"
+
@@ -123,8 +123,32 @@ index 0000000000000000000000000000000000000000..48fa813c57c5c420bee46ea78aa674c7
+}
+
+int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
+ unsigned int numcpus, idx = 0;
+ uv_cpu_info_t* cpu_info;
+
+ *cpu_infos = NULL;
+ *count = 0;
+
+ numcpus = sysconf(_SC_NPROCESSORS_ONLN);
+
+ *cpu_infos = uv__malloc(numcpus * sizeof(uv_cpu_info_t));
+ if (!*cpu_infos) {
+ return UV_ENOMEM;
+ }
+
+ cpu_info = *cpu_infos;
+ for (idx = 0; idx < numcpus; idx++) {
+ cpu_info->speed = 0;
+ cpu_info->model = uv__strdup("unknown");
+ cpu_info->cpu_times.user = 0;
+ cpu_info->cpu_times.sys = 0;
+ cpu_info->cpu_times.idle = 0;
+ cpu_info->cpu_times.irq = 0;
+ cpu_info->cpu_times.nice = 0;
+ cpu_info++;
+ }
+ *count = numcpus;
+
+ return 0;
+}
+