]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/cpu-set-util.h
shared/varlink: add missing va_end()
[thirdparty/systemd.git] / src / shared / cpu-set-util.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
618234a5
LP
2#pragma once
3
618234a5
LP
4#include <sched.h>
5
6#include "macro.h"
7
0985c7c4
ZJS
8/* This wraps the libc interface with a variable to keep the allocated size. */
9typedef struct CPUSet {
10 cpu_set_t *set;
11 size_t allocated; /* in bytes */
12} CPUSet;
13
14static inline void cpu_set_reset(CPUSet *a) {
15 assert((a->allocated > 0) == !!a->set);
16 if (a->set)
17 CPU_FREE(a->set);
18 *a = (CPUSet) {};
6d8a29b2
YW
19}
20
0985c7c4
ZJS
21int cpu_set_add_all(CPUSet *a, const CPUSet *b);
22
23char* cpu_set_to_string(const CPUSet *a);
71b28519 24char *cpu_set_to_range_string(const CPUSet *a);
167a776d 25int cpu_set_realloc(CPUSet *cpu_set, unsigned ncpus);
71b28519 26
0985c7c4
ZJS
27int parse_cpu_set_full(
28 const char *rvalue,
29 CPUSet *cpu_set,
30 bool warn,
31 const char *unit,
32 const char *filename, unsigned line,
33 const char *lvalue);
34int parse_cpu_set_extend(
35 const char *rvalue,
36 CPUSet *old,
37 bool warn,
38 const char *unit,
39 const char *filename,
40 unsigned line,
41 const char *lvalue);
42
43static inline int parse_cpu_set(const char *rvalue, CPUSet *cpu_set){
44 return parse_cpu_set_full(rvalue, cpu_set, false, NULL, NULL, 0, NULL);
6d8a29b2 45}
f44b3035 46
c367f996
MS
47int cpu_set_to_dbus(const CPUSet *set, uint8_t **ret, size_t *allocated);
48int cpu_set_from_dbus(const uint8_t *bits, size_t size, CPUSet *set);
49
f44b3035 50int cpus_in_affinity_mask(void);