-error:
- if (job1) {
- job1->next = free_jobs;
- free_jobs = job1;
- }
- if (job2) {
- job2->next = free_jobs;
- free_jobs = job2;
- }
- ERROR("can't process job with threads: %s, %m", info);
+/**
+ * Initialise the job stuff.
+ * @param allowed_count Maximum count of thread for jobs (can be 0,
+ * see 'jobs_add_me' for merging new threads)
+ * @param start_count Count of thread to start now, must be lower.
+ * @param waiter_count Maximum count of jobs that can be waiting.
+ * @return 0 in case of success or -1 in case of error.
+ */
+int jobs_init(int allowed_count, int start_count, int waiter_count)
+{
+ int rc, launched;
+
+ assert(allowed_count >= 0);
+ assert(start_count >= 0);
+ assert(waiter_count > 0);
+ assert(start_count <= allowed_count);
+
+ /* records the allowed count */
+ allowed = allowed_count;
+ started = 0;
+ waiting = 0;
+ remains = waiter_count;
+
+ /* start at least one thread */
+ pthread_mutex_lock(&mutex);
+ launched = 0;
+ while (launched < start_count && start_one_thread() == 0)
+ launched++;
+ rc = -(launched != start_count);