Re: [PATCH v10 1/7] system/physmem: Replace qemu_mutex_lock() calls with QEMU_LOCK_GUARD

2024-05-07 Thread Peter Xu
On Tue, May 07, 2024 at 07:34:25AM -0700, Mattias Nissler wrote:
> From: Philippe Mathieu-Daudé 
> 
> From: Philippe Mathieu-Daudé 
> 
> Simplify cpu_[un]register_map_client() and cpu_notify_map_clients()
> by replacing the pair of qemu_mutex_lock/qemu_mutex_unlock calls by
> the WITH_QEMU_LOCK_GUARD() macro.
> 
> Signed-off-by: Philippe Mathieu-Daudé 
> Signed-off-by: Mattias Nissler 
> Reviewed-by: Mattias Nissler 

Reviewed-by: Peter Xu 

-- 
Peter Xu




[PATCH v10 1/7] system/physmem: Replace qemu_mutex_lock() calls with QEMU_LOCK_GUARD

2024-05-07 Thread Mattias Nissler
From: Philippe Mathieu-Daudé 

From: Philippe Mathieu-Daudé 

Simplify cpu_[un]register_map_client() and cpu_notify_map_clients()
by replacing the pair of qemu_mutex_lock/qemu_mutex_unlock calls by
the WITH_QEMU_LOCK_GUARD() macro.

Signed-off-by: Philippe Mathieu-Daudé 
Signed-off-by: Mattias Nissler 
Reviewed-by: Mattias Nissler 
---
 system/physmem.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/system/physmem.c b/system/physmem.c
index d3a3d8a45c..5486014cf2 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -3086,7 +3086,7 @@ void cpu_register_map_client(QEMUBH *bh)
 {
 MapClient *client = g_malloc(sizeof(*client));
 
-qemu_mutex_lock(_client_list_lock);
+QEMU_LOCK_GUARD(_client_list_lock);
 client->bh = bh;
 QLIST_INSERT_HEAD(_client_list, client, link);
 /* Write map_client_list before reading in_use.  */
@@ -3094,7 +3094,6 @@ void cpu_register_map_client(QEMUBH *bh)
 if (!qatomic_read(_use)) {
 cpu_notify_map_clients_locked();
 }
-qemu_mutex_unlock(_client_list_lock);
 }
 
 void cpu_exec_init_all(void)
@@ -3117,21 +3116,19 @@ void cpu_unregister_map_client(QEMUBH *bh)
 {
 MapClient *client;
 
-qemu_mutex_lock(_client_list_lock);
+QEMU_LOCK_GUARD(_client_list_lock);
 QLIST_FOREACH(client, _client_list, link) {
 if (client->bh == bh) {
 cpu_unregister_map_client_do(client);
 break;
 }
 }
-qemu_mutex_unlock(_client_list_lock);
 }
 
 static void cpu_notify_map_clients(void)
 {
-qemu_mutex_lock(_client_list_lock);
+QEMU_LOCK_GUARD(_client_list_lock);
 cpu_notify_map_clients_locked();
-qemu_mutex_unlock(_client_list_lock);
 }
 
 static bool flatview_access_valid(FlatView *fv, hwaddr addr, hwaddr len,
-- 
2.43.2