diff options
author | Niels de Vos <ndevos@redhat.com> | 2018-12-27 13:21:57 +0100 |
---|---|---|
committer | Atin Mukherjee <amukherj@redhat.com> | 2018-12-28 03:43:59 +0000 |
commit | 89f1ebef957813f1262603ea5ec82539edb1ecad (patch) | |
tree | 1577499edcd611d7e9de259ea9a46abac17d6acf /xlators | |
parent | a6dc153e47f9025b09e8aae14ca6ba96fa20a23e (diff) |
barrier: replace boolean-switch statement with if/else
Squash some ugly warnings, and make the code a little bit simpler by
removing some unneeded goto jumps.
On Ubuntu 16.04 the following warnings were reported by Amudhan:
CC barrier.lo
barrier.c: In function ‘notify’:
barrier.c:499:33: warning: switch condition has boolean value [-Wswitch-bool]
switch (past) {
^
barrier.c: In function ‘reconfigure’:
barrier.c:565:25: warning: switch condition has boolean value [-Wswitch-bool]
switch (past) {
^
Change-Id: Ifb6b75058dff8c789b729c76530a1358d391f4d1
Updates: bz#1193929
Reported-by: Amudhan P <amudhan83@gmail.com>
Signed-off-by: Niels de Vos <ndevos@redhat.com>
Diffstat (limited to 'xlators')
-rw-r--r-- | xlators/features/barrier/src/barrier.c | 66 |
1 files changed, 23 insertions, 43 deletions
diff --git a/xlators/features/barrier/src/barrier.c b/xlators/features/barrier/src/barrier.c index 73e746f7d65..58054699132 100644 --- a/xlators/features/barrier/src/barrier.c +++ b/xlators/features/barrier/src/barrier.c @@ -463,7 +463,6 @@ notify(xlator_t *this, int event, void *data, ...) { barrier_priv_t *priv = NULL; dict_t *dict = NULL; - gf_boolean_t past = _gf_false; int ret = -1; int barrier_enabled = _gf_false; struct list_head queue = { @@ -488,33 +487,21 @@ notify(xlator_t *this, int event, void *data, ...) LOCK(&priv->lock); { - past = priv->barrier_enabled; - - switch (past) { - case _gf_false: - if (barrier_enabled) { - ret = __barrier_enable(this, priv); - if (ret) - goto unlock; - } else { - gf_log(this->name, GF_LOG_ERROR, - "Already disabled."); - goto unlock; - } - break; - - case _gf_true: - if (!barrier_enabled) { - __barrier_disable(this, &queue); - } else { - gf_log(this->name, GF_LOG_ERROR, "Already enabled"); - goto unlock; - } - break; + if (!priv->barrier_enabled) { + if (barrier_enabled) { + ret = __barrier_enable(this, priv); + } else { + gf_log(this->name, GF_LOG_ERROR, "Already disabled."); + } + } else { + if (!barrier_enabled) { + __barrier_disable(this, &queue); + ret = 0; + } else { + gf_log(this->name, GF_LOG_ERROR, "Already enabled"); + } } - ret = 0; } - unlock: UNLOCK(&priv->lock); if (!list_empty(&queue)) @@ -536,7 +523,6 @@ int reconfigure(xlator_t *this, dict_t *options) { barrier_priv_t *priv = NULL; - gf_boolean_t past = _gf_false; int ret = -1; gf_boolean_t barrier_enabled = _gf_false; uint32_t timeout = { @@ -556,23 +542,17 @@ reconfigure(xlator_t *this, dict_t *options) LOCK(&priv->lock); { - past = priv->barrier_enabled; - - switch (past) { - case _gf_false: - if (barrier_enabled) { - ret = __barrier_enable(this, priv); - if (ret) { - goto unlock; - } + if (!priv->barrier_enabled) { + if (barrier_enabled) { + ret = __barrier_enable(this, priv); + if (ret) { + goto unlock; } - break; - - case _gf_true: - if (!barrier_enabled) { - __barrier_disable(this, &queue); - } - break; + } + } else { + if (!barrier_enabled) { + __barrier_disable(this, &queue); + } } priv->timeout.tv_sec = timeout; ret = 0; |