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