cpu-set-util: rename cpu_set_reset() -> cpu_set_done()
This also introduces cpu_set_done_and_replace(). No functional change, just refactoring.
This commit is contained in:
@@ -615,7 +615,8 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
|
||||
"StartupAllowedCPUs",
|
||||
"AllowedMemoryNodes",
|
||||
"StartupAllowedMemoryNodes")) {
|
||||
_cleanup_(cpu_set_reset) CPUSet cpuset = {};
|
||||
|
||||
_cleanup_(cpu_set_done) CPUSet cpuset = {};
|
||||
_cleanup_free_ uint8_t *array = NULL;
|
||||
size_t allocated;
|
||||
|
||||
@@ -1564,7 +1565,7 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
|
||||
}
|
||||
|
||||
if (streq(field, "CPUAffinity")) {
|
||||
_cleanup_(cpu_set_reset) CPUSet cpuset = {};
|
||||
_cleanup_(cpu_set_done) CPUSet cpuset = {};
|
||||
_cleanup_free_ uint8_t *array = NULL;
|
||||
size_t allocated;
|
||||
|
||||
@@ -1599,7 +1600,7 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
|
||||
}
|
||||
|
||||
if (streq(field, "NUMAMask")) {
|
||||
_cleanup_(cpu_set_reset) CPUSet nodes = {};
|
||||
_cleanup_(cpu_set_done) CPUSet nodes = {};
|
||||
_cleanup_free_ uint8_t *array = NULL;
|
||||
size_t allocated;
|
||||
|
||||
|
||||
@@ -117,11 +117,20 @@ char* cpu_set_to_mask_string(const CPUSet *c) {
|
||||
return TAKE_PTR(str) ?: strdup("0");
|
||||
}
|
||||
|
||||
void cpu_set_done(CPUSet *c) {
|
||||
assert(c);
|
||||
|
||||
if (c->set)
|
||||
CPU_FREE(c->set);
|
||||
|
||||
*c = (CPUSet) {};
|
||||
}
|
||||
|
||||
CPUSet* cpu_set_free(CPUSet *c) {
|
||||
if (!c)
|
||||
return c;
|
||||
|
||||
cpu_set_reset(c);
|
||||
cpu_set_done(c);
|
||||
return mfree(c);
|
||||
}
|
||||
|
||||
@@ -217,7 +226,7 @@ int parse_cpu_set_full(
|
||||
unsigned line,
|
||||
const char *lvalue) {
|
||||
|
||||
_cleanup_(cpu_set_reset) CPUSet c = {};
|
||||
_cleanup_(cpu_set_done) CPUSet c = {};
|
||||
const char *p = ASSERT_PTR(rvalue);
|
||||
|
||||
assert(cpu_set);
|
||||
@@ -272,7 +281,7 @@ int parse_cpu_set_extend(
|
||||
unsigned line,
|
||||
const char *lvalue) {
|
||||
|
||||
_cleanup_(cpu_set_reset) CPUSet cpuset = {};
|
||||
_cleanup_(cpu_set_done) CPUSet cpuset = {};
|
||||
int r;
|
||||
|
||||
assert(old);
|
||||
@@ -282,8 +291,8 @@ int parse_cpu_set_extend(
|
||||
return r;
|
||||
|
||||
if (!cpuset.set) {
|
||||
/* An empty assignment resets the CPU list */
|
||||
cpu_set_reset(old);
|
||||
/* An empty assignment clears the CPU list */
|
||||
cpu_set_done(old);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -348,7 +357,7 @@ int cpu_set_to_dbus(const CPUSet *c, uint8_t **ret, size_t *ret_size) {
|
||||
}
|
||||
|
||||
int cpu_set_from_dbus(const uint8_t *bits, size_t size, CPUSet *ret) {
|
||||
_cleanup_(cpu_set_reset) CPUSet c = {};
|
||||
_cleanup_(cpu_set_done) CPUSet c = {};
|
||||
int r;
|
||||
|
||||
assert(bits || size == 0);
|
||||
|
||||
@@ -11,12 +11,14 @@ typedef struct CPUSet {
|
||||
size_t allocated; /* in bytes */
|
||||
} CPUSet;
|
||||
|
||||
static inline void cpu_set_reset(CPUSet *a) {
|
||||
assert((a->allocated > 0) == !!a->set);
|
||||
if (a->set)
|
||||
CPU_FREE(a->set);
|
||||
*a = (CPUSet) {};
|
||||
}
|
||||
void cpu_set_done(CPUSet *c);
|
||||
#define cpu_set_done_and_replace(a, b) \
|
||||
({ \
|
||||
CPUSet *_a = &(a), *_b = &(b); \
|
||||
cpu_set_done(_a); \
|
||||
*_a = TAKE_STRUCT(*_b); \
|
||||
0; \
|
||||
})
|
||||
|
||||
CPUSet* cpu_set_free(CPUSet *c);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(CPUSet*, cpu_set_free);
|
||||
|
||||
@@ -91,17 +91,15 @@ int apply_numa_policy(const NUMAPolicy *policy) {
|
||||
}
|
||||
|
||||
int numa_to_cpu_set(const NUMAPolicy *policy, CPUSet *ret) {
|
||||
_cleanup_(cpu_set_done) CPUSet s = {};
|
||||
int r;
|
||||
size_t i;
|
||||
_cleanup_(cpu_set_reset) CPUSet s = {};
|
||||
|
||||
assert(policy);
|
||||
assert(ret);
|
||||
|
||||
for (i = 0; i < policy->nodes.allocated * 8; i++) {
|
||||
for (size_t i = 0; i < policy->nodes.allocated * 8; i++) {
|
||||
_cleanup_free_ char *l = NULL;
|
||||
char p[STRLEN("/sys/devices/system/node/node//cpulist") + DECIMAL_STR_MAX(size_t) + 1];
|
||||
_cleanup_(cpu_set_reset) CPUSet part = {};
|
||||
|
||||
if (!CPU_ISSET_S(i, policy->nodes.allocated, policy->nodes.set))
|
||||
continue;
|
||||
@@ -112,6 +110,7 @@ int numa_to_cpu_set(const NUMAPolicy *policy, CPUSet *ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
_cleanup_(cpu_set_done) CPUSet part = {};
|
||||
r = parse_cpu_set(l, &part);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -23,7 +23,7 @@ static inline int numa_policy_get_type(const NUMAPolicy *p) {
|
||||
|
||||
static inline void numa_policy_reset(NUMAPolicy *p) {
|
||||
assert(p);
|
||||
cpu_set_reset(&p->nodes);
|
||||
cpu_set_done(&p->nodes);
|
||||
p->type = -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user