]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/cpu-set-util.h
Move cpus_in_affinity_mask() to cpu-set-util.[ch]
[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
8DEFINE_TRIVIAL_CLEANUP_FUNC(cpu_set_t*, CPU_FREE);
9#define _cleanup_cpu_free_ _cleanup_(CPU_FREEp)
10
11cpu_set_t* cpu_set_malloc(unsigned *ncpus);
12
0985c7c4
ZJS
13/* This wraps the libc interface with a variable to keep the allocated size. */
14typedef struct CPUSet {
15 cpu_set_t *set;
16 size_t allocated; /* in bytes */
17} CPUSet;
18
19static inline void cpu_set_reset(CPUSet *a) {
20 assert((a->allocated > 0) == !!a->set);
21 if (a->set)
22 CPU_FREE(a->set);
23 *a = (CPUSet) {};
6d8a29b2
YW
24}
25
0985c7c4
ZJS
26int cpu_set_add_all(CPUSet *a, const CPUSet *b);
27
28char* cpu_set_to_string(const CPUSet *a);
29int parse_cpu_set_full(
30 const char *rvalue,
31 CPUSet *cpu_set,
32 bool warn,
33 const char *unit,
34 const char *filename, unsigned line,
35 const char *lvalue);
36int parse_cpu_set_extend(
37 const char *rvalue,
38 CPUSet *old,
39 bool warn,
40 const char *unit,
41 const char *filename,
42 unsigned line,
43 const char *lvalue);
44
45static inline int parse_cpu_set(const char *rvalue, CPUSet *cpu_set){
46 return parse_cpu_set_full(rvalue, cpu_set, false, NULL, NULL, 0, NULL);
6d8a29b2 47}
f44b3035
ZJS
48
49int cpus_in_affinity_mask(void);