]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/cpu-set-util.h
tree-wide: drop license boilerplate
[thirdparty/systemd.git] / src / basic / cpu-set-util.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
618234a5
LP
2#pragma once
3
4/***
5 This file is part of systemd.
6
7 Copyright 2010-2015 Lennart Poettering
8 Copyright 2015 Filipe Brandenburger
618234a5
LP
9***/
10
11#include <sched.h>
12
13#include "macro.h"
14
501941aa
YW
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
618234a5
LP
21DEFINE_TRIVIAL_CLEANUP_FUNC(cpu_set_t*, CPU_FREE);
22#define _cleanup_cpu_free_ _cleanup_(CPU_FREEp)
23
a9a2ed3f
YW
24static inline cpu_set_t* cpu_set_mfree(cpu_set_t *p) {
25 if (p)
26 CPU_FREE(p);
27 return NULL;
28}
29
618234a5
LP
30cpu_set_t* cpu_set_malloc(unsigned *ncpus);
31
6d8a29b2
YW
32int 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
34static 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
40static 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}