[libc-commits] [libc] [libc][sched] Implement `CPU_ZERO`, `CPU_ISSET`, `CPU_SET` macros (PR #131524)
via libc-commits
libc-commits at lists.llvm.org
Tue Mar 18 13:55:10 PDT 2025
================
@@ -0,0 +1,33 @@
+//===-- Implementation of sched_getcpuisset -------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/sched/sched_getcpuisset.h"
+
+#include "src/__support/common.h" // LLVM_LIBC_FUNCTION
+#include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL
+
+#include "hdr/sched_macros.h" // NCPUBITS
+#include "hdr/types/cpu_set_t.h"
+#include "hdr/types/size_t.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, __sched_getcpuisset,
+ (int cpu, const size_t cpuset_size, cpu_set_t *set)) {
+ if (static_cast<size_t>(cpu) / 8 < cpuset_size) {
+ const size_t element_index = static_cast<size_t>(cpu) / NCPUBITS;
+ const size_t bit_position = static_cast<size_t>(cpu) % NCPUBITS;
+
+ const unsigned long mask = 1UL << bit_position;
+ return (set->__mask[element_index] & mask) != 0;
----------------
lntue wrote:
Yes, can you add null check with https://github.com/llvm/llvm-project/blob/main/libc/src/__support/macros/null_check.h for these functions in this PR? Thanks,
https://github.com/llvm/llvm-project/pull/131524
More information about the libc-commits
mailing list