1 | //===-- Implementation of sched_setcpuset ---------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "src/sched/sched_setcpuset.h" |
10 | |
11 | #include "src/__support/common.h" // LLVM_LIBC_FUNCTION |
12 | #include "src/__support/macros/config.h" // LIBC_NAMESPACE_DECL |
13 | #include "src/__support/macros/null_check.h" // LIBC_CRASH_ON_NULLPTR |
14 | |
15 | #include "hdr/sched_macros.h" // NCPUBITS |
16 | #include "hdr/types/cpu_set_t.h" |
17 | #include "hdr/types/size_t.h" |
18 | |
19 | namespace LIBC_NAMESPACE_DECL { |
20 | |
21 | LLVM_LIBC_FUNCTION(void, __sched_setcpuset, |
22 | (int cpu, const size_t cpuset_size, cpu_set_t *set)) { |
23 | LIBC_CRASH_ON_NULLPTR(set); |
24 | if (static_cast<size_t>(cpu) / 8 < cpuset_size) { |
25 | const size_t element_index = static_cast<size_t>(cpu) / NCPUBITS; |
26 | const size_t bit_position = static_cast<size_t>(cpu) % NCPUBITS; |
27 | |
28 | const unsigned long mask = 1UL << bit_position; |
29 | set->__mask[element_index] |= mask; |
30 | } |
31 | } |
32 | |
33 | } // namespace LIBC_NAMESPACE_DECL |
34 | |