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: dd33b3a14e ('shared: add nm_auto_unlock_g_mutex and NM_G_MUTEX_LOCKED() helper macros')
(cherry picked from commit 098ac7dbc0)
This commit is contained in:
Thomas Haller 2021-01-13 16:10:37 +01:00
parent 65e88671d6
commit 3c27a3ed5f
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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)