diff options
author | Thomas Haller <thaller@redhat.com> | 2021-01-13 16:10:37 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-03-08 22:29:00 +0100 |
commit | 098ac7dbc0a7f8847d357f9e25aec929237f745f (patch) | |
tree | 1f48a4c18d339329ddab5be9bea660a458d164be | |
parent | a5829ea6d1f9238b20c47d7f57ca3683b1e64053 (diff) | |
download | NetworkManager-098ac7dbc0a7f8847d357f9e25aec929237f745f.tar.gz |
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')
-rw-r--r-- | src/libnm-glib-aux/nm-macros-internal.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/libnm-glib-aux/nm-macros-internal.h b/src/libnm-glib-aux/nm-macros-internal.h index 113a67a0d2..3f45cfaea2 100644 --- a/src/libnm-glib-aux/nm-macros-internal.h +++ b/src/libnm-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) |