+int jobs_add_event_loop(void *key, int timeout, void (*evloop)(int signum, void*), void *closure)
+{
+ struct job *job;
+
+ pthread_mutex_lock(&mutex);
+ job = job_create(key, timeout, (void (*)(int, void *, void *, void *))evloop, closure, NULL, NULL);
+ if (job) {
+ /* adds the loop */
+ job->next = first_evloop;
+ first_evloop = job;
+
+ /* signal the loop */
+ pthread_cond_signal(&cond);
+ }
+ pthread_mutex_unlock(&mutex);
+ return -!job;
+}
+
+int jobs_add_me()
+{
+ pthread_t me;
+ struct thread *t;
+
+ /* how am i? */
+ me = pthread_self();
+
+ /* request all threads to stop */
+ pthread_mutex_lock(&mutex);
+ t = threads;
+ while (t) {
+ if (pthread_equal(t->tid, me)) {
+ pthread_mutex_unlock(&mutex);
+ ERROR("thread already running");
+ errno = EINVAL;
+ return -1;
+ }
+ t = t->next;
+ }
+
+ /* allowed... */
+ allowed++;
+ pthread_mutex_unlock(&mutex);
+
+ /* run */
+ thread_main_loop(NULL);
+
+ /* returns */
+ pthread_mutex_lock(&mutex);
+ allowed--;
+ pthread_mutex_unlock(&mutex);
+ return 0;
+}
+
+