+/**
+ * Internal callback for evloop management.
+ * The effect of this function is hidden: it exits
+ * the waiting poll if any. Then it wakes up a thread
+ * awaiting the evloop using signal.
+ */
+static int on_evloop_efd(sd_event_source *s, int fd, uint32_t revents, void *userdata)
+{
+ uint64_t x;
+ struct evloop *evloop = userdata;
+ read(evloop->efd, &x, sizeof x);
+ pthread_mutex_lock(&mutex);
+ pthread_cond_broadcast(&evloop->cond);
+ pthread_mutex_unlock(&mutex);
+ return 1;
+}
+
+/**
+ * unlock the event loop if needed by sending
+ * an event.
+ * @param el the event loop to unlock
+ * @param wait wait the unlocked state of the event loop
+ */
+static void unlock_evloop(struct evloop *el, int wait)
+{
+ /* wait for a modifiable event loop */
+ while (__atomic_load_n(&el->state, __ATOMIC_RELAXED) & EVLOOP_STATE_WAIT) {
+ uint64_t x = 1;
+ write(el->efd, &x, sizeof x);
+ if (!wait)
+ break;
+ pthread_cond_wait(&el->cond, &mutex);
+ }
+}
+
+/**
+ * Unlocks the execution flow designed by 'jobloop'.
+ * @param jobloop indication of the flow to unlock
+ * @return 0 in case of success of -1 on error
+ */
+int jobs_leave(struct jobloop *jobloop)
+{
+ struct thread *t;
+ int i;
+
+ pthread_mutex_lock(&mutex);
+ t = threads;
+ while (t && t != (struct thread*)jobloop)
+ t = t->next;
+ if (!t) {
+ errno = EINVAL;
+ } else {
+ t->stop = 1;
+ if (t->waits)
+ pthread_cond_broadcast(&cond);
+ else {
+ i = (int)(sizeof evloop / sizeof *evloop);
+ while(i) {
+ if (evloop[--i].holder == t) {
+ unlock_evloop(&evloop[i], 0);
+ break;
+ }
+ }
+ }
+ }
+ pthread_mutex_unlock(&mutex);
+ return -!t;
+}
+
+/**
+ * Calls synchronously the job represented by 'callback' and 'arg1'
+ * for the 'group' and the 'timeout' and waits for its completion.
+ * @param group The group of the job or NULL when no group.
+ * @param timeout The maximum execution time in seconds of the job
+ * or 0 for unlimited time.
+ * @param callback The function to execute for achieving the job.
+ * Its first parameter is either 0 on normal flow
+ * or the signal number that broke the normal flow.
+ * The remaining parameter is the parameter 'arg1'
+ * given here.
+ * @param arg The second argument for 'callback'
+ * @return 0 in case of success or -1 in case of error
+ */
+int jobs_call(
+ const void *group,