feat: set as blocked

main
Sean McBride 4 years ago
parent b85d089537
commit c014f94797

@ -281,5 +281,6 @@ void sandbox_set_as_initialized(struct sandbox *sandbox, struct sandbox_request
uint64_t allocation_timestamp);
void sandbox_set_as_runnable(struct sandbox *sandbox);
void sandbox_set_as_running(struct sandbox *sandbox);
void sandbox_set_as_blocked(struct sandbox *sandbox);
void sandbox_set_as_preempted(struct sandbox *sandbox);
void sandbox_set_as_complete(struct sandbox *sandbox);

@ -653,6 +653,39 @@ sandbox_set_as_preempted(struct sandbox *sandbox)
sandbox->state = SANDBOX_PREEMPTED;
}
/**
* Transitions a sandbox to the SANDBOX_BLOCKED state.
* This occurs when a sandbox is executing and it makes a blocking API call of some kind.
* Automatically removes the sandbox from the runqueue
* @param sandbox the blocking sandbox
*/
void
sandbox_set_as_blocked(struct sandbox *sandbox)
{
assert(sandbox);
uint64_t now = __getcycles();
uint64_t duration_of_last_state = now - sandbox->last_state_change_timestamp;
sandbox_state_t last_state = sandbox->state;
sandbox->state = SANDBOX_SET_AS_BLOCKED;
debuglog("Thread %lu | Sandbox %lu | %s => Blocked\n", pthread_self(), sandbox->allocation_timestamp,
sandbox_state_stringify(last_state));
switch (last_state) {
case SANDBOX_RUNNING: {
sandbox->running_duration += duration_of_last_state;
local_runqueue_delete(sandbox);
break;
}
default: {
panic("Thread %lu | Sandbox %lu | Illegal transition from %s to Blocked\n", pthread_self(),
sandbox->allocation_timestamp, sandbox_state_stringify(last_state));
}
}
sandbox->last_state_change_timestamp = now;
sandbox->state = SANDBOX_BLOCKED;
}
/**
* Transitions a sandbox from the SANDBOX_RETURNED state to the SANDBOX_COMPLETE state.
* Adds the sandbox to the completion queue

@ -161,8 +161,8 @@ worker_thread_block_current_sandbox(void)
/* Remove the sandbox we were just executing from the runqueue and mark as blocked */
struct sandbox *current_sandbox = current_sandbox_get();
local_runqueue_delete(current_sandbox);
current_sandbox->state = SANDBOX_BLOCKED;
sandbox_set_as_blocked(current_sandbox);
current_sandbox_set(NULL);
/* Switch to the next sandbox */
struct sandbox *next_sandbox = local_runqueue_get_next();

Loading…
Cancel
Save