diff --git a/mk/rt.mk b/mk/rt.mk index 2eaa784e191..21aeae09cc8 100644 --- a/mk/rt.mk +++ b/mk/rt.mk @@ -51,6 +51,7 @@ RUNTIME_CS_$(1) := \ rt/rust_run_program.cpp \ rt/rust_env.cpp \ rt/rust_task_thread.cpp \ + rt/rust_sched_launcher.cpp \ rt/rust_scheduler.cpp \ rt/rust_task.cpp \ rt/rust_stack.cpp \ diff --git a/src/rt/rust_sched_launcher.cpp b/src/rt/rust_sched_launcher.cpp new file mode 100644 index 00000000000..ae0c002dd95 --- /dev/null +++ b/src/rt/rust_sched_launcher.cpp @@ -0,0 +1,16 @@ +#include "rust_sched_launcher.h" +#include "rust_scheduler.h" + +const size_t SCHED_STACK_SIZE = 1024*100; + +rust_sched_launcher::rust_sched_launcher(rust_scheduler *sched, + rust_srv *srv, int id) + : rust_thread(SCHED_STACK_SIZE), + kernel(sched->kernel), + thread(sched, srv, id) { +} + +void +rust_sched_launcher::run() { + thread.start_main_loop(); +} diff --git a/src/rt/rust_sched_launcher.h b/src/rt/rust_sched_launcher.h new file mode 100644 index 00000000000..4036ceb9c7e --- /dev/null +++ b/src/rt/rust_sched_launcher.h @@ -0,0 +1,29 @@ +#ifndef RUST_SCHED_LAUNCHER_H +#define RUST_SCHED_LAUNCHER_H + +#include "rust_internal.h" +#include "sync/rust_thread.h" + +#ifndef _WIN32 +#include +#else +#include +#endif + +class rust_sched_launcher + : public kernel_owned, + public rust_thread { +public: + rust_kernel *kernel; + +private: + rust_task_thread thread; + +public: + rust_sched_launcher(rust_scheduler *sched, rust_srv *srv, int id); + + virtual void run(); + rust_task_thread *get_loop() { return &thread; } +}; + +#endif // RUST_SCHED_LAUNCHER_H diff --git a/src/rt/rust_scheduler.cpp b/src/rt/rust_scheduler.cpp index 482739ded99..4153972f83a 100644 --- a/src/rt/rust_scheduler.cpp +++ b/src/rt/rust_scheduler.cpp @@ -1,5 +1,6 @@ #include "rust_scheduler.h" #include "rust_util.h" +#include "rust_sched_launcher.h" rust_scheduler::rust_scheduler(rust_kernel *kernel, rust_srv *srv, @@ -21,21 +22,20 @@ rust_scheduler::~rust_scheduler() { destroy_task_threads(); } -rust_task_thread * +rust_sched_launcher * rust_scheduler::create_task_thread(int id) { rust_srv *srv = this->srv->clone(); - rust_task_thread *thread = - new (kernel, "rust_task_thread") rust_task_thread(this, srv, id); - KLOG(kernel, kern, "created task thread: " PTR ", id: %d, index: %d", - thread, id, thread->list_index); + rust_sched_launcher *thread = + new (kernel, "rust_sched_launcher") rust_sched_launcher(this, srv, id); + KLOG(kernel, kern, "created task thread: " PTR ", id: %d", + thread, id); return thread; } void -rust_scheduler::destroy_task_thread(rust_task_thread *thread) { - KLOG(kernel, kern, "deleting task thread: " PTR ", name: %s, index: %d", - thread, thread->name, thread->list_index); - rust_srv *srv = thread->srv; +rust_scheduler::destroy_task_thread(rust_sched_launcher *thread) { + KLOG(kernel, kern, "deleting task thread: " PTR, thread); + rust_srv *srv = thread->get_loop()->srv; delete thread; delete srv; } @@ -60,7 +60,7 @@ void rust_scheduler::start_task_threads() { for(size_t i = 0; i < num_threads; ++i) { - rust_task_thread *thread = threads[i]; + rust_sched_launcher *thread = threads[i]; thread->start(); } } @@ -69,7 +69,7 @@ void rust_scheduler::join_task_threads() { for(size_t i = 0; i < num_threads; ++i) { - rust_task_thread *thread = threads[i]; + rust_sched_launcher *thread = threads[i]; thread->join(); } } @@ -77,8 +77,8 @@ rust_scheduler::join_task_threads() void rust_scheduler::kill_all_tasks() { for(size_t i = 0; i < num_threads; ++i) { - rust_task_thread *thread = threads[i]; - thread->kill_all_tasks(); + rust_sched_launcher *thread = threads[i]; + thread->get_loop()->kill_all_tasks(); } } @@ -92,8 +92,8 @@ rust_scheduler::create_task(rust_task *spawner, const char *name) { if (cur_thread >= num_threads) cur_thread = 0; } - rust_task_thread *thread = threads[thread_no]; - return thread->create_task(spawner, name); + rust_sched_launcher *thread = threads[thread_no]; + return thread->get_loop()->create_task(spawner, name); } void @@ -118,7 +118,7 @@ rust_scheduler::exit() { // scheduler will get destroyed, and our fields will cease to exist. size_t current_num_threads = num_threads; for(size_t i = 0; i < current_num_threads; ++i) { - threads[i]->exit(); + threads[i]->get_loop()->exit(); } } diff --git a/src/rt/rust_scheduler.h b/src/rt/rust_scheduler.h index dae867536fb..f1bfaf9b6b1 100644 --- a/src/rt/rust_scheduler.h +++ b/src/rt/rust_scheduler.h @@ -3,6 +3,8 @@ #include "rust_internal.h" +class rust_sched_launcher; + class rust_scheduler : public kernel_owned { // FIXME: Make these private public: @@ -17,7 +19,7 @@ private: // When this hits zero we'll tell the threads to exit uintptr_t live_tasks; - array_list threads; + array_list threads; const size_t num_threads; size_t cur_thread; @@ -26,8 +28,8 @@ private: void create_task_threads(); void destroy_task_threads(); - rust_task_thread *create_task_thread(int id); - void destroy_task_thread(rust_task_thread *thread); + rust_sched_launcher *create_task_thread(int id); + void destroy_task_thread(rust_sched_launcher *thread); void exit(); diff --git a/src/rt/rust_task_thread.cpp b/src/rt/rust_task_thread.cpp index 6a5b8bc2ab0..d692de1414d 100644 --- a/src/rt/rust_task_thread.cpp +++ b/src/rt/rust_task_thread.cpp @@ -13,7 +13,6 @@ pthread_key_t rust_task_thread::task_key; DWORD rust_task_thread::task_key; #endif -const size_t SCHED_STACK_SIZE = 1024*100; const size_t C_STACK_SIZE = 1024*1024; bool rust_task_thread::tls_initialized = false; @@ -21,7 +20,6 @@ bool rust_task_thread::tls_initialized = false; rust_task_thread::rust_task_thread(rust_scheduler *sched, rust_srv *srv, int id) : - rust_thread(SCHED_STACK_SIZE), _log(srv, this), id(id), should_exit(false), @@ -256,6 +254,8 @@ rust_task_thread::start_main_loop() { destroy_stack(kernel->region(), cached_c_stack); cached_c_stack = NULL; } + + sched->release_task_thread(); } rust_task * @@ -327,11 +327,6 @@ rust_task_thread::transition(rust_task *task, lock.signal(); } -void rust_task_thread::run() { - this->start_main_loop(); - sched->release_task_thread(); -} - #ifndef _WIN32 void rust_task_thread::init_tls() { diff --git a/src/rt/rust_task_thread.h b/src/rt/rust_task_thread.h index 6f178431144..a145cc6b12f 100644 --- a/src/rt/rust_task_thread.h +++ b/src/rt/rust_task_thread.h @@ -2,16 +2,9 @@ #define RUST_TASK_THREAD_H #include "rust_internal.h" -#include "sync/rust_thread.h" #include "rust_stack.h" #include "context.h" -#ifndef _WIN32 -#include -#else -#include -#endif - enum rust_task_state { task_state_newborn, task_state_running, @@ -21,8 +14,7 @@ enum rust_task_state { typedef indexed_list rust_task_list; -struct rust_task_thread : public kernel_owned, - rust_thread +struct rust_task_thread { private: @@ -75,6 +67,7 @@ public: randctx rctx; + // FIXME: Neither of these are used int32_t list_index; const char *const name; @@ -103,8 +96,6 @@ public: rust_task_state src, rust_task_state dst, rust_cond *cond, const char* cond_name); - virtual void run(); - void init_tls(); void place_task_in_tls(rust_task *task);