Skip to content

Commit

Permalink
lockable: fix __COUNTER__ macro to be referenced properly
Browse files Browse the repository at this point in the history
- __COUNTER__ doesn't work with ## concat
- replaced ## with glue() macro so __COUNTER__ is evaluated

Fixes: 3284c3d

Signed-off-by: Daniel Brodsky <[email protected]>
Message-id: [email protected]
Signed-off-by: Stefan Hajnoczi <[email protected]>
  • Loading branch information
danbrodsky authored and stefanhaRH committed May 4, 2020
1 parent 05509c8 commit 56f2171
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions include/qemu/lockable.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuLockable, qemu_lockable_auto_unlock)
* }
*/
#define WITH_QEMU_LOCK_GUARD(x) \
WITH_QEMU_LOCK_GUARD_((x), qemu_lockable_auto##__COUNTER__)
WITH_QEMU_LOCK_GUARD_((x), glue(qemu_lockable_auto, __COUNTER__))

/**
* QEMU_LOCK_GUARD - Lock an object until the end of the scope
Expand All @@ -169,8 +169,9 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuLockable, qemu_lockable_auto_unlock)
* return; <-- mutex is automatically unlocked
* }
*/
#define QEMU_LOCK_GUARD(x) \
g_autoptr(QemuLockable) qemu_lockable_auto##__COUNTER__ = \
#define QEMU_LOCK_GUARD(x) \
g_autoptr(QemuLockable) \
glue(qemu_lockable_auto, __COUNTER__) G_GNUC_UNUSED = \
qemu_lockable_auto_lock(QEMU_MAKE_LOCKABLE((x)))

#endif
2 changes: 1 addition & 1 deletion include/qemu/rcu.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ static inline void rcu_read_auto_unlock(RCUReadAuto *r)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(RCUReadAuto, rcu_read_auto_unlock)

#define WITH_RCU_READ_LOCK_GUARD() \
WITH_RCU_READ_LOCK_GUARD_(_rcu_read_auto##__COUNTER__)
WITH_RCU_READ_LOCK_GUARD_(glue(_rcu_read_auto, __COUNTER__))

#define WITH_RCU_READ_LOCK_GUARD_(var) \
for (g_autoptr(RCUReadAuto) var = rcu_read_auto_lock(); \
Expand Down

0 comments on commit 56f2171

Please sign in to comment.