]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/cpu-set-util.h
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / shared / cpu-set-util.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include <sched.h>
5
6 #include "macro.h"
7
8 #ifdef __NCPUBITS
9 #define CPU_SIZE_TO_NUM(n) ((n) * __NCPUBITS)
10 #else
11 #define CPU_SIZE_TO_NUM(n) ((n) * sizeof(cpu_set_t) * 8)
12 #endif
13
14 DEFINE_TRIVIAL_CLEANUP_FUNC(cpu_set_t*, CPU_FREE);
15 #define _cleanup_cpu_free_ _cleanup_(CPU_FREEp)
16
17 static inline cpu_set_t* cpu_set_mfree(cpu_set_t *p) {
18 if (p)
19 CPU_FREE(p);
20 return NULL;
21 }
22
23 cpu_set_t* cpu_set_malloc(unsigned *ncpus);
24
25 int parse_cpu_set_internal(const char *rvalue, cpu_set_t **cpu_set, bool warn, const char *unit, const char *filename, unsigned line, const char *lvalue);
26
27 static inline int parse_cpu_set_and_warn(const char *rvalue, cpu_set_t **cpu_set, const char *unit, const char *filename, unsigned line, const char *lvalue) {
28 assert(lvalue);
29
30 return parse_cpu_set_internal(rvalue, cpu_set, true, unit, filename, line, lvalue);
31 }
32
33 static inline int parse_cpu_set(const char *rvalue, cpu_set_t **cpu_set){
34 return parse_cpu_set_internal(rvalue, cpu_set, false, NULL, NULL, 0, NULL);
35 }