From 6ac9666fabefe123c171adc1cb06888a2cd73408 Mon Sep 17 00:00:00 2001 From: Red Bear OS Date: Fri, 10 Jul 2026 10:09:10 +0300 Subject: [PATCH] relibc: add CPU_ZERO/CPU_SET/CPU_CLR/CPU_ISSET/CPU_COUNT to sched.h --- src/header/sched/cbindgen.toml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/header/sched/cbindgen.toml b/src/header/sched/cbindgen.toml index c54d4ec488..40b79b78fc 100644 --- a/src/header/sched/cbindgen.toml +++ b/src/header/sched/cbindgen.toml @@ -9,6 +9,29 @@ sys_includes = ["sys/types.h", "stdint.h"] include_guard = "_RELIBC_SCHED_H" after_includes = """ #include // for timespec + +#define CPU_SETSIZE 1024 +static inline void CPU_ZERO(cpu_set_t *set) { + for (int i = 0; i < 16; i++) set->__bits[i] = 0; +} +static inline void CPU_SET(int cpu, cpu_set_t *set) { + if (cpu >= 0 && cpu < CPU_SETSIZE) set->__bits[cpu / 64] |= 1ULL << (cpu % 64); +} +static inline void CPU_CLR(int cpu, cpu_set_t *set) { + if (cpu >= 0 && cpu < CPU_SETSIZE) set->__bits[cpu / 64] &= ~(1ULL << (cpu % 64)); +} +static inline int CPU_ISSET(int cpu, cpu_set_t *set) { + if (cpu >= 0 && cpu < CPU_SETSIZE) return (set->__bits[cpu / 64] >> (cpu % 64)) & 1; + return 0; +} +static inline int CPU_COUNT(cpu_set_t *set) { + int count = 0; + for (int i = 0; i < 16; i++) { + unsigned long long v = set->__bits[i]; + while (v) { count += v & 1; v >>= 1; } + } + return count; +} """ language = "C" style = "Both"