+ /* put the eventfd in the event loop */
+ rc = sd_event_add_io(el->sdev, NULL, el->efd, EPOLLIN, on_evloop_efd, el);
+ if (rc < 0) {
+ ERROR("can't register eventfd");
+ sd_event_unref(el->sdev);
+ el->sdev = NULL;
+error2:
+ close(el->efd);
+error1:
+ pthread_mutex_unlock(&mutex);
+ return NULL;
+ }
+ /* terminate creation */
+ el->state = 0;
+ }
+
+ /* attach the event loop to the current thread */
+ if (current_evloop != el) {
+ if (current_evloop)
+ current_evloop->state -= EVLOOP_STATE_LOCK;
+ current_evloop = el;
+ el->state += EVLOOP_STATE_LOCK;
+ }
+
+ /* wait for a modifiable event loop */
+ while (el->state & EVLOOP_STATE_WAIT) {
+ x = 1;
+ write(el->efd, &x, sizeof x);
+ pthread_cond_wait(&el->cond, &mutex);