From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:58950) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGshe-0001Po-N2 for qemu-devel@nongnu.org; Wed, 26 Sep 2012 10:35:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TGshW-0001wL-VM for qemu-devel@nongnu.org; Wed, 26 Sep 2012 10:35:06 -0400 Received: from mail-ie0-f173.google.com ([209.85.223.173]:36464) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGshW-0001wB-Qk for qemu-devel@nongnu.org; Wed, 26 Sep 2012 10:34:58 -0400 Received: by iea17 with SMTP id 17so1441880iea.4 for ; Wed, 26 Sep 2012 07:34:57 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <1348577046-12643-1-git-send-email-pbonzini@redhat.com> References: <1348577046-12643-1-git-send-email-pbonzini@redhat.com> Date: Wed, 26 Sep 2012 15:34:57 +0100 Message-ID: From: Peter Maydell Content-Type: text/plain; charset=UTF-8 Subject: Re: [Qemu-devel] [PATCH] coroutine: always use pooling List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: kwolf@redhat.com, stefanha@gmail.com, qemu-devel@nongnu.org On 25 September 2012 13:44, Paolo Bonzini wrote: > 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.] -- PMM