[PATCH 3/9] char: Replaced a qemu_mutex_lock with QEMU_LOCK_GUARD

Mahmoud Mandour posted 9 patches 4 years, 11 months ago
Maintainers: Markus Armbruster <armbru@redhat.com>, Eric Blake <eblake@redhat.com>, Kevin Wolf <kwolf@redhat.com>, Juan Quintela <quintela@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Christian Schoenebeck <qemu_oss@crudebyte.com>, Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>, Max Reitz <mreitz@redhat.com>, Stefan Berger <stefanb@linux.vnet.ibm.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, Greg Kurz <groug@kaod.org>, Eric Auger <eric.auger@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Dr. David Alan Gilbert" <dgilbert@redhat.com>
[PATCH 3/9] char: Replaced a qemu_mutex_lock with QEMU_LOCK_GUARD
Posted by Mahmoud Mandour 4 years, 11 months ago
Removed a pair of qemu_mutex_lock and its respective qemu_mutex_unlock
and used a QEMU_LOCK_GUARD instead. This improves readability by
removing the call to qemu_mutex_unlock.

Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com>
---
 chardev/char.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/chardev/char.c b/chardev/char.c
index 97cafd6849..2b0bc1325c 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -115,7 +115,7 @@ static int qemu_chr_write_buffer(Chardev *s,
     int res = 0;
     *offset = 0;
 
-    qemu_mutex_lock(&s->chr_write_lock);
+    QEMU_LOCK_GUARD(&s->chr_write_lock);
     while (*offset < len) {
     retry:
         res = cc->chr_write(s, buf + *offset, len - *offset);
@@ -153,7 +153,6 @@ static int qemu_chr_write_buffer(Chardev *s,
          */
         qemu_chr_write_log(s, buf, len);
     }
-    qemu_mutex_unlock(&s->chr_write_lock);
 
     return res;
 }
-- 
2.25.1


Re: [PATCH 3/9] char: Replaced a qemu_mutex_lock with QEMU_LOCK_GUARD
Posted by Marc-André Lureau 4 years, 11 months ago
On Thu, Mar 11, 2021 at 1:28 PM Mahmoud Mandour <ma.mandourr@gmail.com>
wrote:

> Removed a pair of qemu_mutex_lock and its respective qemu_mutex_unlock
> and used a QEMU_LOCK_GUARD instead. This improves readability by
> removing the call to qemu_mutex_unlock.
>
> Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com>
>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

---
>  chardev/char.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/chardev/char.c b/chardev/char.c
> index 97cafd6849..2b0bc1325c 100644
> --- a/chardev/char.c
> +++ b/chardev/char.c
> @@ -115,7 +115,7 @@ static int qemu_chr_write_buffer(Chardev *s,
>      int res = 0;
>      *offset = 0;
>
> -    qemu_mutex_lock(&s->chr_write_lock);
> +    QEMU_LOCK_GUARD(&s->chr_write_lock);
>      while (*offset < len) {
>      retry:
>          res = cc->chr_write(s, buf + *offset, len - *offset);
> @@ -153,7 +153,6 @@ static int qemu_chr_write_buffer(Chardev *s,
>           */
>          qemu_chr_write_log(s, buf, len);
>      }
> -    qemu_mutex_unlock(&s->chr_write_lock);
>
>      return res;
>  }
> --
> 2.25.1
>
>
>

-- 
Marc-André Lureau