Merge pull request #1980 from evverx/sd-event-use-prioq-ensure-allocated
sd-event: update tests; small refactoring
This commit is contained in:
@@ -416,11 +416,9 @@ _public_ int sd_event_new(sd_event** ret) {
|
||||
e->original_pid = getpid();
|
||||
e->perturb = USEC_INFINITY;
|
||||
|
||||
e->pending = prioq_new(pending_prioq_compare);
|
||||
if (!e->pending) {
|
||||
r = -ENOMEM;
|
||||
r = prioq_ensure_allocated(&e->pending, pending_prioq_compare);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
e->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
|
||||
if (e->epoll_fd < 0) {
|
||||
@@ -1052,17 +1050,13 @@ _public_ int sd_event_add_time(
|
||||
d = event_get_clock_data(e, type);
|
||||
assert(d);
|
||||
|
||||
if (!d->earliest) {
|
||||
d->earliest = prioq_new(earliest_time_prioq_compare);
|
||||
if (!d->earliest)
|
||||
return -ENOMEM;
|
||||
}
|
||||
r = prioq_ensure_allocated(&d->earliest, earliest_time_prioq_compare);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (!d->latest) {
|
||||
d->latest = prioq_new(latest_time_prioq_compare);
|
||||
if (!d->latest)
|
||||
return -ENOMEM;
|
||||
}
|
||||
r = prioq_ensure_allocated(&d->latest, latest_time_prioq_compare);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (d->fd < 0) {
|
||||
r = event_setup_timer_fd(e, d, clock);
|
||||
@@ -1313,11 +1307,9 @@ _public_ int sd_event_add_exit(
|
||||
assert_return(e->state != SD_EVENT_FINISHED, -ESTALE);
|
||||
assert_return(!event_pid_changed(e), -ECHILD);
|
||||
|
||||
if (!e->exit) {
|
||||
e->exit = prioq_new(exit_prioq_compare);
|
||||
if (!e->exit)
|
||||
return -ENOMEM;
|
||||
}
|
||||
r = prioq_ensure_allocated(&e->exit, exit_prioq_compare);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
s = source_new(e, !ret, SOURCE_EXIT);
|
||||
if (!s)
|
||||
|
||||
@@ -158,6 +158,16 @@ static int exit_handler(sd_event_source *s, void *userdata) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
static bool got_post = false;
|
||||
|
||||
static int post_handler(sd_event_source *s, void *userdata) {
|
||||
log_info("got post handler");
|
||||
|
||||
got_post = true;
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
static void test_basic(void) {
|
||||
sd_event *e = NULL;
|
||||
sd_event_source *w = NULL, *x = NULL, *y = NULL, *z = NULL, *q = NULL, *t = NULL;
|
||||
@@ -230,10 +240,13 @@ static void test_basic(void) {
|
||||
sd_event_source_unref(y);
|
||||
|
||||
do_quit = true;
|
||||
assert_se(sd_event_add_post(e, NULL, post_handler, NULL) >= 0);
|
||||
assert_se(sd_event_source_set_time(z, now(CLOCK_MONOTONIC) + 200 * USEC_PER_MSEC) >= 0);
|
||||
assert_se(sd_event_source_set_enabled(z, SD_EVENT_ONESHOT) >= 0);
|
||||
|
||||
assert_se(sd_event_loop(e) >= 0);
|
||||
assert_se(got_post);
|
||||
assert_se(got_exit);
|
||||
|
||||
sd_event_source_unref(z);
|
||||
sd_event_source_unref(q);
|
||||
|
||||
Reference in New Issue
Block a user