All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Stefan Hajnoczi <stefanha@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 14:35:11 +0800	[thread overview]
Message-ID: <20171211063511.GA18868@xz-mi> (raw)
In-Reply-To: <20171208151306.GC8998@stefanha-x1.localdomain>

On Fri, Dec 08, 2017 at 03:13:06PM +0000, Stefan Hajnoczi wrote:

[...]

> > @@ -330,7 +326,7 @@ void thread_pool_free(ThreadPool *pool)
> >  
> >      assert(QLIST_EMPTY(&pool->head));
> >  
> > -    qemu_mutex_lock(&pool->lock);
> > +    QEMU_LOCK_GUARD(QemuMutex, pool_guard, &pool->lock);
> >  
> >      /* Stop new threads from spawning */
> >      qemu_bh_delete(pool->new_thread_bh);
> > @@ -344,7 +340,7 @@ void thread_pool_free(ThreadPool *pool)
> >          qemu_cond_wait(&pool->worker_stopped, &pool->lock);
> >      }
> >  
> > -    qemu_mutex_unlock(&pool->lock);
> > +    qemu_lock_guard_unlock(&pool_guard);
> 
> Here too.  I don't see the advantage of replacing a single lock/unlock
> with QEMU_LOCK_GUARD/unlock, if it cannot be made shorter/safer then
> it's fine to use QemuMutex directly.

Agree.

For such use cases (and maybe mostly the cases that can use
QEMU_ADOPT_LOCK, QEMU_RETURN_LOCK, QEMU_TAKEN_LOCK) for me I would
still prefer the old ways, which is clearer to me (and faster?).  But
I do think the guard can really help for the specific case when
e.g. we need to take the lock at the entry of the function but need to
make sure it's released before leaving, especially when the function
contains multiple return points.

Maybe we can do this incrementally?  Say, we can at least start to use
it in new codes, and replace some obvious scenarios where proper.
After all it sounds good to have such an API that QEMU code can use
directly.

Thanks,

-- 
Peter Xu

  parent reply	other threads:[~2017-12-11  6:35 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
2017-12-11 22:03           ` Paolo Bonzini
2017-12-08 19:50     ` Eric Blake
2017-12-11  6:35     ` Peter Xu [this message]
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=20171211063511.GA18868@xz-mi \
    --to=peterx@redhat.com \
    --cc=cota@braap.org \
    --cc=famz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.