The removal of the systemd event loop will be made
in later changes.
Change-Id: Ia6c52feb4969f360c31cbfc50ae991f1767f007d
Signed-off-by: Jose Bollo <jose.bollo@iot.bzh>
-#if !defined(REMOVE_SYSTEMD_EVENT)
-
#include "afb-systemd.h"
#include "fdev-systemd.h"
#include "afb-systemd.h"
#include "fdev-systemd.h"
{
return fdev_systemd_create(afb_systemd_get_event_loop(), fd);
}
{
return fdev_systemd_create(afb_systemd_get_event_loop(), fd);
}
-
-#else
-
-#include "jobs.h"
-#include "fdev-epoll.h"
-
-struct fdev *afb_fdev_create(int fd)
-{
- return fdev_epoll_add(jobs_get_fdev_epoll(), fd);
-}
-
-#endif
-
#include "sig-monitor.h"
#include "verbose.h"
#include "sig-monitor.h"
#include "verbose.h"
-#if defined(REMOVE_SYSTEMD_EVENT)
-#include "fdev-epoll.h"
-#endif
-
#define EVENT_TIMEOUT_TOP ((uint64_t)-1)
#define EVENT_TIMEOUT_CHILD ((uint64_t)10000)
#define EVENT_TIMEOUT_TOP ((uint64_t)-1)
#define EVENT_TIMEOUT_CHILD ((uint64_t)10000)
/* event loop */
static struct evloop evloop;
/* event loop */
static struct evloop evloop;
-#if defined(REMOVE_SYSTEMD_EVENT)
-static struct fdev_epoll *fdevepoll;
-static int waitevt;
-#endif
-
/**
* Create a new job with the given parameters
* @param group the group of the job
/**
* Create a new job with the given parameters
* @param group the group of the job
job->callback(SIGABRT, job->arg);
}
job->callback(SIGABRT, job->arg);
}
-#if defined(REMOVE_SYSTEMD_EVENT)
-/**
- * Gets a fdev_epoll item.
- * @return a fdev_epoll or NULL in case of error
- */
-static struct fdev_epoll *get_fdevepoll()
-{
- struct fdev_epoll *result;
-
- result = fdevepoll;
- if (!result)
- result = fdevepoll = fdev_epoll_create();
-
- return result;
-}
-#endif
-
/**
* Monitored normal callback for events.
* This function is called by the monitor
/**
* Monitored normal callback for events.
* This function is called by the monitor
-#if defined(REMOVE_SYSTEMD_EVENT)
-/**
- * Monitored normal loop for waiting events.
- * @param signum 0 on normal flow or the number
- * of the signal that interrupted the normal
- * flow
- * @param arg the events to run
- */
-static void monitored_wait_and_dispatch(int signum, void *arg)
-{
- struct fdev_epoll *fdev_epoll = arg;
- if (!signum) {
- fdev_epoll_wait_and_dispatch(fdev_epoll, -1);
- }
-}
-#endif
-
/**
* Enter the thread
* @param me the description of the thread to enter
/**
* Enter the thread
* @param me the description of the thread to enter
/* release the run job */
job_release(job);
/* release the run job */
job_release(job);
-#if !defined(REMOVE_SYSTEMD_EVENT)
/* no job, check event loop wait */
} else if (evloop_get()) {
if (evloop.state != 0) {
/* no job, check event loop wait */
} else if (evloop_get()) {
if (evloop.state != 0) {
pthread_cond_wait(&cond, &mutex);
me->waits = 0;
running++;
pthread_cond_wait(&cond, &mutex);
me->waits = 0;
running++;
-#else
- } else if (waitevt) {
- /* no job and not events */
- running--;
- if (!running)
- ERROR("Entering job deep sleep! Check your bindings.");
- me->waits = 1;
- pthread_cond_wait(&cond, &mutex);
- me->waits = 0;
- running++;
- } else {
- /* wait for events */
- waitevt = 1;
- pthread_mutex_unlock(&mutex);
- sig_monitor(0, monitored_wait_and_dispatch, get_fdevepoll());
- pthread_mutex_lock(&mutex);
- waitevt = 0;
-#endif
-/* temporary hack */
-#if !defined(REMOVE_SYSTEMD_EVENT)
-__attribute__((unused))
-#endif
-static void evloop_callback(void *arg, uint32_t event, struct fdev *fdev)
-{
- sig_monitor(0, evloop_run, arg);
-}
-
/**
* Gets a sd_event item for the current thread.
* @return a sd_event or NULL in case of error
/**
* Gets a sd_event item for the current thread.
* @return a sd_event or NULL in case of error
rc = sd_event_add_io(evloop.sdev, NULL, evloop.efd, EPOLLIN, on_evloop_efd, NULL);
if (rc < 0) {
ERROR("can't register eventfd");
rc = sd_event_add_io(evloop.sdev, NULL, evloop.efd, EPOLLIN, on_evloop_efd, NULL);
if (rc < 0) {
ERROR("can't register eventfd");
-#if !defined(REMOVE_SYSTEMD_EVENT)
sd_event_unref(evloop.sdev);
evloop.sdev = NULL;
error2:
sd_event_unref(evloop.sdev);
evloop.sdev = NULL;
error2:
-#else
- goto error3;
- }
- /* handle the event loop */
- evloop.fdev = fdev_epoll_add(get_fdevepoll(), sd_event_get_fd(evloop.sdev));
- if (!evloop.fdev) {
- ERROR("can't create fdev");
-error3:
- sd_event_unref(evloop.sdev);
-error2:
- close(evloop.efd);
-error1:
- memset(&evloop, 0, sizeof evloop);
- return NULL;
- }
- fdev_set_autoclose(evloop.fdev, 0);
- fdev_set_events(evloop.fdev, EPOLLIN);
- fdev_set_callback(evloop.fdev, evloop_callback, NULL);
-#endif
}
/* acquire the event loop */
}
/* acquire the event loop */
-#if defined(REMOVE_SYSTEMD_EVENT)
-/**
- * Gets the fdev_epoll item.
- * @return a fdev_epoll or NULL in case of error
- */
-struct fdev_epoll *jobs_get_fdev_epoll()
-{
- struct fdev_epoll *result;
-
- pthread_mutex_lock(&mutex);
- result = get_fdevepoll();
- pthread_mutex_unlock(&mutex);
-
- return result;
-}
-#endif
-
/**
* Enter the jobs processing loop.
* @param allowed_count Maximum count of thread for jobs including this one
/**
* Enter the jobs processing loop.
* @param allowed_count Maximum count of thread for jobs including this one
void (*start)(int signum, void* arg),
void *arg);
void (*start)(int signum, void* arg),
void *arg);
-#if !defined(REMOVE_SYSTEMD_EVENT)
struct sd_event;
extern struct sd_event *jobs_get_sd_event();
struct sd_event;
extern struct sd_event *jobs_get_sd_event();
-#else
-struct fdev_epoll;
-extern struct fdev_epoll *jobs_get_fdev_epoll();
-#endif