qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [RFC PATCH 1/3] cpus: protect queued_work_* with work_m


From: Frederic Konrad
Subject: Re: [Qemu-devel] [RFC PATCH 1/3] cpus: protect queued_work_* with work_mutex.
Date: Fri, 10 Jul 2015 17:32:28 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0

On 10/07/2015 17:22, Paolo Bonzini wrote:

On 10/07/2015 17:19, address@hidden wrote:
+    qemu_mutex_lock(&cpu->work_mutex);
      while ((wi = cpu->queued_work_first)) {
          cpu->queued_work_first = wi->next;
          wi->func(wi->data);
Please unlock the mutex while calling the callback.

Paolo

@@ -905,6 +912,8 @@ static void flush_queued_work(CPUState *cpu)
          }
      }
      cpu->queued_work_last = NULL;
+    qemu_mutex_unlock(&cpu->work_mutex);
+
      qemu_cond_broadcast(&qemu_work_cond);

I think something like that can work because we don't have two
flush_queued_work at the same time on the same CPU?

static void flush_queued_work(CPUState *cpu)
{
    struct qemu_work_item *wi;

    if (cpu->queued_work_first == NULL) {
        return;
    }

    qemu_mutex_lock(&cpu->work_mutex);
    while ((wi = cpu->queued_work_first)) {
        cpu->queued_work_first = wi->next;
        qemu_mutex_unlock(&cpu->work_mutex);
        wi->func(wi->data);
        qemu_mutex_lock(&cpu->work_mutex);
        wi->done = true;
        if (wi->free) {
            g_free(wi);
        }
    }
    cpu->queued_work_last = NULL;
    qemu_mutex_unlock(&cpu->work_mutex);

    qemu_cond_broadcast(&qemu_work_cond);
}

Fred



reply via email to

[Prev in Thread] Current Thread [Next in Thread]