From: Stefan Hajnoczi <stefanha@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
"Emilio G . Cota" <cota@braap.org>, Fam Zheng <famz@redhat.com>,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 5/5] thread-pool: convert to use lock guards
Date: Mon, 11 Dec 2017 10:23:04 +0000 [thread overview]
Message-ID: <20171211102304.GC13593@stefanha-x1.localdomain> (raw)
In-Reply-To: <a53f2cc7-9da4-bd8e-4d0b-bb3c32c9d4a9@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2143 bytes --]
On Fri, Dec 08, 2017 at 02:02:32PM -0600, Eric Blake wrote:
> On 12/08/2017 12:12 PM, Paolo Bonzini wrote:
> > On 08/12/2017 16:13, Stefan Hajnoczi wrote:
> >>> - qemu_mutex_lock(&pool->lock);
> >>> + QEMU_LOCK_GUARD(QemuMutex, pool_guard, &pool->lock);
> >>> if (pool->idle_threads == 0 && pool->cur_threads < pool->max_threads) {
> >>> spawn_thread(pool);
> >>> }
> >>> QTAILQ_INSERT_TAIL(&pool->request_list, req, reqs);
> >>> - qemu_mutex_unlock(&pool->lock);
> >>> + qemu_lock_guard_unlock(&pool_guard);
> >> Why not QEMU_WITH_LOCK()? Then you can get rid of the explicit unlock.
> >
> > I agree that QEMU_WITH_LOCK_GUARD is better in this case. (IIRC I wrote
> > this patch before coming up with the is_taken trick!).
> >
> > My main question for the series is what you think the balance should be
> > between a more widely applicable API and a simpler one.
>
> If you require the user to provide the scope, this could be:
>
> @@ -258,12 +254,12 @@ BlockAIOCB *thread_pool_submit_aio(ThreadPool *pool,
>
> trace_thread_pool_submit(pool, req, arg);
>
> - qemu_mutex_lock(&pool->lock);
> - if (pool->idle_threads == 0 && pool->cur_threads < pool->max_threads) {
> - spawn_thread(pool);
> - QTAILQ_INSERT_TAIL(&pool->request_list, req, reqs);
> + {
> + QEMU_LOCK_GUARD(QemuMutex, pool_guard, &pool->lock);
> + if (pool->idle_threads == 0 && pool->cur_threads <
> pool->max_threads) {
> + spawn_thread(pool);
> + }
> + QTAILQ_INSERT_TAIL(&pool->request_list, req, reqs);
> }
> - qemu_mutex_unlock(&pool->lock);
> qemu_sem_post(&pool->sem);
> return &req->common;
> }
>
> In other words, I don't see what 'QEMU_WITH_LOCK_GUARD() {}' buys us
> over '{ QEMU_LOCK_GUARD() }'.
The QEMU_WITH_LOCK_GUARD() {} syntax is nice because it's similar to
if/while/for statements.
However, { QEMU_LOCK_GUARD() } doesn't hide a for statement in a macro
so the break statement works inside the scope. Less chance of bugs.
I'd be okay without QEMU_WITH_LOCK_GUARD().
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
next prev parent reply other threads:[~2017-12-11 10:23 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-08 10:55 [Qemu-devel] [RFC PATCH 0/5] Scoped locks using attribute((cleanup)) Paolo Bonzini
2017-12-08 10:55 ` [Qemu-devel] [PATCH 1/5] compiler: add a helper for C99 inline functions Paolo Bonzini
2017-12-08 10:55 ` [Qemu-devel] [PATCH 2/5] lock-guard: add scoped lock implementation Paolo Bonzini
2017-12-08 15:30 ` Stefan Hajnoczi
2017-12-08 17:56 ` Paolo Bonzini
2017-12-08 20:12 ` Eric Blake
2017-12-11 10:16 ` Stefan Hajnoczi
2017-12-11 13:51 ` Eric Blake
2017-12-12 9:16 ` Stefan Hajnoczi
2017-12-08 10:55 ` [Qemu-devel] [PATCH 3/5] qemu-timer: convert to use lock guards Paolo Bonzini
2017-12-08 14:26 ` Stefan Hajnoczi
2017-12-08 10:55 ` [Qemu-devel] [PATCH 4/5] qht: " Paolo Bonzini
2017-12-08 14:27 ` Stefan Hajnoczi
2017-12-08 10:55 ` [Qemu-devel] [PATCH 5/5] thread-pool: " Paolo Bonzini
2017-12-08 15:13 ` Stefan Hajnoczi
2017-12-08 18:12 ` Paolo Bonzini
2017-12-08 20:02 ` Eric Blake
2017-12-11 10:23 ` Stefan Hajnoczi [this message]
2017-12-11 22:03 ` Paolo Bonzini
2017-12-08 19:50 ` Eric Blake
2017-12-11 6:35 ` Peter Xu
2017-12-08 19:40 ` [Qemu-devel] [RFC PATCH 0/5] Scoped locks using attribute((cleanup)) Eric Blake
2017-12-11 9:38 ` Peter Maydell
2017-12-11 14:11 ` Eric Blake
2017-12-11 21:32 ` Paolo Bonzini
2017-12-12 20:41 ` Eric Blake
2017-12-15 15:50 ` Richard Henderson
2017-12-11 6:40 ` no-reply
2017-12-11 6:40 ` no-reply
2017-12-11 6:46 ` no-reply
2017-12-11 22:06 ` Emilio G. Cota
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171211102304.GC13593@stefanha-x1.localdomain \
--to=stefanha@redhat.com \
--cc=cota@braap.org \
--cc=eblake@redhat.com \
--cc=famz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).