- * @param arg1 The second argument for 'callback'
- * @param arg2 The third argument for 'callback'
- * @param arg3 The forth argument for 'callback'
- * @return 0 in case of success or -1 in case of error
- */
-int jobs_queue3(
- void *group,
- int timeout,
- void (*callback)(int, void*, void *, void*),
- void *arg1,
- void *arg2,
- void *arg3)
-{
- const char *info;
- struct job *job;
- int rc;
-
- pthread_mutex_lock(&mutex);
-
- /* allocates the job */
- job = job_create(group, timeout, callback, arg1, arg2, arg3);
- if (!job) {
- errno = ENOMEM;
- info = "out of memory";
- goto error;
- }
-
- /* check availability */
- if (remains == 0) {
- errno = EBUSY;
- info = "too many jobs";
- goto error2;
- }
-
- /* start a thread if needed */
- if (waiting == 0 && started < allowed) {
- /* all threads are busy and a new can be started */
- rc = start_one_thread();
- if (rc < 0 && started == 0) {
- info = "can't start first thread";
- goto error2;
- }
- }
-
- /* queues the job */
- remains--;
- job_add2(job, NULL);
-
- /* signal an existing job */
- pthread_cond_signal(&cond);
- pthread_mutex_unlock(&mutex);
- return 0;
-
-error2:
- job->next = free_jobs;
- free_jobs = job;
-error:
- ERROR("can't process job with threads: %s, %m", info);
- pthread_mutex_unlock(&mutex);
- return -1;
-}
-
-/**
- * Run a asynchronous job represented by 'callback'
- * with the 'timeout' but only returns after job completion.
- * @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.