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