mirror of
https://github.com/systemd/systemd.git
synced 2024-10-28 11:55:44 +03:00
sd-event: use structure initialization instead of new0() where possible
This commit is contained in:
parent
a5cc7e5ac1
commit
d08eb1fabd
@ -504,16 +504,32 @@ _public_ int sd_event_new(sd_event** ret) {
|
|||||||
|
|
||||||
assert_return(ret, -EINVAL);
|
assert_return(ret, -EINVAL);
|
||||||
|
|
||||||
e = new0(sd_event, 1);
|
e = new(sd_event, 1);
|
||||||
if (!e)
|
if (!e)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
e->n_ref = 1;
|
*e = (sd_event) {
|
||||||
e->watchdog_fd = e->epoll_fd = e->realtime.fd = e->boottime.fd = e->monotonic.fd = e->realtime_alarm.fd = e->boottime_alarm.fd = -1;
|
.n_ref = 1,
|
||||||
e->realtime.next = e->boottime.next = e->monotonic.next = e->realtime_alarm.next = e->boottime_alarm.next = USEC_INFINITY;
|
.epoll_fd = -1,
|
||||||
e->realtime.wakeup = e->boottime.wakeup = e->monotonic.wakeup = e->realtime_alarm.wakeup = e->boottime_alarm.wakeup = WAKEUP_CLOCK_DATA;
|
.watchdog_fd = -1,
|
||||||
e->original_pid = getpid_cached();
|
.realtime.wakeup = WAKEUP_CLOCK_DATA,
|
||||||
e->perturb = USEC_INFINITY;
|
.realtime.fd = -1,
|
||||||
|
.realtime.next = USEC_INFINITY,
|
||||||
|
.boottime.wakeup = WAKEUP_CLOCK_DATA,
|
||||||
|
.boottime.fd = -1,
|
||||||
|
.boottime.next = USEC_INFINITY,
|
||||||
|
.monotonic.wakeup = WAKEUP_CLOCK_DATA,
|
||||||
|
.monotonic.fd = -1,
|
||||||
|
.monotonic.next = USEC_INFINITY,
|
||||||
|
.realtime_alarm.wakeup = WAKEUP_CLOCK_DATA,
|
||||||
|
.realtime_alarm.fd = -1,
|
||||||
|
.realtime_alarm.next = USEC_INFINITY,
|
||||||
|
.boottime_alarm.wakeup = WAKEUP_CLOCK_DATA,
|
||||||
|
.boottime_alarm.fd = -1,
|
||||||
|
.boottime_alarm.next = USEC_INFINITY,
|
||||||
|
.perturb = USEC_INFINITY,
|
||||||
|
.original_pid = getpid_cached(),
|
||||||
|
};
|
||||||
|
|
||||||
r = prioq_ensure_allocated(&e->pending, pending_prioq_compare);
|
r = prioq_ensure_allocated(&e->pending, pending_prioq_compare);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@ -730,13 +746,15 @@ static int event_make_signal_data(
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
d = new0(struct signal_data, 1);
|
d = new(struct signal_data, 1);
|
||||||
if (!d)
|
if (!d)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
d->wakeup = WAKEUP_SIGNAL_DATA;
|
*d = (struct signal_data) {
|
||||||
d->fd = -1;
|
.wakeup = WAKEUP_SIGNAL_DATA,
|
||||||
d->priority = priority;
|
.fd = -1,
|
||||||
|
.priority = priority,
|
||||||
|
};
|
||||||
|
|
||||||
r = hashmap_put(e->signal_data, &d->priority, d);
|
r = hashmap_put(e->signal_data, &d->priority, d);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
@ -1066,15 +1084,18 @@ static sd_event_source *source_new(sd_event *e, bool floating, EventSourceType t
|
|||||||
|
|
||||||
assert(e);
|
assert(e);
|
||||||
|
|
||||||
s = new0(sd_event_source, 1);
|
s = new(sd_event_source, 1);
|
||||||
if (!s)
|
if (!s)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
s->n_ref = 1;
|
*s = (struct sd_event_source) {
|
||||||
s->event = e;
|
.n_ref = 1,
|
||||||
s->floating = floating;
|
.event = e,
|
||||||
s->type = type;
|
.floating = floating,
|
||||||
s->pending_index = s->prepare_index = PRIOQ_IDX_NULL;
|
.type = type,
|
||||||
|
.pending_index = PRIOQ_IDX_NULL,
|
||||||
|
.prepare_index = PRIOQ_IDX_NULL,
|
||||||
|
};
|
||||||
|
|
||||||
if (!floating)
|
if (!floating)
|
||||||
sd_event_ref(e);
|
sd_event_ref(e);
|
||||||
|
Loading…
Reference in New Issue
Block a user