From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:46544) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGtNo-0006cC-O7 for qemu-devel@nongnu.org; Wed, 26 Sep 2012 11:18:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TGtNi-0004Is-Vu for qemu-devel@nongnu.org; Wed, 26 Sep 2012 11:18:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:16439) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGtNi-0004IZ-Nq for qemu-devel@nongnu.org; Wed, 26 Sep 2012 11:18:34 -0400 Message-ID: <50631CC5.5090504@redhat.com> Date: Wed, 26 Sep 2012 17:18:29 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1348577046-12643-1-git-send-email-pbonzini@redhat.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] coroutine: always use pooling List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: kwolf@redhat.com, stefanha@gmail.com, qemu-devel@nongnu.org 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