diff options
author | Thomas Haller <thaller@redhat.com> | 2019-02-20 16:06:06 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-02-21 21:02:51 +0100 |
commit | 4dd5570eea2b108f73a7c0b4efda8dadc4ba533d (patch) | |
tree | 1beab0739763aec913b65f4ae102d9a1cb5d1994 | |
parent | 6f4cb7c11025802152248b75a02197a83e051e00 (diff) | |
download | NetworkManager-4dd5570eea2b108f73a7c0b4efda8dadc4ba533d.tar.gz |
platform: refactor FOR_EACH_DELAYED_ACTION() macro to have only one for(;;) statement
for-each macros can be nice to use. However, such macros are potentially
error prone, as they abstract C control statements and scoping blogs.
I find it ugly to expand the macro to:
for (...)
if (...)
Instead, move the additional "if" inside the loop's condition
expression.
-rw-r--r-- | src/platform/nm-linux-platform.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 3370620e3a..f5f75e3d97 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -321,8 +321,22 @@ typedef enum { } DelayedActionType; #define FOR_EACH_DELAYED_ACTION(iflags, flags_all) \ - for ((iflags) = (DelayedActionType) 0x1LL; (iflags) <= DELAYED_ACTION_TYPE_MAX; (iflags) <<= 1) \ - if (NM_FLAGS_ANY (flags_all, iflags)) + for ((iflags) = (DelayedActionType) 0x1LL; \ + ({ \ + gboolean _good = FALSE; \ + \ + nm_assert (nm_utils_is_power_of_two (iflags)); \ + \ + while ((iflags) <= DELAYED_ACTION_TYPE_MAX) { \ + if (NM_FLAGS_ANY ((flags_all), (iflags))) { \ + _good = TRUE; \ + break; \ + } \ + (iflags) <<= 1; \ + } \ + _good; \ + }); \ + (iflags) <<= 1) typedef enum { /* Negative values are errors from kernel. Add dummy member to @@ -4633,9 +4647,8 @@ delayed_action_handle_one (NMPlatform *platform) priv->delayed_action.flags &= ~DELAYED_ACTION_TYPE_REFRESH_ALL; if (_LOGt_ENABLED ()) { - FOR_EACH_DELAYED_ACTION (iflags, flags) { + FOR_EACH_DELAYED_ACTION (iflags, flags) _LOGt_delayed_action (iflags, NULL, "handle"); - } } delayed_action_handle_REFRESH_ALL (platform, flags); @@ -4719,9 +4732,8 @@ delayed_action_schedule (NMPlatform *platform, DelayedActionType action_type, gp priv->delayed_action.flags |= action_type; if (_LOGt_ENABLED ()) { - FOR_EACH_DELAYED_ACTION (iflags, action_type) { + FOR_EACH_DELAYED_ACTION (iflags, action_type) _LOGt_delayed_action (iflags, user_data, "schedule"); - } } } |