chore: simplify event loop

main
Sean McBride 5 years ago
parent d42370c357
commit 82f79b1ed4

@ -325,27 +325,18 @@ worker_thread_get_next_sandbox(int in_interrupt)
} }
/** /**
* Tries to free a completed request, executes libuv callbacks, and then gets * Tries to free a completed request, executes libuv callbacks
* and returns the standbox at the head of the thread-local runqueue
* @return sandbox or NULL * @return sandbox or NULL
**/ **/
static inline struct sandbox * static inline void
worker_thread_execute_runtime_maintenance_and_get_next_sandbox(void) worker_thread_execute_runtime_maintenance(void)
{ {
assert(current_sandbox_get() == NULL); assert(current_sandbox_get() == NULL);
// Try to free one sandbox from the completion queue
sandbox_completion_queue_free(1); sandbox_completion_queue_free(1);
// Execute libuv callbacks
if (!worker_thread_is_in_callback) worker_thread_execute_libuv_event_loop(); if (!worker_thread_is_in_callback) worker_thread_execute_libuv_event_loop();
// Get and return the sandbox at the head of the thread local runqueue
software_interrupt_disable();
struct sandbox *sandbox = worker_thread_get_next_sandbox(0);
software_interrupt_enable();
assert(sandbox == NULL || sandbox->state == RUNNABLE);
return sandbox;
} }
/** /**
* The entry function for sandbox worker threads * The entry function for sandbox worker threads
* Initializes thread-local state, unmasks signals, sets up libuv loop and * Initializes thread-local state, unmasks signals, sets up libuv loop and
@ -368,10 +359,18 @@ worker_thread_main(void *return_code)
worker_thread_is_in_callback = 0; worker_thread_is_in_callback = 0;
while (true) { while (true) {
struct sandbox *sandbox = worker_thread_execute_runtime_maintenance_and_get_next_sandbox(); worker_thread_execute_runtime_maintenance();
software_interrupt_disable();
struct sandbox *sandbox = worker_thread_get_next_sandbox(0);
software_interrupt_enable();
assert(sandbox == NULL || sandbox->state == RUNNABLE);
while (sandbox) { while (sandbox) {
worker_thread_switch_to_sandbox(sandbox); worker_thread_switch_to_sandbox(sandbox);
sandbox = worker_thread_execute_runtime_maintenance_and_get_next_sandbox(); worker_thread_execute_runtime_maintenance();
software_interrupt_disable();
sandbox = worker_thread_get_next_sandbox(0);
software_interrupt_enable();
assert(sandbox == NULL || sandbox->state == RUNNABLE);
} }
} }

Loading…
Cancel
Save