]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/cpu-set-util.h
tree-wide: drop license boilerplate
[thirdparty/systemd.git] / src / basic / cpu-set-util.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 This file is part of systemd.
6
7 Copyright 2010-2015 Lennart Poettering
8 Copyright 2015 Filipe Brandenburger
9 ***/
10
11 #include <sched.h>
12
13 #include "macro.h"
14
15 #ifdef __NCPUBITS
16 #define CPU_SIZE_TO_NUM(n) ((n) * __NCPUBITS)
17 #else
18 #define CPU_SIZE_TO_NUM(n) ((n) * sizeof(cpu_set_t) * 8)
19 #endif
20
21 DEFINE_TRIVIAL_CLEANUP_FUNC(cpu_set_t*, CPU_FREE);
22 #define _cleanup_cpu_free_ _cleanup_(CPU_FREEp)
23
24 static inline cpu_set_t* cpu_set_mfree(cpu_set_t *p) {
25 if (p)
26 CPU_FREE(p);
27 return NULL;
28 }
29
30 cpu_set_t* cpu_set_malloc(unsigned *ncpus);
31
32 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);
33
34 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) {
35 assert(lvalue);
36
37 return parse_cpu_set_internal(rvalue, cpu_set, true, unit, filename, line, lvalue);
38 }
39
40 static inline int parse_cpu_set(const char *rvalue, cpu_set_t **cpu_set){
41 return parse_cpu_set_internal(rvalue, cpu_set, false, NULL, NULL, 0, NULL);
42 }