thread: Change if-else_if to switch-case blocks of thread_execute_poller()

Change if - else if - else blocks of thread_execute_poller() and
thread_execute_timed_poller() to switch - cases blocks and specify
possible states explicitly in these switch - cases blocks.

The code will be simpler and clarified, and then the following patches
will be easier.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I2e283894f5d69e1bd67466ae070c5b8bb9014616
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7664
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Shuhei Matsumoto 2021-04-27 00:20:54 +09:00 committed by Tomasz Zawadzki
parent 54215a1e9b
commit 3f45ed2467

View File

@ -608,15 +608,21 @@ thread_execute_poller(struct spdk_thread *thread, struct spdk_poller *poller)
{
int rc;
if (poller->state == SPDK_POLLER_STATE_UNREGISTERED) {
switch (poller->state) {
case SPDK_POLLER_STATE_UNREGISTERED:
TAILQ_REMOVE(&thread->active_pollers, poller, tailq);
free(poller);
return 0;
} else if (poller->state == SPDK_POLLER_STATE_PAUSING) {
case SPDK_POLLER_STATE_PAUSING:
TAILQ_REMOVE(&thread->active_pollers, poller, tailq);
TAILQ_INSERT_TAIL(&thread->paused_pollers, poller, tailq);
poller->state = SPDK_POLLER_STATE_PAUSED;
return 0;
case SPDK_POLLER_STATE_WAITING:
break;
default:
assert(false);
break;
}
poller->state = SPDK_POLLER_STATE_RUNNING;
@ -633,11 +639,19 @@ thread_execute_poller(struct spdk_thread *thread, struct spdk_poller *poller)
}
#endif
if (poller->state == SPDK_POLLER_STATE_UNREGISTERED) {
switch (poller->state) {
case SPDK_POLLER_STATE_UNREGISTERED:
TAILQ_REMOVE(&thread->active_pollers, poller, tailq);
free(poller);
} else if (poller->state != SPDK_POLLER_STATE_PAUSED) {
break;
case SPDK_POLLER_STATE_PAUSED:
break;
case SPDK_POLLER_STATE_RUNNING:
poller->state = SPDK_POLLER_STATE_WAITING;
break;
default:
assert(false);
break;
}
return rc;
@ -649,15 +663,21 @@ thread_execute_timed_poller(struct spdk_thread *thread, struct spdk_poller *poll
{
int rc;
if (poller->state == SPDK_POLLER_STATE_UNREGISTERED) {
switch (poller->state) {
case SPDK_POLLER_STATE_UNREGISTERED:
TAILQ_REMOVE(&thread->timed_pollers, poller, tailq);
free(poller);
return 0;
} else if (poller->state == SPDK_POLLER_STATE_PAUSING) {
case SPDK_POLLER_STATE_PAUSING:
TAILQ_REMOVE(&thread->timed_pollers, poller, tailq);
TAILQ_INSERT_TAIL(&thread->paused_pollers, poller, tailq);
poller->state = SPDK_POLLER_STATE_PAUSED;
return 0;
case SPDK_POLLER_STATE_WAITING:
break;
default:
assert(false);
break;
}
poller->state = SPDK_POLLER_STATE_RUNNING;
@ -674,13 +694,21 @@ thread_execute_timed_poller(struct spdk_thread *thread, struct spdk_poller *poll
}
#endif
if (poller->state == SPDK_POLLER_STATE_UNREGISTERED) {
switch (poller->state) {
case SPDK_POLLER_STATE_UNREGISTERED:
TAILQ_REMOVE(&thread->timed_pollers, poller, tailq);
free(poller);
} else if (poller->state != SPDK_POLLER_STATE_PAUSED) {
break;
case SPDK_POLLER_STATE_PAUSED:
break;
case SPDK_POLLER_STATE_RUNNING:
poller->state = SPDK_POLLER_STATE_WAITING;
TAILQ_REMOVE(&thread->timed_pollers, poller, tailq);
poller_insert_timer(thread, poller, now);
break;
default:
assert(false);
break;
}
return rc;