refactor: DRY up state transitions

main
Sean McBride 4 years ago
parent c37b2ba9a9
commit a70187eed0

@ -555,12 +555,10 @@ sandbox_set_as_runnable(struct sandbox *sandbox)
switch (last_state) { switch (last_state) {
case SANDBOX_INITIALIZED: { case SANDBOX_INITIALIZED: {
sandbox->initializing_duration += duration_of_last_state; sandbox->initializing_duration += duration_of_last_state;
local_runqueue_add(sandbox);
break; break;
} }
case SANDBOX_BLOCKED: { case SANDBOX_BLOCKED: {
sandbox->blocked_duration += duration_of_last_state; sandbox->blocked_duration += duration_of_last_state;
local_runqueue_add(sandbox);
break; break;
} }
default: { default: {
@ -569,6 +567,7 @@ sandbox_set_as_runnable(struct sandbox *sandbox)
} }
} }
local_runqueue_add(sandbox);
sandbox->last_state_change_timestamp = now; sandbox->last_state_change_timestamp = now;
sandbox->state = SANDBOX_RUNNABLE; sandbox->state = SANDBOX_RUNNABLE;
} }
@ -599,12 +598,10 @@ sandbox_set_as_running(struct sandbox *sandbox)
switch (last_state) { switch (last_state) {
case SANDBOX_RUNNABLE: { case SANDBOX_RUNNABLE: {
sandbox->runnable_duration += duration_of_last_state; sandbox->runnable_duration += duration_of_last_state;
current_sandbox_set(sandbox);
break; break;
} }
case SANDBOX_PREEMPTED: { case SANDBOX_PREEMPTED: {
sandbox->preempted_duration += duration_of_last_state; sandbox->preempted_duration += duration_of_last_state;
current_sandbox_set(sandbox);
break; break;
} }
default: { default: {
@ -613,6 +610,7 @@ sandbox_set_as_running(struct sandbox *sandbox)
} }
} }
current_sandbox_set(sandbox);
sandbox->last_state_change_timestamp = now; sandbox->last_state_change_timestamp = now;
sandbox->state = SANDBOX_RUNNING; sandbox->state = SANDBOX_RUNNING;
} }
@ -746,12 +744,10 @@ sandbox_set_as_error(struct sandbox *sandbox)
case SANDBOX_SET_AS_INITIALIZED: case SANDBOX_SET_AS_INITIALIZED:
/* Technically, this is a degenerate sandbox that we generate by hand */ /* Technically, this is a degenerate sandbox that we generate by hand */
sandbox->initializing_duration += duration_of_last_state; sandbox->initializing_duration += duration_of_last_state;
sandbox_free_linear_memory(sandbox);
break; break;
case SANDBOX_RUNNING: { case SANDBOX_RUNNING: {
sandbox->running_duration += duration_of_last_state; sandbox->running_duration += duration_of_last_state;
local_runqueue_delete(sandbox); local_runqueue_delete(sandbox);
sandbox_free_linear_memory(sandbox);
break; break;
} }
default: { default: {
@ -760,6 +756,7 @@ sandbox_set_as_error(struct sandbox *sandbox)
} }
} }
sandbox_free_linear_memory(sandbox);
sandbox->last_state_change_timestamp = now; sandbox->last_state_change_timestamp = now;
sandbox->state = SANDBOX_ERROR; sandbox->state = SANDBOX_ERROR;

Loading…
Cancel
Save