- pthread_mutex_unlock(&mutex);
- pthread_cond_broadcast(&cond);
- pthread_join(other, NULL);
- pthread_mutex_lock(&mutex);
+ if (t->waits)
+ pthread_cond_broadcast(&cond);
+ else
+ evloop_wakeup();
+ }
+ 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,
+ int timeout,
+ void (*callback)(int, void*),
+ void *arg)
+{
+ struct sync sync;
+
+ sync.callback = callback;
+ sync.arg = arg;
+
+ return do_sync(group, timeout, call_cb, &sync);
+}
+
+/**
+ * Ensure that the current running thread can control the event loop.
+ */
+void jobs_acquire_event_manager()
+{
+ struct thread lt;
+
+ /* ensure an existing thread environment */
+ if (!current_thread) {
+ memset(<, 0, sizeof lt);
+ current_thread = <