refactor: Further sigalrm changes

master
Sean McBride 4 years ago
parent 9b7cefccd7
commit 8d563a5f53

@ -76,16 +76,17 @@ propagate_sigalrm(siginfo_t *signal_info)
} }
static inline bool static inline bool
running_cooperative_scheduler(void) worker_thread_is_running_cooperative_scheduler(void)
{ {
return current_sandbox_get() == NULL; return current_sandbox_get() == NULL;
} }
static inline bool static inline bool
preemptable(sandbox_state_t state) current_sandbox_is_preemptable()
{ {
return state == SANDBOX_RUNNING_USER; struct sandbox *sandbox = current_sandbox_get();
return sandbox != NULL && sandbox->state == SANDBOX_RUNNING_USER;
} }
/** /**
@ -114,28 +115,25 @@ software_interrupt_handle_signals(int signal_type, siginfo_t *signal_info, void
switch (signal_type) { switch (signal_type) {
case SIGALRM: { case SIGALRM: {
if (worker_thread_is_running_cooperative_scheduler()) {
/* There is no benefit to deferring SIGALRMs that occur when we are already in the cooperative /* There is no benefit to deferring SIGALRMs that occur when we are already in the cooperative
* scheduler, so just propagate and return */ * scheduler, so just propagate and return */
if (running_cooperative_scheduler()) {
propagate_sigalrm(signal_info); propagate_sigalrm(signal_info);
break; } else if (current_sandbox_is_preemptable()) {
} /* Preemptable, so run scheduler. The scheduler handles outgoing state changes */
sandbox_interrupt(current_sandbox);
/* We transition the sandbox to an interrupted state to exclude time propagating signals and running the propagate_sigalrm(signal_info);
* scheduler from per-sandbox accounting */ scheduler_preemptive_sched(interrupted_context);
} else {
/* We transition the sandbox to an interrupted state to exclude time propagating signals and
* running the scheduler from per-sandbox accounting */
sandbox_state_t interrupted_state = current_sandbox->state; sandbox_state_t interrupted_state = current_sandbox->state;
sandbox_interrupt(current_sandbox); sandbox_interrupt(current_sandbox);
propagate_sigalrm(signal_info); propagate_sigalrm(signal_info);
/* If our interrupted sandbox is not preempatable, defer the sigalarm and return */
if (!preemptable(interrupted_state)) {
atomic_fetch_add(&deferred_sigalrm, 1); atomic_fetch_add(&deferred_sigalrm, 1);
sandbox_interrupt_return(current_sandbox, interrupted_state); sandbox_interrupt_return(current_sandbox, interrupted_state);
break;
} }
/* Preemptable, so run scheduler. The scheduler handles outgoing state changes */
scheduler_preemptive_sched(interrupted_context);
break; break;
} }
case SIGUSR1: { case SIGUSR1: {

Loading…
Cancel
Save