From 3c27a3ed5f3bfcfb91e8e32fb6d4fb26ee0ac7a2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 13 Jan 2021 16:10:37 +0100 Subject: [PATCH] shared: fix behavior of NM_G_MUTEX_LOCKED() The idea of NM_G_MUTEX_LOCKED() macro is not only to register a mutex for unlocking (via nm_auto_unlock_g_mutex) but also to lock it at the same time. That is a useful helper macro. If you have to lock the mutex yourself, it makes usage less convenient. At which point you don't need the macro anymore and you should instead take full control and lock/unlock yourself. Fix the macro and change behavior. The macro was not used so far, so it's not a problem. Fixes: dd33b3a14e9c ('shared: add nm_auto_unlock_g_mutex and NM_G_MUTEX_LOCKED() helper macros') (cherry picked from commit 098ac7dbc0a7f8847d357f9e25aec929237f745f) --- shared/nm-glib-aux/nm-macros-internal.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/shared/nm-glib-aux/nm-macros-internal.h b/shared/nm-glib-aux/nm-macros-internal.h index 113a67a0d2..3f45cfaea2 100644 --- a/shared/nm-glib-aux/nm-macros-internal.h +++ b/shared/nm-glib-aux/nm-macros-internal.h @@ -1805,8 +1805,13 @@ NM_AUTO_DEFINE_FCN_VOID0(GMutex *, _nm_auto_unlock_g_mutex, g_mutex_unlock); #define nm_auto_unlock_g_mutex nm_auto(_nm_auto_unlock_g_mutex) -#define _NM_G_MUTEX_LOCKED(lock, uniq) \ - nm_auto_unlock_g_mutex GMutex *NM_UNIQ_T(nm_lock, uniq) = (lock) +#define _NM_G_MUTEX_LOCKED(lock, uniq) \ + _nm_unused nm_auto_unlock_g_mutex GMutex *NM_UNIQ_T(nm_lock, uniq) = ({ \ + GMutex *const _lock = (lock); \ + \ + g_mutex_lock(_lock); \ + _lock; \ + }) #define NM_G_MUTEX_LOCKED(lock) _NM_G_MUTEX_LOCKED(lock, NM_UNIQ)