[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] coroutine: always use pooling
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH] coroutine: always use pooling |
Date: |
Wed, 26 Sep 2012 17:18:29 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120911 Thunderbird/15.0.1 |
Il 26/09/2012 16:34, Peter Maydell ha scritto:
>> It makes sense to use it for other implementations than ucontext, too.
>> > Coroutine *qemu_coroutine_create(CoroutineEntry *entry)
>> > {
>> > - Coroutine *co = qemu_coroutine_new();
>> > + Coroutine *co;
>> > +
>> > + co = QSLIST_FIRST(&pool);
>> > + if (co) {
>> > + QSLIST_REMOVE_HEAD(&pool, pool_next);
>> > + pool_size--;
>> > + } else {
>> > + co = qemu_coroutine_new();
>> > + }
>> > co->entry = entry;
>> > return co;
>> > }
> Since this is obviously going to blow up badly if it's called
> from multiple threads, is there some kind of assert we can add
> so that we fail obviously if somebody makes that coding error?
> [the difficulty is probably when your backend is the gthread
> one, at least I assume creating a coroutine inside a coroutine
> is allowed.]
Yes, it is; however, creating a coroutine outside the big QEMU lock is
not allowed. Since one coroutine only runs at a time the code is safe,
just like the other global variables that are used in
qemu-coroutine-lock.c for example.
Paolo