+/**
+ * get the eventloop for the current thread
+ */
+static int evloop_get()
+{
+ struct thread *ct = current_thread;
+
+ if (evloop.holder)
+ return evloop.holder == ct;
+
+ ct->nholder = NULL;
+ evloop.holder = ct;
+ return 1;
+}
+
+/**
+ * acquire the eventloop for the current thread
+ */
+static void evloop_acquire()
+{
+ struct thread **pwait, *ct;
+ pthread_cond_t cond;
+
+ /* try to get the evloop */
+ if (!evloop_get()) {
+ /* failed, init waiting state */
+ ct = current_thread;
+ ct->nholder = NULL;
+ ct->cwhold = &cond;
+ pthread_cond_init(&cond, NULL);
+
+ /* queue current thread in holder list */
+ pwait = &evloop.holder;
+ while (*pwait)
+ pwait = &(*pwait)->nholder;
+ *pwait = ct;
+
+ /* wake up the evloop */
+ evloop_wakeup();
+
+ /* wait to acquire the evloop */
+ pthread_cond_wait(&cond, &mutex);
+ pthread_cond_destroy(&cond);
+ }
+}
+
+/**
+ * Enter the thread
+ * @param me the description of the thread to enter
+ */
+static void thread_enter(volatile struct thread *me)
+{
+ evloop_release();