qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] LockGuards: replace manual lock()/unlock() calls to WITH_QEM


From: Stefan Hajnoczi
Subject: Re: [PATCH] LockGuards: replace manual lock()/unlock() calls to WITH_QEMU_LOCK_GUARD()
Date: Sun, 6 Nov 2022 08:48:55 -0500

On Fri, 4 Nov 2022 at 21:04, <nyoro.gachu@gmail.com> wrote:
>
> From: Samker <samkergachu@gmail.com>
...
> Signed-off-by: M N Gachu <nyoro.gachu@gmail.com>

The author and Signed-off-by name/email are different. Do you want to
use a single name/email?

> ---
>  softmmu/physmem.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/softmmu/physmem.c b/softmmu/physmem.c
> index d9578ccfd4..fb00596777 100644
> --- a/softmmu/physmem.c
> +++ b/softmmu/physmem.c
> @@ -24,6 +24,7 @@
>  #include "qemu/cutils.h"
>  #include "qemu/cacheflush.h"
>  #include "qemu/madvise.h"
> +#include "qemu/lockable.h"
>
>  #ifdef CONFIG_TCG
>  #include "hw/core/tcg-cpu-ops.h"
> @@ -3114,13 +3115,12 @@ void cpu_register_map_client(QEMUBH *bh)
>  {
>      MapClient *client = g_malloc(sizeof(*client));
>
> -    qemu_mutex_lock(&map_client_list_lock);
> +    WITH_QEMU_LOCK_GUARD(&map_client_list_lock);

There is a bug here: the lock won't be held after this line because
WITH_QEMU_LOCK_GUARD() is block scoped. It requires curly braces:

  WITH_QEMU_LOCK_GUARD(&lock) {
      ...protected code...
  }
  ...unprotected code...

Use QEMU_LOCK_GUARD(&lock); when don't want block scope. It holds the
lock for the remainder of the function.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]