list: make our list macros a bit easier to use by not requring type spec on each invocation

We can determine the list entry type via the typeof() gcc construct, and
so we should to make the macros much shorter to use.
This commit is contained in:
Lennart Poettering
2013-10-14 06:11:19 +02:00
parent 14bf2c9d37
commit 71fda00f32
38 changed files with 153 additions and 157 deletions
+5 -5
View File
@@ -41,7 +41,7 @@ void cgroup_context_free_device_allow(CGroupContext *c, CGroupDeviceAllow *a) {
assert(c);
assert(a);
LIST_REMOVE(CGroupDeviceAllow, device_allow, c->device_allow, a);
LIST_REMOVE(device_allow, c->device_allow, a);
free(a->path);
free(a);
}
@@ -50,7 +50,7 @@ void cgroup_context_free_blockio_device_weight(CGroupContext *c, CGroupBlockIODe
assert(c);
assert(w);
LIST_REMOVE(CGroupBlockIODeviceWeight, device_weights, c->blockio_device_weights, w);
LIST_REMOVE(device_weights, c->blockio_device_weights, w);
free(w->path);
free(w);
}
@@ -59,7 +59,7 @@ void cgroup_context_free_blockio_device_bandwidth(CGroupContext *c, CGroupBlockI
assert(c);
assert(b);
LIST_REMOVE(CGroupBlockIODeviceBandwidth, device_bandwidths, c->blockio_device_bandwidths, b);
LIST_REMOVE(device_bandwidths, c->blockio_device_bandwidths, b);
free(b->path);
free(b);
}
@@ -426,7 +426,7 @@ static int unit_realize_cgroup_now(Unit *u) {
assert(u);
if (u->in_cgroup_queue) {
LIST_REMOVE(Unit, cgroup_queue, u->manager->cgroup_queue, u);
LIST_REMOVE(cgroup_queue, u->manager->cgroup_queue, u);
u->in_cgroup_queue = false;
}
@@ -450,7 +450,7 @@ static void unit_add_to_cgroup_queue(Unit *u) {
if (u->in_cgroup_queue)
return;
LIST_PREPEND(Unit, cgroup_queue, u->manager->cgroup_queue, u);
LIST_PREPEND(cgroup_queue, u->manager->cgroup_queue, u);
u->in_cgroup_queue = true;
}
+3 -5
View File
@@ -273,8 +273,7 @@ int bus_cgroup_set_property(
a->bandwidth = u64;
if (!exist)
LIST_PREPEND(CGroupBlockIODeviceBandwidth, device_bandwidths,
c->blockio_device_bandwidths, a);
LIST_PREPEND(device_bandwidths, c->blockio_device_bandwidths, a);
}
n++;
@@ -369,8 +368,7 @@ int bus_cgroup_set_property(
a->weight = ul;
if (!exist)
LIST_PREPEND(CGroupBlockIODeviceWeight, device_weights,
c->blockio_device_weights, a);
LIST_PREPEND(device_weights,c->blockio_device_weights, a);
}
n++;
@@ -517,7 +515,7 @@ int bus_cgroup_set_property(
a->m = !!strchr(rwm, 'm');
if (!exist)
LIST_PREPEND(CGroupDeviceAllow, device_allow, c->device_allow, a);
LIST_PREPEND(device_allow, c->device_allow, a);
}
n++;
+1 -1
View File
@@ -319,7 +319,7 @@ void bus_job_send_change_signal(Job *j) {
assert(j);
if (j->in_dbus_queue) {
LIST_REMOVE(Job, dbus_queue, j->manager->dbus_job_queue, j);
LIST_REMOVE(dbus_queue, j->manager->dbus_job_queue, j);
j->in_dbus_queue = false;
}
+2 -2
View File
@@ -627,7 +627,7 @@ void bus_unit_send_change_signal(Unit *u) {
assert(u);
if (u->in_dbus_queue) {
LIST_REMOVE(Unit, dbus_queue, u->manager->dbus_unit_queue, u);
LIST_REMOVE(dbus_queue, u->manager->dbus_unit_queue, u);
u->in_dbus_queue = false;
}
@@ -801,7 +801,7 @@ DBusHandlerResult bus_unit_queue_job(
if (!cl)
goto oom;
LIST_PREPEND(JobBusClient, client, j->bus_client_list, cl);
LIST_PREPEND(client, j->bus_client_list, cl);
reply = dbus_message_new_method_return(message);
if (!reply)
+1 -1
View File
@@ -1170,7 +1170,7 @@ static void shutdown_connection(Manager *m, DBusConnection *c) {
JobBusClient *cl, *nextcl;
LIST_FOREACH_SAFE(client, cl, nextcl, j->bus_client_list) {
if (cl->bus == c) {
LIST_REMOVE(JobBusClient, client, j->bus_client_list, cl);
LIST_REMOVE(client, j->bus_client_list, cl);
free(cl);
}
}
+2 -2
View File
@@ -48,7 +48,7 @@ static void device_unset_sysfs(Device *d) {
/* Remove this unit from the chain of devices which share the
* same sysfs path. */
first = hashmap_get(UNIT(d)->manager->devices_by_sysfs, d->sysfs);
LIST_REMOVE(Device, same_sysfs, first, d);
LIST_REMOVE(same_sysfs, first, d);
if (first)
hashmap_remove_and_replace(UNIT(d)->manager->devices_by_sysfs, d->sysfs, first->sysfs, first);
@@ -234,7 +234,7 @@ static int device_update_unit(Manager *m, struct udev_device *dev, const char *p
}
first = hashmap_get(m->devices_by_sysfs, sysfs);
LIST_PREPEND(Device, same_sysfs, first, DEVICE(u));
LIST_PREPEND(same_sysfs, first, DEVICE(u));
r = hashmap_replace(m->devices_by_sysfs, DEVICE(u)->sysfs, first);
if (r < 0)
+3 -3
View File
@@ -1706,7 +1706,7 @@ void exec_command_free_list(ExecCommand *c) {
ExecCommand *i;
while ((i = c)) {
LIST_REMOVE(ExecCommand, command, c, i);
LIST_REMOVE(command, c, i);
exec_command_done(i);
free(i);
}
@@ -2194,8 +2194,8 @@ void exec_command_append_list(ExecCommand **l, ExecCommand *e) {
if (*l) {
/* It's kind of important, that we keep the order here */
LIST_FIND_TAIL(ExecCommand, command, *l, end);
LIST_INSERT_AFTER(ExecCommand, command, *l, end, e);
LIST_FIND_TAIL(command, *l, end);
LIST_INSERT_AFTER(command, *l, end, e);
} else
*l = e;
}
+10 -10
View File
@@ -99,10 +99,10 @@ void job_free(Job *j) {
assert(!j->object_list);
if (j->in_run_queue)
LIST_REMOVE(Job, run_queue, j->manager->run_queue, j);
LIST_REMOVE(run_queue, j->manager->run_queue, j);
if (j->in_dbus_queue)
LIST_REMOVE(Job, dbus_queue, j->manager->dbus_job_queue, j);
LIST_REMOVE(dbus_queue, j->manager->dbus_job_queue, j);
if (j->timer_watch.type != WATCH_INVALID) {
assert(j->timer_watch.type == WATCH_JOB_TIMER);
@@ -114,7 +114,7 @@ void job_free(Job *j) {
}
while ((cl = j->bus_client_list)) {
LIST_REMOVE(JobBusClient, client, j->bus_client_list, cl);
LIST_REMOVE(client, j->bus_client_list, cl);
free(cl);
}
free(j);
@@ -267,9 +267,9 @@ JobDependency* job_dependency_new(Job *subject, Job *object, bool matters, bool
l->conflicts = conflicts;
if (subject)
LIST_PREPEND(JobDependency, subject, subject->subject_list, l);
LIST_PREPEND(subject, subject->subject_list, l);
LIST_PREPEND(JobDependency, object, object->object_list, l);
LIST_PREPEND(object, object->object_list, l);
return l;
}
@@ -278,9 +278,9 @@ void job_dependency_free(JobDependency *l) {
assert(l);
if (l->subject)
LIST_REMOVE(JobDependency, subject, l->subject->subject_list, l);
LIST_REMOVE(subject, l->subject->subject_list, l);
LIST_REMOVE(JobDependency, object, l->object->object_list, l);
LIST_REMOVE(object, l->object->object_list, l);
free(l);
}
@@ -491,7 +491,7 @@ int job_run_and_invalidate(Job *j) {
assert(j->type < _JOB_TYPE_MAX_IN_TRANSACTION);
assert(j->in_run_queue);
LIST_REMOVE(Job, run_queue, j->manager->run_queue, j);
LIST_REMOVE(run_queue, j->manager->run_queue, j);
j->in_run_queue = false;
if (j->state != JOB_WAITING)
@@ -910,7 +910,7 @@ void job_add_to_run_queue(Job *j) {
if (j->in_run_queue)
return;
LIST_PREPEND(Job, run_queue, j->manager->run_queue, j);
LIST_PREPEND(run_queue, j->manager->run_queue, j);
j->in_run_queue = true;
}
@@ -925,7 +925,7 @@ void job_add_to_dbus_queue(Job *j) {
* job might just have been created and not yet assigned to a
* connection/client. */
LIST_PREPEND(Job, dbus_queue, j->manager->dbus_job_queue, j);
LIST_PREPEND(dbus_queue, j->manager->dbus_job_queue, j);
j->in_dbus_queue = true;
}
+11 -11
View File
@@ -300,10 +300,10 @@ int config_parse_socket_listen(const char *unit,
p->fd = -1;
if (s->ports) {
LIST_FIND_TAIL(SocketPort, port, s->ports, tail);
LIST_INSERT_AFTER(SocketPort, port, s->ports, tail, p);
LIST_FIND_TAIL(port, s->ports, tail);
LIST_INSERT_AFTER(port, s->ports, tail, p);
} else
LIST_PREPEND(SocketPort, port, s->ports, p);
LIST_PREPEND(port, s->ports, p);
return 0;
}
@@ -1203,7 +1203,7 @@ int config_parse_timer(const char *unit,
v->value = u;
v->calendar_spec = c;
LIST_PREPEND(TimerValue, value, t->values, v);
LIST_PREPEND(value, t->values, v);
return 0;
}
@@ -1323,7 +1323,7 @@ int config_parse_path_spec(const char *unit,
s->type = b;
s->inotify_fd = -1;
LIST_PREPEND(PathSpec, spec, p->specs, s);
LIST_PREPEND(spec, p->specs, s);
return 0;
}
@@ -1657,7 +1657,7 @@ int config_parse_unit_condition_path(const char *unit,
if (!c)
return log_oom();
LIST_PREPEND(Condition, conditions, u->conditions, c);
LIST_PREPEND(conditions, u->conditions, c);
return 0;
}
@@ -1712,7 +1712,7 @@ int config_parse_unit_condition_string(const char *unit,
if (!c)
return log_oom();
LIST_PREPEND(Condition, conditions, u->conditions, c);
LIST_PREPEND(conditions, u->conditions, c);
return 0;
}
@@ -1766,7 +1766,7 @@ int config_parse_unit_condition_null(const char *unit,
if (!c)
return log_oom();
LIST_PREPEND(Condition, conditions, u->conditions, c);
LIST_PREPEND(conditions, u->conditions, c);
return 0;
}
@@ -2128,7 +2128,7 @@ int config_parse_device_allow(
a->w = !!strchr(m, 'w');
a->m = !!strchr(m, 'm');
LIST_PREPEND(CGroupDeviceAllow, device_allow, c->device_allow, a);
LIST_PREPEND(device_allow, c->device_allow, a);
return 0;
}
@@ -2234,7 +2234,7 @@ int config_parse_blockio_device_weight(
w->weight = lu;
LIST_PREPEND(CGroupBlockIODeviceWeight, device_weights, c->blockio_device_weights, w);
LIST_PREPEND(device_weights, c->blockio_device_weights, w);
return 0;
}
@@ -2310,7 +2310,7 @@ int config_parse_blockio_bandwidth(
b->bandwidth = (uint64_t) bytes;
b->read = read;
LIST_PREPEND(CGroupBlockIODeviceBandwidth, device_bandwidths, c->blockio_device_bandwidths, b);
LIST_PREPEND(device_bandwidths, c->blockio_device_bandwidths, b);
return 0;
}
+1 -1
View File
@@ -676,7 +676,7 @@ static unsigned manager_dispatch_gc_queue(Manager *m) {
unit_gc_sweep(u, gc_marker);
LIST_REMOVE(Unit, gc_queue, m->gc_queue, u);
LIST_REMOVE(gc_queue, m->gc_queue, u);
u->in_gc_queue = false;
n++;
+1 -1
View File
@@ -283,7 +283,7 @@ void path_free_specs(Path *p) {
while ((s = p->specs)) {
path_spec_unwatch(s, UNIT(p));
LIST_REMOVE(PathSpec, spec, p->specs, s);
LIST_REMOVE(spec, p->specs, s);
path_spec_done(s);
free(s);
}
+1 -1
View File
@@ -110,7 +110,7 @@ void socket_free_ports(Socket *s) {
assert(s);
while ((p = s->ports)) {
LIST_REMOVE(SocketPort, port, s->ports, p);
LIST_REMOVE(port, s->ports, p);
if (p->fd >= 0) {
unit_unwatch_fd(UNIT(s), &p->fd_watch);
+2 -2
View File
@@ -66,7 +66,7 @@ static void swap_unset_proc_swaps(Swap *s) {
* same kernel swap device. */
swaps = UNIT(s)->manager->swaps_by_proc_swaps;
first = hashmap_get(swaps, s->parameters_proc_swaps.what);
LIST_REMOVE(Swap, same_proc_swaps, first, s);
LIST_REMOVE(same_proc_swaps, first, s);
if (first)
hashmap_remove_and_replace(swaps,
@@ -364,7 +364,7 @@ static int swap_add_one(
p->what = wp;
first = hashmap_get(m->swaps_by_proc_swaps, wp);
LIST_PREPEND(Swap, same_proc_swaps, first, SWAP(u));
LIST_PREPEND(same_proc_swaps, first, SWAP(u));
r = hashmap_replace(m->swaps_by_proc_swaps, wp, first);
if (r < 0)
+1 -1
View File
@@ -54,7 +54,7 @@ void timer_free_values(Timer *t) {
assert(t);
while ((v = t->values)) {
LIST_REMOVE(TimerValue, value, t->values, v);
LIST_REMOVE(value, t->values, v);
if (v->calendar_spec)
calendar_spec_free(v->calendar_spec);
+2 -2
View File
@@ -775,10 +775,10 @@ static Job* transaction_add_one_job(Transaction *tr, JobType type, Unit *unit, b
j->override = override;
j->irreversible = tr->irreversible;
LIST_PREPEND(Job, transaction, f, j);
LIST_PREPEND(transaction, f, j);
if (hashmap_replace(tr->jobs, unit, f) < 0) {
LIST_REMOVE(Job, transaction, f, j);
LIST_REMOVE(transaction, f, j);
job_free(j);
return NULL;
}
+10 -10
View File
@@ -40,14 +40,14 @@
typedef struct MountPoint {
char *path;
dev_t devnum;
LIST_FIELDS (struct MountPoint, mount_point);
LIST_FIELDS(struct MountPoint, mount_point);
} MountPoint;
static void mount_point_free(MountPoint **head, MountPoint *m) {
assert(head);
assert(m);
LIST_REMOVE(MountPoint, mount_point, *head, m);
LIST_REMOVE(mount_point, *head, m);
free(m->path);
free(m);
@@ -125,7 +125,7 @@ static int mount_points_list_get(MountPoint **head) {
}
m->path = p;
LIST_PREPEND(MountPoint, mount_point, *head, m);
LIST_PREPEND(mount_point, *head, m);
}
r = 0;
@@ -190,7 +190,7 @@ static int swap_list_get(MountPoint **head) {
}
swap->path = d;
LIST_PREPEND(MountPoint, mount_point, *head, swap);
LIST_PREPEND(mount_point, *head, swap);
}
r = 0;
@@ -250,7 +250,7 @@ static int loopback_list_get(MountPoint **head) {
}
lb->path = loop;
LIST_PREPEND(MountPoint, mount_point, *head, lb);
LIST_PREPEND(mount_point, *head, lb);
}
return 0;
@@ -308,7 +308,7 @@ static int dm_list_get(MountPoint **head) {
m->path = node;
m->devnum = devnum;
LIST_PREPEND(MountPoint, mount_point, *head, m);
LIST_PREPEND(mount_point, *head, m);
}
return 0;
@@ -513,7 +513,7 @@ int umount_all(bool *changed) {
bool umount_changed;
LIST_HEAD(MountPoint, mp_list_head);
LIST_HEAD_INIT(MountPoint, mp_list_head);
LIST_HEAD_INIT(mp_list_head);
r = mount_points_list_get(&mp_list_head);
if (r < 0)
goto end;
@@ -543,7 +543,7 @@ int swapoff_all(bool *changed) {
int r;
LIST_HEAD(MountPoint, swap_list_head);
LIST_HEAD_INIT(MountPoint, swap_list_head);
LIST_HEAD_INIT(swap_list_head);
r = swap_list_get(&swap_list_head);
if (r < 0)
@@ -561,7 +561,7 @@ int loopback_detach_all(bool *changed) {
int r;
LIST_HEAD(MountPoint, loopback_list_head);
LIST_HEAD_INIT(MountPoint, loopback_list_head);
LIST_HEAD_INIT(loopback_list_head);
r = loopback_list_get(&loopback_list_head);
if (r < 0)
@@ -579,7 +579,7 @@ int dm_detach_all(bool *changed) {
int r;
LIST_HEAD(MountPoint, dm_list_head);
LIST_HEAD_INIT(MountPoint, dm_list_head);
LIST_HEAD_INIT(dm_list_head);
r = dm_list_get(&dm_list_head);
if (r < 0)
+14 -14
View File
@@ -171,7 +171,7 @@ int unit_add_name(Unit *u, const char *text) {
u->id = s;
u->instance = i;
LIST_PREPEND(Unit, units_by_type, u->manager->units_by_type[t], u);
LIST_PREPEND(units_by_type, u->manager->units_by_type[t], u);
if (UNIT_VTABLE(u)->init)
UNIT_VTABLE(u)->init(u);
@@ -284,7 +284,7 @@ void unit_add_to_load_queue(Unit *u) {
if (u->load_state != UNIT_STUB || u->in_load_queue)
return;
LIST_PREPEND(Unit, load_queue, u->manager->load_queue, u);
LIST_PREPEND(load_queue, u->manager->load_queue, u);
u->in_load_queue = true;
}
@@ -294,7 +294,7 @@ void unit_add_to_cleanup_queue(Unit *u) {
if (u->in_cleanup_queue)
return;
LIST_PREPEND(Unit, cleanup_queue, u->manager->cleanup_queue, u);
LIST_PREPEND(cleanup_queue, u->manager->cleanup_queue, u);
u->in_cleanup_queue = true;
}
@@ -307,7 +307,7 @@ void unit_add_to_gc_queue(Unit *u) {
if (unit_check_gc(u))
return;
LIST_PREPEND(Unit, gc_queue, u->manager->gc_queue, u);
LIST_PREPEND(gc_queue, u->manager->gc_queue, u);
u->in_gc_queue = true;
u->manager->n_in_gc_queue ++;
@@ -326,7 +326,7 @@ void unit_add_to_dbus_queue(Unit *u) {
return;
}
LIST_PREPEND(Unit, dbus_queue, u->manager->dbus_unit_queue, u);
LIST_PREPEND(dbus_queue, u->manager->dbus_unit_queue, u);
u->in_dbus_queue = true;
}
@@ -439,24 +439,24 @@ void unit_free(Unit *u) {
bidi_set_free(u, u->dependencies[d]);
if (u->type != _UNIT_TYPE_INVALID)
LIST_REMOVE(Unit, units_by_type, u->manager->units_by_type[u->type], u);
LIST_REMOVE(units_by_type, u->manager->units_by_type[u->type], u);
if (u->in_load_queue)
LIST_REMOVE(Unit, load_queue, u->manager->load_queue, u);
LIST_REMOVE(load_queue, u->manager->load_queue, u);
if (u->in_dbus_queue)
LIST_REMOVE(Unit, dbus_queue, u->manager->dbus_unit_queue, u);
LIST_REMOVE(dbus_queue, u->manager->dbus_unit_queue, u);
if (u->in_cleanup_queue)
LIST_REMOVE(Unit, cleanup_queue, u->manager->cleanup_queue, u);
LIST_REMOVE(cleanup_queue, u->manager->cleanup_queue, u);
if (u->in_gc_queue) {
LIST_REMOVE(Unit, gc_queue, u->manager->gc_queue, u);
LIST_REMOVE(gc_queue, u->manager->gc_queue, u);
u->manager->n_in_gc_queue--;
}
if (u->in_cgroup_queue)
LIST_REMOVE(Unit, cgroup_queue, u->manager->cgroup_queue, u);
LIST_REMOVE(cgroup_queue, u->manager->cgroup_queue, u);
if (u->cgroup_path) {
hashmap_remove(u->manager->cgroup_unit, u->cgroup_path);
@@ -952,7 +952,7 @@ int unit_load(Unit *u) {
assert(u);
if (u->in_load_queue) {
LIST_REMOVE(Unit, load_queue, u->manager->load_queue, u);
LIST_REMOVE(load_queue, u->manager->load_queue, u);
u->in_load_queue = false;
}
@@ -2670,7 +2670,7 @@ Unit* unit_ref_set(UnitRef *ref, Unit *u) {
unit_ref_unset(ref);
ref->unit = u;
LIST_PREPEND(UnitRef, refs, u->refs, ref);
LIST_PREPEND(refs, u->refs, ref);
return u;
}
@@ -2680,7 +2680,7 @@ void unit_ref_unset(UnitRef *ref) {
if (!ref->unit)
return;
LIST_REMOVE(UnitRef, refs, ref->unit->refs, ref);
LIST_REMOVE(refs, ref->unit->refs, ref);
ref->unit = NULL;
}