X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fjobs.c;h=217c5391e2b915a6302085b1d1528e3a7f7d49bf;hb=c330ecf92fef81fdb0471715326b8bc6b4d52bc6;hp=d06d24cfe008da0b51a85f712d6ca305d5b49569;hpb=fcd68bb0f872c65c4317377f787f5fdddea6e5d0;p=src%2Fapp-framework-binder.git diff --git a/src/jobs.c b/src/jobs.c index d06d24cf..217c5391 100644 --- a/src/jobs.c +++ b/src/jobs.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016, 2017, 2018 "IoT.bzh" + * Copyright (C) 2016-2019 "IoT.bzh" * Author José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,12 +17,6 @@ #define _GNU_SOURCE -#if defined(NO_JOBS_WATCHDOG) -# define HAS_WATCHDOG 0 -#else -# define HAS_WATCHDOG 1 -#endif - #include #include #include @@ -36,14 +30,11 @@ #include #include -#include "fdev.h" -#if HAS_WATCHDOG -#include -#endif #include "jobs.h" #include "sig-monitor.h" #include "verbose.h" +#include "systemd.h" #define EVENT_TIMEOUT_TOP ((uint64_t)-1) #define EVENT_TIMEOUT_CHILD ((uint64_t)10000) @@ -71,7 +62,6 @@ struct evloop unsigned state; /**< encoded state */ int efd; /**< event notification */ struct sd_event *sdev; /**< the systemd event loop */ - struct fdev *fdev; /**< handling of events */ struct thread *holder; /**< holder of the evloop */ }; @@ -355,6 +345,9 @@ static int evloop_get() if (evloop.holder) return evloop.holder == ct; + if (!evloop.sdev) + return 0; + ct->nholder = NULL; evloop.holder = ct; return 1; @@ -791,16 +784,15 @@ static struct sd_event *get_sd_event_locked() goto error1; } /* create the systemd event loop */ - rc = sd_event_new(&evloop.sdev); - if (rc < 0) { - ERROR("can't make new event loop"); + evloop.sdev = systemd_get_event_loop(); + if (!evloop.sdev) { + ERROR("can't make event loop"); goto error2; } /* put the eventfd in the event loop */ rc = sd_event_add_io(evloop.sdev, NULL, evloop.efd, EPOLLIN, on_evloop_efd, NULL); if (rc < 0) { ERROR("can't register eventfd"); - sd_event_unref(evloop.sdev); evloop.sdev = NULL; error2: close(evloop.efd); @@ -816,12 +808,10 @@ error1: } /** - * Gets a sd_event item for the current thread. - * @return a sd_event or NULL in case of error + * Ensure that the current running thread can control the event loop. */ -struct sd_event *jobs_get_sd_event() +void jobs_acquire_event_manager() { - struct sd_event *result; struct thread lt; /* ensure an existing thread environment */ @@ -832,7 +822,7 @@ struct sd_event *jobs_get_sd_event() /* process */ pthread_mutex_lock(&mutex); - result = get_sd_event_locked(); + get_sd_event_locked(); pthread_mutex_unlock(&mutex); /* release the faked thread environment if needed */ @@ -851,8 +841,6 @@ struct sd_event *jobs_get_sd_event() evloop_release(); current_thread = NULL; } - - return result; } /** @@ -889,12 +877,6 @@ int jobs_start(int allowed_count, int start_count, int waiter_count, void (*star running = 0; remains = waiter_count; -#if HAS_WATCHDOG - /* set the watchdog */ - if (sd_watchdog_enabled(0, NULL)) - sd_event_set_watchdog(get_sd_event_locked(), 1); -#endif - /* start at least one thread: the current one */ launched = 1; while (launched < start_count) {