From 89f1ebef957813f1262603ea5ec82539edb1ecad Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Thu, 27 Dec 2018 13:21:57 +0100 Subject: barrier: replace boolean-switch statement with if/else MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Niels de Vos --- xlators/features/barrier/src/barrier.c | 66 ++++++++++++---------------------- 1 file 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; -- cgit