]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: don't shadow `_once` in `frr_with_mutex`
authorDavid Lamparter <equinox@opensourcerouting.org>
Tue, 28 Jan 2025 01:58:09 +0000 (02:58 +0100)
committerMark Stapp <mjs@cisco.com>
Tue, 8 Apr 2025 18:41:26 +0000 (14:41 -0400)
The `_once` loop variable will result in a `-Wshadow` warning when that
is turned on.  Use `__COUNTER__` to give these variables distinct names,
like is already done with `_mtx_`.

(and because I touched it, clang-format wants it reformatted... ohwell.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
lib/frr_pthread.h

index bb751b707186ecfc4d60718e7478c12154be6906..368ada36ad7eebaf80ea979847643949061bc4c9 100644 (file)
@@ -233,11 +233,13 @@ int frr_pthread_non_controlled_startup(pthread_t thread, const char *name,
                unused, cleanup(_frr_mtx_unlock))) = _frr_mtx_lock(mutex),     \
        /* end */
 
-#define frr_with_mutex(...)                                                    \
-       for (pthread_mutex_t MACRO_REPEAT(_frr_with_mutex, ##__VA_ARGS__)      \
-            *_once = NULL; _once == NULL; _once = (void *)1)                  \
+#define _frr_with_mutex_once(_once, ...)                                                           \
+       for (pthread_mutex_t MACRO_REPEAT(_frr_with_mutex, ##__VA_ARGS__)*_once = NULL;           \
+            _once == NULL; _once = (void *)1)                                                     \
        /* end */
 
+#define frr_with_mutex(...) _frr_with_mutex_once(NAMECTR(_once_), __VA_ARGS__)
+
 /* variant 2:
  * (more suitable for long blocks, no extra indentation)
  *