machine: introduce machine_hash_ops and use it
This commit is contained in:
@@ -70,8 +70,9 @@ fail:
|
||||
return mfree(m);
|
||||
}
|
||||
|
||||
void machine_free(Machine *m) {
|
||||
assert(m);
|
||||
Machine* machine_free(Machine *m) {
|
||||
if (!m)
|
||||
return NULL;
|
||||
|
||||
while (m->operations)
|
||||
operation_free(m->operations);
|
||||
@@ -98,7 +99,7 @@ void machine_free(Machine *m) {
|
||||
free(m->service);
|
||||
free(m->root_directory);
|
||||
free(m->netif);
|
||||
free(m);
|
||||
return mfree(m);
|
||||
}
|
||||
|
||||
int machine_save(Machine *m) {
|
||||
|
||||
@@ -65,7 +65,7 @@ struct Machine {
|
||||
};
|
||||
|
||||
Machine* machine_new(Manager *manager, MachineClass class, const char *name);
|
||||
void machine_free(Machine *m);
|
||||
Machine* machine_free(Machine *m);
|
||||
bool machine_may_gc(Machine *m, bool drop_not_started);
|
||||
void machine_add_to_gc_queue(Machine *m);
|
||||
int machine_start(Machine *m, sd_bus_message *properties, sd_bus_error *error);
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
static Manager* manager_unref(Manager *m);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_unref);
|
||||
|
||||
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(machine_hash_ops, void, trivial_hash_func, trivial_compare_func,
|
||||
Machine, machine_free);
|
||||
|
||||
static int manager_new(Manager **ret) {
|
||||
_cleanup_(manager_unrefp) Manager *m = NULL;
|
||||
int r;
|
||||
@@ -37,7 +40,7 @@ static int manager_new(Manager **ret) {
|
||||
|
||||
m->machines = hashmap_new(&string_hash_ops);
|
||||
m->machine_units = hashmap_new(&string_hash_ops);
|
||||
m->machine_leaders = hashmap_new(NULL);
|
||||
m->machine_leaders = hashmap_new(&machine_hash_ops);
|
||||
|
||||
if (!m->machines || !m->machine_units || !m->machine_leaders)
|
||||
return -ENOMEM;
|
||||
@@ -61,8 +64,6 @@ static int manager_new(Manager **ret) {
|
||||
}
|
||||
|
||||
static Manager* manager_unref(Manager *m) {
|
||||
Machine *machine;
|
||||
|
||||
if (!m)
|
||||
return NULL;
|
||||
|
||||
@@ -71,9 +72,6 @@ static Manager* manager_unref(Manager *m) {
|
||||
|
||||
assert(m->n_operations == 0);
|
||||
|
||||
while ((machine = hashmap_first(m->machines)))
|
||||
machine_free(machine);
|
||||
|
||||
hashmap_free(m->machines);
|
||||
hashmap_free(m->machine_units);
|
||||
hashmap_free(m->machine_leaders);
|
||||
|
||||
Reference in New Issue
Block a user