On Mon, 01/16 13:19, Paolo Bonzini wrote:
> >> +static void co_schedule_bh_cb(void *opaque)
> >> +{
> >> +    AioContext *ctx = opaque;
> >> +    QSLIST_HEAD(, Coroutine) straight, reversed;
> >> +
> >> +    QSLIST_MOVE_ATOMIC(&reversed, &ctx->scheduled_coroutines);
> >> +    QSLIST_INIT(&straight);
> > 
> > Worth special casing 1 element case?
> 
> Sounds like premature optimization; the QSLIST_MOVE_ATOMIC is going to
> be pretty expensive anyway.  Do you mean something like:
> 
>       if (QSLIST_EMPTY(&reversed)) {
>           return;
>       }
>       Coroutine *co = QSLIST_FIRST(&reversed);
>       if (!QSLIST_NEXT(co, co_scheduled_next)) {
>           straight = reversed;
>       } else {
>           do {
>                 ...
>           } while (!QSLIST_EMPTY(&reversed);
>       }
> 
>       do {
>           ...
>       } while (!QSLIST_EMPTY(&straight);
> 
> ?  Looks a but busy.  However, removing the QSLIST_EMPTY case and then
> using do/while may be a nice middle.

I think QSLIST_EMPTY is very unusual. I don't know if these are premature or
not, just asked because the !QSLIST_NEXT() case will be the most common one.

Fam

Reply via email to