Fix LOCK_SCOPE to allow multiple locks per scope.
@@ -47,13 +47,26 @@ __attribute__((unused)) static void objc_release_lock(void *x)
mutex_t *lock = *(mutex_t**)x;
UNLOCK(lock);
}
+/**
+ * Concatenate strings during macro expansion.
+ */
+#define LOCK_HOLDERN_NAME_CAT(x, y) x ## y
+/**
+ * Concatenate string with unique variable during macro expansion.
+ */
+#define LOCK_HOLDER_NAME_COUNTER(x, y) LOCK_HOLDERN_NAME_CAT(x, y)
+/**
+ * Create a unique name for a lock holder variable
+ */
+#define LOCK_HOLDER_NAME(x) LOCK_HOLDER_NAME_COUNTER(x, __COUNTER__)
+
/**
* Acquires the lock and automatically releases it at the end of the current
* scope.
*/
#define LOCK_FOR_SCOPE(lock) \
__attribute__((cleanup(objc_release_lock)))\
- __attribute__((unused)) mutex_t *lock_pointer = lock;\
+ __attribute__((unused)) mutex_t *LOCK_HOLDER_NAME(lock_pointer) = lock;\
LOCK(lock)
/**
