/* Ensure that at least one server looks at the queue. */
stat = start_server(jq);
- if (stat == 0) {
- pthread_mutex_unlock(&jq->mutex);
- }
+ pthread_mutex_unlock(&jq->mutex);
Dmsg0(100, "Return jobq_add\n");
return stat;
}
jq->ready_jobs->prepend(item);
stat = start_server(jq);
- if (stat != 0) {
- return stat;
- }
+
pthread_mutex_unlock(&jq->mutex);
Dmsg0(100, "Return jobq_remove\n");
return stat;
if (jq->idle_workers > 0) {
Dmsg0(100, "Signal worker to wake up\n");
if ((stat = pthread_cond_signal(&jq->work)) != 0) {
- pthread_mutex_unlock(&jq->mutex);
return stat;
}
} else if (jq->num_workers < jq->max_workers) {
/* No idle threads so create a new one */
set_thread_concurrency(jq->max_workers + 1);
if ((stat = pthread_create(&id, &jq->attr, jobq_server, (void *)jq)) != 0) {
- pthread_mutex_unlock(&jq->mutex);
return stat;
}
- jq->num_workers++;
}
return stat;
}
if ((stat = pthread_mutex_lock(&jq->mutex)) != 0) {
return NULL;
}
+ jq->num_workers++;
for (;;) {
struct timeval tv;
if (!jq->ready_jobs->empty()) {
Dmsg0(100, "ready queue not empty start server\n");
if (start_server(jq) != 0) {
+ jq->num_workers--;
+ pthread_mutex_unlock(&jq->mutex);
return NULL;
}
}
jq->running_jobs->append(je);
Dmsg1(100, "Took jobid=%d from ready and appended to run\n", jcr->JobId);
if ((stat = pthread_mutex_unlock(&jq->mutex)) != 0) {
+ jq->num_workers--;
return NULL;
}
/* Call user's routine here */
jq->engine(je->jcr);
Dmsg1(100, "Back from user engine jobid=%d.\n", jcr->JobId);
if ((stat = pthread_mutex_lock(&jq->mutex)) != 0) {
+ jq->num_workers--;
free(je); /* release job entry */
return NULL;
}