-/**
- * 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);
- }
-}
-