thread: Change if-else_if to switch-case blocks of spdk_poller_pause/resume()
It will be sufficiently reasonable to check if the caller thread is valid even if spdk_poller_pause() or spdk_poller_resume() does nothing. Besides, let's write all possibles states explicitly in switch - cases. This refactoring clarifies the logic and makes the following patches easier. Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: I1163eff388fe741d6b6924f474a82b1aa7d18acb Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7665 Community-CI: Mellanox Build Bot 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> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
3f45ed2467
commit
42ad32da60
@ -1391,11 +1391,6 @@ spdk_poller_pause(struct spdk_poller *poller)
|
|||||||
{
|
{
|
||||||
struct spdk_thread *thread;
|
struct spdk_thread *thread;
|
||||||
|
|
||||||
if (poller->state == SPDK_POLLER_STATE_PAUSED ||
|
|
||||||
poller->state == SPDK_POLLER_STATE_PAUSING) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
thread = spdk_get_thread();
|
thread = spdk_get_thread();
|
||||||
if (!thread) {
|
if (!thread) {
|
||||||
assert(false);
|
assert(false);
|
||||||
@ -1414,9 +1409,11 @@ spdk_poller_pause(struct spdk_poller *poller)
|
|||||||
* allows a poller to be paused from another one's context without
|
* allows a poller to be paused from another one's context without
|
||||||
* breaking the TAILQ_FOREACH_REVERSE_SAFE iteration.
|
* breaking the TAILQ_FOREACH_REVERSE_SAFE iteration.
|
||||||
*/
|
*/
|
||||||
if (poller->state != SPDK_POLLER_STATE_RUNNING) {
|
switch (poller->state) {
|
||||||
poller->state = SPDK_POLLER_STATE_PAUSING;
|
case SPDK_POLLER_STATE_PAUSED:
|
||||||
} else {
|
case SPDK_POLLER_STATE_PAUSING:
|
||||||
|
break;
|
||||||
|
case SPDK_POLLER_STATE_RUNNING:
|
||||||
if (poller->period_ticks > 0) {
|
if (poller->period_ticks > 0) {
|
||||||
TAILQ_REMOVE(&thread->timed_pollers, poller, tailq);
|
TAILQ_REMOVE(&thread->timed_pollers, poller, tailq);
|
||||||
} else {
|
} else {
|
||||||
@ -1425,6 +1422,13 @@ spdk_poller_pause(struct spdk_poller *poller)
|
|||||||
|
|
||||||
TAILQ_INSERT_TAIL(&thread->paused_pollers, poller, tailq);
|
TAILQ_INSERT_TAIL(&thread->paused_pollers, poller, tailq);
|
||||||
poller->state = SPDK_POLLER_STATE_PAUSED;
|
poller->state = SPDK_POLLER_STATE_PAUSED;
|
||||||
|
break;
|
||||||
|
case SPDK_POLLER_STATE_WAITING:
|
||||||
|
poller->state = SPDK_POLLER_STATE_PAUSING;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1433,11 +1437,6 @@ spdk_poller_resume(struct spdk_poller *poller)
|
|||||||
{
|
{
|
||||||
struct spdk_thread *thread;
|
struct spdk_thread *thread;
|
||||||
|
|
||||||
if (poller->state != SPDK_POLLER_STATE_PAUSED &&
|
|
||||||
poller->state != SPDK_POLLER_STATE_PAUSING) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
thread = spdk_get_thread();
|
thread = spdk_get_thread();
|
||||||
if (!thread) {
|
if (!thread) {
|
||||||
assert(false);
|
assert(false);
|
||||||
@ -1456,12 +1455,21 @@ spdk_poller_resume(struct spdk_poller *poller)
|
|||||||
* we just need to flip its state back to waiting, as it's already on
|
* we just need to flip its state back to waiting, as it's already on
|
||||||
* the appropriate list.
|
* the appropriate list.
|
||||||
*/
|
*/
|
||||||
if (poller->state == SPDK_POLLER_STATE_PAUSED) {
|
switch (poller->state) {
|
||||||
|
case SPDK_POLLER_STATE_PAUSED:
|
||||||
TAILQ_REMOVE(&thread->paused_pollers, poller, tailq);
|
TAILQ_REMOVE(&thread->paused_pollers, poller, tailq);
|
||||||
thread_insert_poller(thread, poller);
|
thread_insert_poller(thread, poller);
|
||||||
}
|
/* fallthrough */
|
||||||
|
case SPDK_POLLER_STATE_PAUSING:
|
||||||
poller->state = SPDK_POLLER_STATE_WAITING;
|
poller->state = SPDK_POLLER_STATE_WAITING;
|
||||||
|
break;
|
||||||
|
case SPDK_POLLER_STATE_RUNNING:
|
||||||
|
case SPDK_POLLER_STATE_WAITING:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
Loading…
Reference in New Issue
Block a user