jobs: Wake up an event loop if needed 17/22417/1
authorJosé Bollo <jose.bollo@iot.bzh>
Fri, 13 Sep 2019 09:01:42 +0000 (11:01 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Fri, 13 Sep 2019 09:07:57 +0000 (11:07 +0200)
A queued job must be treated. It was not the case
when the job was queued from a foreign thread.
This change detect that a potential hang exists
and wake up an event loop to avoid it.

Bug-AGL: SPEC-2809

Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Change-Id: Id12d32771ea37df5f5f2e208ec9645a6c4b0d0ab

src/jobs.c

index a9773aa..3b617b5 100644 (file)
@@ -510,7 +510,7 @@ static int queue_job(
                enum start_mode start_mode)
 {
        struct job *job;
-       int rc;
+       int rc, busy;
 
        pthread_mutex_lock(&mutex);
 
@@ -527,8 +527,9 @@ static int queue_job(
                goto error;
 
        /* start a thread if needed */
+       busy = busy_thread_count == started_thread_count;
        if (start_mode != Start_Lazy
-        && busy_thread_count == started_thread_count
+        && busy
         && (start_mode == Start_Urgent || remaining_job_count + started_thread_count < allowed_job_count)
         && started_thread_count < allowed_thread_count) {
                /* all threads are busy and a new can be started */
@@ -537,11 +538,16 @@ static int queue_job(
                        ERROR("can't start initial thread: %m");
                        goto error2;
                }
+               busy = 0;
        }
 
        /* queues the job */
        job_add(job);
 
+       /* wakeup an evloop if needed */
+       if (busy)
+               evloop_wakeup();
+
        /* signal an existing job */
        pthread_cond_signal(&cond);
        pthread_mutex_unlock(&mutex);