On 10/07/2015 17:32, Frederic Konrad wrote:
>>>
> 
> I think something like that can work because we don't have two
> flush_queued_work at the same time on the same CPU?

Yes, this works; there is only one consumer.

Holding locks within a callback can be very painful, especially if there
is a chance that the callback will take a very coarse lock such as big
QEMU lock.  It can cause AB-BA deadlocks.

Paolo

> 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);
> }

Reply via email to