rt: Rename rust_scheduler to rust_task_thread

This commit is contained in:
Brian Anderson
2012-02-03 12:47:01 -08:00
parent f3343b3571
commit f94339cc1c
23 changed files with 273 additions and 274 deletions

View File

@@ -42,7 +42,7 @@ RUNTIME_CS_$(1) := \
rt/rust_run_program.cpp \ rt/rust_run_program.cpp \
rt/rust_crate_cache.cpp \ rt/rust_crate_cache.cpp \
rt/rust_env.cpp \ rt/rust_env.cpp \
rt/rust_scheduler.cpp \ rt/rust_task_thread.cpp \
rt/rust_task.cpp \ rt/rust_task.cpp \
rt/rust_task_list.cpp \ rt/rust_task_list.cpp \
rt/rust_port.cpp \ rt/rust_port.cpp \
@@ -79,7 +79,7 @@ RUNTIME_HDR_$(1) := rt/globals.h \
rt/rust_unwind.h \ rt/rust_unwind.h \
rt/rust_upcall.h \ rt/rust_upcall.h \
rt/rust_port.h \ rt/rust_port.h \
rt/rust_scheduler.h \ rt/rust_task_thread.h \
rt/rust_shape.h \ rt/rust_shape.h \
rt/rust_task.h \ rt/rust_task.h \
rt/rust_task_list.h \ rt/rust_task_list.h \

View File

@@ -5,7 +5,6 @@
#include "../rust_internal.h" #include "../rust_internal.h"
#include "../rust_util.h" #include "../rust_util.h"
#include "../rust_scheduler.h"
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>

View File

@@ -10,15 +10,15 @@ target triple = "@CFG_TARGET_TRIPLE@"
%struct.rust_vec = type { i32, i32, [0 x i8] } %struct.rust_vec = type { i32, i32, [0 x i8] }
%struct.rust_fn = type { i32*, %struct.rust_box* } %struct.rust_fn = type { i32*, %struct.rust_box* }
%struct.rust_box = type opaque %struct.rust_box = type opaque
%struct.rust_task = type { %struct.rust_task_user, i32, [8 x i8], %class.context, %struct.stk_seg*, i32, %struct.rust_scheduler*, %class.rust_crate_cache*, %class.rust_kernel*, i8*, %class.rust_task_list*, %struct.rust_cond*, i8*, %struct.rust_task*, i32, i32, i32*, i32, i32, %class.memory_region, %class.boxed_region, i8, i8, i8, %class.lock_and_signal, %class.hash_map.4, %class.rust_obstack, i32, %"class.debug::task_debug_info", i32, [12 x i8] } %struct.rust_task = type { %struct.rust_task_user, i32, [8 x i8], %class.context, %struct.stk_seg*, i32, %struct.rust_task_thread*, %class.rust_crate_cache*, %class.rust_kernel*, i8*, %class.rust_task_list*, %struct.rust_cond*, i8*, %struct.rust_task*, i32, i32, i32*, %class.memory_region, %class.boxed_region, i8, i8, i8, %class.lock_and_signal, %class.hash_map.4, %class.rust_obstack, i32, %"class.debug::task_debug_info", i32, [4 x i8] }
%struct.rust_task_user = type { i32, i32, %struct.chan_handle, i32 } %struct.rust_task_user = type { i32, i32, %struct.chan_handle, i32 }
%struct.chan_handle = type { i32, i32 } %struct.chan_handle = type { i32, i32 }
%class.context = type { %struct.registers_t, %class.context*, [12 x i8] } %class.context = type { %struct.registers_t, %class.context*, [12 x i8] }
%struct.registers_t = type { i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i16, i16, i16, i16, i32, i32, [12 x i8] } %struct.registers_t = type { i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i16, i16, i16, i16, i32, i32, [12 x i8] }
%struct.stk_seg = type { %struct.stk_seg*, %struct.stk_seg*, i32, i32, i32, [0 x i8] } %struct.stk_seg = type { %struct.stk_seg*, %struct.stk_seg*, i32, i32, i32, [0 x i8] }
%struct.rust_scheduler = type { %class.rust_thread, i32, i32, %class.rust_log, i32, %class.rust_srv*, i8*, %class.rust_task_list, %class.rust_task_list, %class.rust_task_list, %class.rust_task_list, %class.rust_crate_cache, %struct.randctx, %class.rust_kernel*, i32, i32, %class.lock_and_signal, i32, %union.pthread_attr_t, %struct.rust_env*, [8 x i8], %class.context } %struct.rust_task_thread = type { %class.rust_thread, i32, %class.rust_log, i32, %class.rust_srv*, i8*, %class.rust_task_list, %class.rust_task_list, %class.rust_task_list, %class.rust_task_list, %class.rust_crate_cache, %struct.randctx, %class.rust_kernel*, i32, i32, %class.lock_and_signal, i32, %union.pthread_attr_t, %struct.rust_env*, [12 x i8], %class.context, i8, [15 x i8] }
%class.rust_thread = type { i32 (...)**, i8, i32 } %class.rust_thread = type { i32 (...)**, i8, i32 }
%class.rust_log = type { i32 (...)**, %class.rust_srv*, %struct.rust_scheduler*, i8 } %class.rust_log = type { i32 (...)**, %class.rust_srv*, %struct.rust_task_thread*, i8 }
%class.rust_srv = type { i32 (...)**, %struct.rust_env*, %class.memory_region } %class.rust_srv = type { i32 (...)**, %struct.rust_env*, %class.memory_region }
%struct.rust_env = type { i32, i32, i32, i8*, i8, i8, i8* } %struct.rust_env = type { i32, i32, i32, i8*, i8, i8, i8* }
%class.memory_region = type { i32 (...)**, %class.rust_srv*, %class.memory_region*, i32, %class.array_list, i8, i8, %class.lock_and_signal } %class.memory_region = type { i32 (...)**, %class.rust_srv*, %class.memory_region*, i32, %class.array_list, i8, i8, %class.lock_and_signal }
@@ -30,14 +30,14 @@ target triple = "@CFG_TARGET_TRIPLE@"
%union.pthread_mutex_t = type { %"struct.<anonymous union>::__pthread_mutex_s" } %union.pthread_mutex_t = type { %"struct.<anonymous union>::__pthread_mutex_s" }
%"struct.<anonymous union>::__pthread_mutex_s" = type { i32, i32, i32, i32, i32, %union.anon } %"struct.<anonymous union>::__pthread_mutex_s" = type { i32, i32, i32, i32, i32, %union.anon }
%union.anon = type { i32 } %union.anon = type { i32 }
%class.rust_task_list = type { %class.indexed_list, %struct.rust_scheduler*, i8* } %class.rust_task_list = type { %class.indexed_list, %struct.rust_task_thread*, i8* }
%class.indexed_list = type { i32 (...)**, %class.array_list.1 } %class.indexed_list = type { i32 (...)**, %class.array_list.1 }
%class.array_list.1 = type { i32, %struct.rust_task**, i32 } %class.array_list.1 = type { i32, %struct.rust_task**, i32 }
%class.rust_crate_cache = type { %struct.type_desc*, %struct.rust_hashable_dict*, %struct.rust_scheduler*, i32 } %class.rust_crate_cache = type { %struct.type_desc*, %struct.rust_hashable_dict*, %struct.rust_task_thread*, i32 }
%struct.rust_hashable_dict = type { %struct.UT_hash_handle, [0 x i8*] } %struct.rust_hashable_dict = type { %struct.UT_hash_handle, [0 x i8*] }
%struct.randctx = type { i32, [256 x i32], [256 x i32], i32, i32, i32 } %struct.randctx = type { i32, [256 x i32], [256 x i32], i32, i32, i32 }
%class.rust_kernel = type { i32 (...)**, %class.memory_region, %class.rust_log, %class.rust_srv*, %class.lock_and_signal, %class.array_list.3, %struct.randctx, i32, %class.hash_map, i32, i32, i32, %struct.rust_env* } %class.rust_kernel = type { i32 (...)**, %class.memory_region, %class.rust_log, %class.rust_srv*, %class.lock_and_signal, %class.array_list.3, %struct.randctx, i32, %class.hash_map, i32, i32, i32, %struct.rust_env* }
%class.array_list.3 = type { i32, %struct.rust_scheduler**, i32 } %class.array_list.3 = type { i32, %struct.rust_task_thread**, i32 }
%class.hash_map = type { %"struct.hash_map<int, rust_task *>::map_entry"* } %class.hash_map = type { %"struct.hash_map<int, rust_task *>::map_entry"* }
%"struct.hash_map<int, rust_task *>::map_entry" = type opaque %"struct.hash_map<int, rust_task *>::map_entry" = type opaque
%union.pthread_attr_t = type { i32, [32 x i8] } %union.pthread_attr_t = type { i32, [32 x i8] }

View File

@@ -10,15 +10,15 @@ target triple = "@CFG_TARGET_TRIPLE@"
%struct.rust_vec = type { i64, i64, [0 x i8] } %struct.rust_vec = type { i64, i64, [0 x i8] }
%struct.rust_fn = type { i64*, %struct.rust_box* } %struct.rust_fn = type { i64*, %struct.rust_box* }
%struct.rust_box = type opaque %struct.rust_box = type opaque
%struct.rust_task = type { %struct.rust_task_user, i64, %class.context, %struct.stk_seg*, i64, %struct.rust_scheduler*, %class.rust_crate_cache*, %class.rust_kernel*, i8*, %class.rust_task_list*, %struct.rust_cond*, i8*, %struct.rust_task*, i32, i64, i64*, i32, i32, %class.memory_region, %class.boxed_region, i8, i8, i8, %class.lock_and_signal, %class.hash_map.4, %class.rust_obstack, i32, %"class.debug::task_debug_info", i64 } %struct.rust_task = type { %struct.rust_task_user, i64, %class.context, %struct.stk_seg*, i64, %struct.rust_task_thread*, %class.rust_crate_cache*, %class.rust_kernel*, i8*, %class.rust_task_list*, %struct.rust_cond*, i8*, %struct.rust_task*, i32, i64, i64*, %class.memory_region, %class.boxed_region, i8, i8, i8, %class.lock_and_signal, %class.hash_map.4, %class.rust_obstack, i32, %"class.debug::task_debug_info", i64, [8 x i8] }
%struct.rust_task_user = type { i64, i64, %struct.chan_handle, i64 } %struct.rust_task_user = type { i64, i64, %struct.chan_handle, i64 }
%struct.chan_handle = type { i64, i64 } %struct.chan_handle = type { i64, i64 }
%class.context = type { %struct.registers_t, %class.context*, [8 x i8] } %class.context = type { %struct.registers_t, %class.context*, [8 x i8] }
%struct.registers_t = type { [22 x i64] } %struct.registers_t = type { [22 x i64] }
%struct.stk_seg = type { %struct.stk_seg*, %struct.stk_seg*, i64, i32, [0 x i8] } %struct.stk_seg = type { %struct.stk_seg*, %struct.stk_seg*, i64, i32, [0 x i8] }
%struct.rust_scheduler = type { %class.rust_thread, i64, i64, %class.rust_log, i32, %class.rust_srv*, i8*, %class.rust_task_list, %class.rust_task_list, %class.rust_task_list, %class.rust_task_list, %class.rust_crate_cache, %struct.randctx, %class.rust_kernel*, i32, i32, %class.lock_and_signal, i64, %union.pthread_attr_t, %struct.rust_env*, %class.context } %struct.rust_task_thread = type { %class.rust_thread, i64, %class.rust_log, i32, %class.rust_srv*, i8*, %class.rust_task_list, %class.rust_task_list, %class.rust_task_list, %class.rust_task_list, %class.rust_crate_cache, %struct.randctx, %class.rust_kernel*, i32, i32, %class.lock_and_signal, i64, %union.pthread_attr_t, %struct.rust_env*, [8 x i8], %class.context, i8, [15 x i8] }
%class.rust_thread = type { i32 (...)**, i8, i64 } %class.rust_thread = type { i32 (...)**, i8, i64 }
%class.rust_log = type { i32 (...)**, %class.rust_srv*, %struct.rust_scheduler*, i8 } %class.rust_log = type { i32 (...)**, %class.rust_srv*, %struct.rust_task_thread*, i8 }
%class.rust_srv = type { i32 (...)**, %struct.rust_env*, %class.memory_region } %class.rust_srv = type { i32 (...)**, %struct.rust_env*, %class.memory_region }
%struct.rust_env = type { i64, i64, i64, i8*, i8, i8, i8* } %struct.rust_env = type { i64, i64, i64, i8*, i8, i8, i8* }
%class.memory_region = type { i32 (...)**, %class.rust_srv*, %class.memory_region*, i32, %class.array_list, i8, i8, %class.lock_and_signal } %class.memory_region = type { i32 (...)**, %class.rust_srv*, %class.memory_region*, i32, %class.array_list, i8, i8, %class.lock_and_signal }
@@ -30,14 +30,14 @@ target triple = "@CFG_TARGET_TRIPLE@"
%union.pthread_mutex_t = type { %"struct.<anonymous union>::__pthread_mutex_s" } %union.pthread_mutex_t = type { %"struct.<anonymous union>::__pthread_mutex_s" }
%"struct.<anonymous union>::__pthread_mutex_s" = type { i32, i32, i32, i32, i32, i32, %struct.__pthread_internal_list } %"struct.<anonymous union>::__pthread_mutex_s" = type { i32, i32, i32, i32, i32, i32, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { %struct.__pthread_internal_list*, %struct.__pthread_internal_list* } %struct.__pthread_internal_list = type { %struct.__pthread_internal_list*, %struct.__pthread_internal_list* }
%class.rust_task_list = type { %class.indexed_list, %struct.rust_scheduler*, i8* } %class.rust_task_list = type { %class.indexed_list, %struct.rust_task_thread*, i8* }
%class.indexed_list = type { i32 (...)**, %class.array_list.1 } %class.indexed_list = type { i32 (...)**, %class.array_list.1 }
%class.array_list.1 = type { i64, %struct.rust_task**, i64 } %class.array_list.1 = type { i64, %struct.rust_task**, i64 }
%class.rust_crate_cache = type { %struct.type_desc*, %struct.rust_hashable_dict*, %struct.rust_scheduler*, i64 } %class.rust_crate_cache = type { %struct.type_desc*, %struct.rust_hashable_dict*, %struct.rust_task_thread*, i64 }
%struct.rust_hashable_dict = type { %struct.UT_hash_handle, [0 x i8*] } %struct.rust_hashable_dict = type { %struct.UT_hash_handle, [0 x i8*] }
%struct.randctx = type { i64, [256 x i64], [256 x i64], i64, i64, i64 } %struct.randctx = type { i64, [256 x i64], [256 x i64], i64, i64, i64 }
%class.rust_kernel = type { i32 (...)**, %class.memory_region, %class.rust_log, %class.rust_srv*, %class.lock_and_signal, %class.array_list.3, %struct.randctx, i64, %class.hash_map, i32, i64, i32, %struct.rust_env* } %class.rust_kernel = type { i32 (...)**, %class.memory_region, %class.rust_log, %class.rust_srv*, %class.lock_and_signal, %class.array_list.3, %struct.randctx, i64, %class.hash_map, i32, i64, i32, %struct.rust_env* }
%class.array_list.3 = type { i64, %struct.rust_scheduler**, i64 } %class.array_list.3 = type { i64, %struct.rust_task_thread**, i64 }
%class.hash_map = type { %"struct.hash_map<long, rust_task *>::map_entry"* } %class.hash_map = type { %"struct.hash_map<long, rust_task *>::map_entry"* }
%"struct.hash_map<long, rust_task *>::map_entry" = type opaque %"struct.hash_map<long, rust_task *>::map_entry" = type opaque
%union.pthread_attr_t = type { i64, [48 x i8] } %union.pthread_attr_t = type { i64, [48 x i8] }

View File

@@ -90,15 +90,15 @@ rust_start(uintptr_t main_fn, int argc, char **argv, void* crate_map) {
rust_task_id root_id = kernel->create_task(NULL, "main", MAIN_STACK_SIZE); rust_task_id root_id = kernel->create_task(NULL, "main", MAIN_STACK_SIZE);
rust_task *root_task = kernel->get_task_by_id(root_id); rust_task *root_task = kernel->get_task_by_id(root_id);
I(kernel, root_task != NULL); I(kernel, root_task != NULL);
rust_scheduler *sched = root_task->sched; rust_task_thread *thread = root_task->thread;
command_line_args *args command_line_args *args
= new (kernel, "main command line args") = new (kernel, "main command line args")
command_line_args(root_task, argc, argv); command_line_args(root_task, argc, argv);
DLOG(sched, dom, "startup: %d args in 0x%" PRIxPTR, DLOG(thread, dom, "startup: %d args in 0x%" PRIxPTR,
args->argc, (uintptr_t)args->args); args->argc, (uintptr_t)args->args);
for (int i = 0; i < args->argc; i++) { for (int i = 0; i < args->argc; i++) {
DLOG(sched, dom, "startup: arg[%d] = '%s'", i, args->argv[i]); DLOG(thread, dom, "startup: arg[%d] = '%s'", i, args->argv[i]);
} }
root_task->start((spawn_fn)main_fn, NULL, args->args); root_task->start((spawn_fn)main_fn, NULL, args->args);

View File

@@ -1,7 +1,7 @@
/* Native builtins. */ /* Native builtins. */
#include "rust_internal.h" #include "rust_internal.h"
#include "rust_scheduler.h" #include "rust_task_thread.h"
#include "rust_task.h" #include "rust_task.h"
#include "rust_util.h" #include "rust_util.h"
#include "sync/timer.h" #include "sync/timer.h"
@@ -12,7 +12,7 @@
extern "C" CDECL rust_str* extern "C" CDECL rust_str*
last_os_error() { last_os_error() {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG(task, task, "last_os_error()"); LOG(task, task, "last_os_error()");
@@ -55,7 +55,7 @@ last_os_error() {
extern "C" CDECL rust_str * extern "C" CDECL rust_str *
rust_getcwd() { rust_getcwd() {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG(task, task, "rust_getcwd()"); LOG(task, task, "rust_getcwd()");
char cbuf[BUF_BYTES]; char cbuf[BUF_BYTES];
@@ -93,14 +93,14 @@ refcount(intptr_t *v) {
extern "C" CDECL void extern "C" CDECL void
unsupervise() { unsupervise() {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
task->unsupervise(); task->unsupervise();
} }
extern "C" CDECL void extern "C" CDECL void
vec_reserve_shared(type_desc* ty, rust_vec** vp, vec_reserve_shared(type_desc* ty, rust_vec** vp,
size_t n_elts) { size_t n_elts) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
reserve_vec(task, vp, n_elts * ty->size); reserve_vec(task, vp, n_elts * ty->size);
} }
@@ -110,7 +110,7 @@ vec_reserve_shared(type_desc* ty, rust_vec** vp,
*/ */
extern "C" CDECL rust_vec* extern "C" CDECL rust_vec*
vec_from_buf_shared(type_desc *ty, void *ptr, size_t count) { vec_from_buf_shared(type_desc *ty, void *ptr, size_t count) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
size_t fill = ty->size * count; size_t fill = ty->size * count;
rust_vec* v = (rust_vec*)task->kernel->malloc(fill + sizeof(rust_vec), rust_vec* v = (rust_vec*)task->kernel->malloc(fill + sizeof(rust_vec),
"vec_from_buf"); "vec_from_buf");
@@ -121,7 +121,7 @@ vec_from_buf_shared(type_desc *ty, void *ptr, size_t count) {
extern "C" CDECL void extern "C" CDECL void
rust_str_push(rust_vec** sp, uint8_t byte) { rust_str_push(rust_vec** sp, uint8_t byte) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
size_t fill = (*sp)->fill; size_t fill = (*sp)->fill;
reserve_vec(task, sp, fill + 1); reserve_vec(task, sp, fill + 1);
(*sp)->data[fill-1] = byte; (*sp)->data[fill-1] = byte;
@@ -131,14 +131,14 @@ rust_str_push(rust_vec** sp, uint8_t byte) {
extern "C" CDECL void * extern "C" CDECL void *
rand_new() { rand_new() {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
rust_scheduler *sched = task->sched; rust_task_thread *thread = task->thread;
randctx *rctx = (randctx *) task->malloc(sizeof(randctx), "randctx"); randctx *rctx = (randctx *) task->malloc(sizeof(randctx), "randctx");
if (!rctx) { if (!rctx) {
task->fail(); task->fail();
return NULL; return NULL;
} }
isaac_init(sched, rctx); isaac_init(thread, rctx);
return rctx; return rctx;
} }
@@ -149,7 +149,7 @@ rand_next(randctx *rctx) {
extern "C" CDECL void extern "C" CDECL void
rand_free(randctx *rctx) { rand_free(randctx *rctx) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
task->free(rctx); task->free(rctx);
} }
@@ -158,7 +158,7 @@ rand_free(randctx *rctx) {
static void static void
debug_tydesc_helper(type_desc *t) debug_tydesc_helper(type_desc *t)
{ {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG(task, stdlib, " size %" PRIdPTR ", align %" PRIdPTR LOG(task, stdlib, " size %" PRIdPTR ", align %" PRIdPTR
", first_param 0x%" PRIxPTR, ", first_param 0x%" PRIxPTR,
t->size, t->align, t->first_param); t->size, t->align, t->first_param);
@@ -166,14 +166,14 @@ debug_tydesc_helper(type_desc *t)
extern "C" CDECL void extern "C" CDECL void
debug_tydesc(type_desc *t) { debug_tydesc(type_desc *t) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG(task, stdlib, "debug_tydesc"); LOG(task, stdlib, "debug_tydesc");
debug_tydesc_helper(t); debug_tydesc_helper(t);
} }
extern "C" CDECL void extern "C" CDECL void
debug_opaque(type_desc *t, uint8_t *front) { debug_opaque(type_desc *t, uint8_t *front) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG(task, stdlib, "debug_opaque"); LOG(task, stdlib, "debug_opaque");
debug_tydesc_helper(t); debug_tydesc_helper(t);
// FIXME may want to actually account for alignment. `front` may not // FIXME may want to actually account for alignment. `front` may not
@@ -192,7 +192,7 @@ struct rust_box {
extern "C" CDECL void extern "C" CDECL void
debug_box(type_desc *t, rust_box *box) { debug_box(type_desc *t, rust_box *box) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG(task, stdlib, "debug_box(0x%" PRIxPTR ")", box); LOG(task, stdlib, "debug_box(0x%" PRIxPTR ")", box);
debug_tydesc_helper(t); debug_tydesc_helper(t);
LOG(task, stdlib, " refcount %" PRIdPTR, LOG(task, stdlib, " refcount %" PRIdPTR,
@@ -209,7 +209,7 @@ struct rust_tag {
extern "C" CDECL void extern "C" CDECL void
debug_tag(type_desc *t, rust_tag *tag) { debug_tag(type_desc *t, rust_tag *tag) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG(task, stdlib, "debug_tag"); LOG(task, stdlib, "debug_tag");
debug_tydesc_helper(t); debug_tydesc_helper(t);
@@ -227,7 +227,7 @@ struct rust_obj {
extern "C" CDECL void extern "C" CDECL void
debug_obj(type_desc *t, rust_obj *obj, size_t nmethods, size_t nbytes) { debug_obj(type_desc *t, rust_obj *obj, size_t nmethods, size_t nbytes) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG(task, stdlib, "debug_obj with %" PRIdPTR " methods", nmethods); LOG(task, stdlib, "debug_obj with %" PRIdPTR " methods", nmethods);
debug_tydesc_helper(t); debug_tydesc_helper(t);
@@ -249,7 +249,7 @@ struct rust_fn {
extern "C" CDECL void extern "C" CDECL void
debug_fn(type_desc *t, rust_fn *fn) { debug_fn(type_desc *t, rust_fn *fn) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG(task, stdlib, "debug_fn"); LOG(task, stdlib, "debug_fn");
debug_tydesc_helper(t); debug_tydesc_helper(t);
LOG(task, stdlib, " thunk at 0x%" PRIxPTR, fn->thunk); LOG(task, stdlib, " thunk at 0x%" PRIxPTR, fn->thunk);
@@ -263,7 +263,7 @@ extern "C" CDECL void *
debug_ptrcast(type_desc *from_ty, debug_ptrcast(type_desc *from_ty,
type_desc *to_ty, type_desc *to_ty,
void *ptr) { void *ptr) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG(task, stdlib, "debug_ptrcast from"); LOG(task, stdlib, "debug_ptrcast from");
debug_tydesc_helper(from_ty); debug_tydesc_helper(from_ty);
LOG(task, stdlib, "to"); LOG(task, stdlib, "to");
@@ -273,13 +273,13 @@ debug_ptrcast(type_desc *from_ty,
extern "C" CDECL void * extern "C" CDECL void *
debug_get_stk_seg() { debug_get_stk_seg() {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
return task->stk; return task->stk;
} }
extern "C" CDECL rust_vec* extern "C" CDECL rust_vec*
rust_list_files(rust_str *path) { rust_list_files(rust_str *path) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
array_list<rust_str*> strings; array_list<rust_str*> strings;
#if defined(__WIN32__) #if defined(__WIN32__)
WIN32_FIND_DATA FindFileData; WIN32_FIND_DATA FindFileData;
@@ -346,7 +346,7 @@ rust_ptr_eq(type_desc *t, rust_box *a, rust_box *b) {
#if defined(__WIN32__) #if defined(__WIN32__)
extern "C" CDECL void extern "C" CDECL void
get_time(uint32_t *sec, uint32_t *usec) { get_time(uint32_t *sec, uint32_t *usec) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
SYSTEMTIME systemTime; SYSTEMTIME systemTime;
FILETIME fileTime; FILETIME fileTime;
GetSystemTime(&systemTime); GetSystemTime(&systemTime);
@@ -377,13 +377,13 @@ nano_time(uint64_t *ns) {
extern "C" CDECL rust_task_id extern "C" CDECL rust_task_id
get_task_id() { get_task_id() {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
return task->user.id; return task->user.id;
} }
extern "C" CDECL rust_task_id extern "C" CDECL rust_task_id
new_task() { new_task() {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
return task->kernel->create_task(task, NULL); return task->kernel->create_task(task, NULL);
} }
@@ -396,18 +396,18 @@ drop_task(rust_task *target) {
extern "C" CDECL rust_task * extern "C" CDECL rust_task *
get_task_pointer(rust_task_id id) { get_task_pointer(rust_task_id id) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
return task->kernel->get_task_by_id(id); return task->kernel->get_task_by_id(id);
} }
extern "C" rust_task * extern "C" rust_task *
rust_get_task() { rust_get_task() {
return rust_scheduler::get_task(); return rust_task_thread::get_task();
} }
extern "C" CDECL void extern "C" CDECL void
start_task(rust_task_id id, fn_env_pair *f) { start_task(rust_task_id id, fn_env_pair *f) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
rust_task *target = task->kernel->get_task_by_id(id); rust_task *target = task->kernel->get_task_by_id(id);
target->start(f->f, f->env, NULL); target->start(f->f, f->env, NULL);
target->deref(); target->deref();
@@ -415,13 +415,13 @@ start_task(rust_task_id id, fn_env_pair *f) {
extern "C" CDECL int extern "C" CDECL int
sched_threads() { sched_threads() {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
return task->kernel->num_threads; return task->kernel->num_threads;
} }
extern "C" CDECL rust_port* extern "C" CDECL rust_port*
new_port(size_t unit_sz) { new_port(size_t unit_sz) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG(task, comm, "new_port(task=0x%" PRIxPTR " (%s), unit_sz=%d)", LOG(task, comm, "new_port(task=0x%" PRIxPTR " (%s), unit_sz=%d)",
(uintptr_t) task, task->name, unit_sz); (uintptr_t) task, task->name, unit_sz);
// port starts with refcount == 1 // port starts with refcount == 1
@@ -430,7 +430,7 @@ new_port(size_t unit_sz) {
extern "C" CDECL void extern "C" CDECL void
rust_port_detach(rust_port *port) { rust_port_detach(rust_port *port) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG(task, comm, "rust_port_detach(0x%" PRIxPTR ")", (uintptr_t) port); LOG(task, comm, "rust_port_detach(0x%" PRIxPTR ")", (uintptr_t) port);
port->detach(); port->detach();
// FIXME: Busy waiting until we're the only ref // FIXME: Busy waiting until we're the only ref
@@ -443,9 +443,9 @@ rust_port_detach(rust_port *port) {
extern "C" CDECL void extern "C" CDECL void
del_port(rust_port *port) { del_port(rust_port *port) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG(task, comm, "del_port(0x%" PRIxPTR ")", (uintptr_t) port); LOG(task, comm, "del_port(0x%" PRIxPTR ")", (uintptr_t) port);
A(task->sched, port->ref_count == 1, "Expected port ref_count == 1"); A(task->thread, port->ref_count == 1, "Expected port ref_count == 1");
port->deref(); port->deref();
} }
@@ -464,7 +464,7 @@ chan_id_send(type_desc *t, rust_task_id target_task_id,
rust_port_id target_port_id, void *sptr) { rust_port_id target_port_id, void *sptr) {
// FIXME: make sure this is thread-safe // FIXME: make sure this is thread-safe
bool sent = false; bool sent = false;
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
rust_task *target_task = task->kernel->get_task_by_id(target_task_id); rust_task *target_task = task->kernel->get_task_by_id(target_task_id);
if(target_task) { if(target_task) {
rust_port *port = target_task->get_port_by_id(target_port_id); rust_port *port = target_task->get_port_by_id(target_port_id);
@@ -491,7 +491,7 @@ port_recv(uintptr_t *dptr, rust_port *port,
uintptr_t *yield, uintptr_t *killed) { uintptr_t *yield, uintptr_t *killed) {
*yield = false; *yield = false;
*killed = false; *killed = false;
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
{ {
scoped_lock with(port->lock); scoped_lock with(port->lock);
@@ -524,7 +524,7 @@ port_recv(uintptr_t *dptr, rust_port *port,
extern "C" CDECL void extern "C" CDECL void
rust_set_exit_status(intptr_t code) { rust_set_exit_status(intptr_t code) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
task->kernel->set_exit_status((int)code); task->kernel->set_exit_status((int)code);
} }
@@ -539,7 +539,7 @@ extern void log_console_off(rust_env *env);
extern "C" CDECL void extern "C" CDECL void
rust_log_console_off() { rust_log_console_off() {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
log_console_off(task->kernel->env); log_console_off(task->kernel->env);
} }

View File

@@ -9,20 +9,20 @@ rust_crate_cache::get_type_desc(size_t size,
type_desc const **descs, type_desc const **descs,
uintptr_t n_obj_params) uintptr_t n_obj_params)
{ {
I(sched, n_descs > 1); I(thread, n_descs > 1);
type_desc *td = NULL; type_desc *td = NULL;
size_t keysz = n_descs * sizeof(type_desc*); size_t keysz = n_descs * sizeof(type_desc*);
HASH_FIND(hh, this->type_descs, descs, keysz, td); HASH_FIND(hh, this->type_descs, descs, keysz, td);
if (td) { if (td) {
DLOG(sched, cache, "rust_crate_cache::get_type_desc hit"); DLOG(thread, cache, "rust_crate_cache::get_type_desc hit");
// FIXME: This is a gross hack. // FIXME: This is a gross hack.
td->n_obj_params = std::max(td->n_obj_params, n_obj_params); td->n_obj_params = std::max(td->n_obj_params, n_obj_params);
return td; return td;
} }
DLOG(sched, cache, "rust_crate_cache::get_type_desc miss"); DLOG(thread, cache, "rust_crate_cache::get_type_desc miss");
td = (type_desc*) sched->kernel->malloc(sizeof(type_desc) + keysz, td = (type_desc*) thread->kernel->malloc(sizeof(type_desc) + keysz,
"crate cache typedesc"); "crate cache typedesc");
if (!td) if (!td)
return NULL; return NULL;
@@ -34,7 +34,7 @@ rust_crate_cache::get_type_desc(size_t size,
td->size = size; td->size = size;
td->align = align; td->align = align;
for (size_t i = 0; i < n_descs; ++i) { for (size_t i = 0; i < n_descs; ++i) {
DLOG(sched, cache, DLOG(thread, cache,
"rust_crate_cache::descs[%" PRIdPTR "] = 0x%" PRIxPTR, "rust_crate_cache::descs[%" PRIdPTR "] = 0x%" PRIxPTR,
i, descs[i]); i, descs[i]);
td->descs[i] = descs[i]; td->descs[i] = descs[i];
@@ -52,7 +52,7 @@ rust_crate_cache::get_dict(size_t n_fields, void** dict) {
HASH_FIND(hh, this->dicts, dict, dictsz, found); HASH_FIND(hh, this->dicts, dict, dictsz, found);
if (found) return &(found->fields[0]); if (found) return &(found->fields[0]);
found = (rust_hashable_dict*) found = (rust_hashable_dict*)
sched->kernel->malloc(sizeof(UT_hash_handle) + dictsz, thread->kernel->malloc(sizeof(UT_hash_handle) + dictsz,
"crate cache dict"); "crate cache dict");
if (!found) return NULL; if (!found) return NULL;
void** retptr = &(found->fields[0]); void** retptr = &(found->fields[0]);
@@ -61,28 +61,28 @@ rust_crate_cache::get_dict(size_t n_fields, void** dict) {
return retptr; return retptr;
} }
rust_crate_cache::rust_crate_cache(rust_scheduler *sched) rust_crate_cache::rust_crate_cache(rust_task_thread *thread)
: type_descs(NULL), : type_descs(NULL),
dicts(NULL), dicts(NULL),
sched(sched), thread(thread),
idx(0) idx(0)
{ {
} }
void void
rust_crate_cache::flush() { rust_crate_cache::flush() {
DLOG(sched, cache, "rust_crate_cache::flush()"); DLOG(thread, cache, "rust_crate_cache::flush()");
while (type_descs) { while (type_descs) {
type_desc *d = type_descs; type_desc *d = type_descs;
HASH_DEL(type_descs, d); HASH_DEL(type_descs, d);
DLOG(sched, mem, "rust_crate_cache::flush() tydesc %" PRIxPTR, d); DLOG(thread, mem, "rust_crate_cache::flush() tydesc %" PRIxPTR, d);
sched->kernel->free(d); thread->kernel->free(d);
} }
while (dicts) { while (dicts) {
rust_hashable_dict *d = dicts; rust_hashable_dict *d = dicts;
HASH_DEL(dicts, d); HASH_DEL(dicts, d);
sched->kernel->free(d); thread->kernel->free(d);
} }
} }

View File

@@ -50,7 +50,7 @@ extern "C" {
#include "sync/lock_and_signal.h" #include "sync/lock_and_signal.h"
#include "sync/lock_free_queue.h" #include "sync/lock_free_queue.h"
struct rust_scheduler; struct rust_task_thread;
struct rust_task; struct rust_task;
class rust_log; class rust_log;
class rust_port; class rust_port;
@@ -217,7 +217,7 @@ public:
#include "rust_srv.h" #include "rust_srv.h"
#include "rust_log.h" #include "rust_log.h"
#include "rust_kernel.h" #include "rust_kernel.h"
#include "rust_scheduler.h" #include "rust_task_thread.h"
typedef void CDECL (glue_fn)(void *, void *, typedef void CDECL (glue_fn)(void *, void *,
const type_desc **, void *); const type_desc **, void *);

View File

@@ -20,25 +20,25 @@ rust_kernel::rust_kernel(rust_srv *srv, size_t num_threads) :
create_schedulers(); create_schedulers();
} }
rust_scheduler * rust_task_thread *
rust_kernel::create_scheduler(int id) { rust_kernel::create_scheduler(int id) {
_kernel_lock.lock(); _kernel_lock.lock();
rust_srv *srv = this->srv->clone(); rust_srv *srv = this->srv->clone();
rust_scheduler *sched = rust_task_thread *thread =
new (this, "rust_scheduler") rust_scheduler(this, srv, id); new (this, "rust_task_thread") rust_task_thread(this, srv, id);
KLOG_("created scheduler: " PTR ", id: %d, index: %d", KLOG_("created scheduler: " PTR ", id: %d, index: %d",
sched, id, sched->list_index); thread, id, thread->list_index);
_kernel_lock.unlock(); _kernel_lock.unlock();
return sched; return thread;
} }
void void
rust_kernel::destroy_scheduler(rust_scheduler *sched) { rust_kernel::destroy_scheduler(rust_task_thread *thread) {
_kernel_lock.lock(); _kernel_lock.lock();
KLOG_("deleting scheduler: " PTR ", name: %s, index: %d", KLOG_("deleting scheduler: " PTR ", name: %s, index: %d",
sched, sched->name, sched->list_index); thread, thread->name, thread->list_index);
rust_srv *srv = sched->srv; rust_srv *srv = thread->srv;
delete sched; delete thread;
delete srv; delete srv;
_kernel_lock.unlock(); _kernel_lock.unlock();
} }
@@ -120,12 +120,12 @@ rust_kernel::signal_kernel_lock() {
int rust_kernel::start_task_threads() int rust_kernel::start_task_threads()
{ {
for(size_t i = 0; i < num_threads; ++i) { for(size_t i = 0; i < num_threads; ++i) {
rust_scheduler *thread = threads[i]; rust_task_thread *thread = threads[i];
thread->start(); thread->start();
} }
for(size_t i = 0; i < num_threads; ++i) { for(size_t i = 0; i < num_threads; ++i) {
rust_scheduler *thread = threads[i]; rust_task_thread *thread = threads[i];
thread->join(); thread->join();
} }
@@ -142,7 +142,7 @@ rust_kernel::fail() {
exit(rval); exit(rval);
#endif #endif
for(size_t i = 0; i < num_threads; ++i) { for(size_t i = 0; i < num_threads; ++i) {
rust_scheduler *thread = threads[i]; rust_task_thread *thread = threads[i];
thread->kill_all_tasks(); thread->kill_all_tasks();
} }
} }
@@ -151,7 +151,7 @@ rust_task_id
rust_kernel::create_task(rust_task *spawner, const char *name, rust_kernel::create_task(rust_task *spawner, const char *name,
size_t init_stack_sz) { size_t init_stack_sz) {
scoped_lock with(_kernel_lock); scoped_lock with(_kernel_lock);
rust_scheduler *thread = threads[isaac_rand(&rctx) % num_threads]; rust_task_thread *thread = threads[isaac_rand(&rctx) % num_threads];
rust_task *t = thread->create_task(spawner, name, init_stack_sz); rust_task *t = thread->create_task(spawner, name, init_stack_sz);
t->user.id = max_id++; t->user.id = max_id++;
task_table.put(t->user.id, t); task_table.put(t->user.id, t);

View File

@@ -5,7 +5,7 @@
#include "memory_region.h" #include "memory_region.h"
#include "rust_log.h" #include "rust_log.h"
struct rust_scheduler; struct rust_task_thread;
/** /**
* A global object shared by all thread domains. Most of the data structures * A global object shared by all thread domains. Most of the data structures
@@ -21,12 +21,12 @@ public:
private: private:
lock_and_signal _kernel_lock; lock_and_signal _kernel_lock;
array_list<rust_scheduler *> threads; array_list<rust_task_thread *> threads;
randctx rctx; randctx rctx;
rust_scheduler *create_scheduler(int id); rust_task_thread *create_scheduler(int id);
void destroy_scheduler(rust_scheduler *sched); void destroy_scheduler(rust_task_thread *thread);
void create_schedulers(); void create_schedulers();
void destroy_schedulers(); void destroy_schedulers();

View File

@@ -40,9 +40,9 @@ log_console_off(rust_env *env) {
} }
} }
rust_log::rust_log(rust_srv *srv, rust_scheduler *sched) : rust_log::rust_log(rust_srv *srv, rust_task_thread *thread) :
_srv(srv), _srv(srv),
_sched(sched) { _thread(thread) {
} }
rust_log::~rust_log() { rust_log::~rust_log() {
@@ -118,12 +118,12 @@ rust_log::trace_ln(rust_task *task, uint32_t level, char *message) {
#endif #endif
char prefix[BUF_BYTES] = ""; char prefix[BUF_BYTES] = "";
if (_sched && _sched->name) { if (_thread && _thread->name) {
append_string(prefix, "%04" PRIxPTR ":%.10s:", append_string(prefix, "%04" PRIxPTR ":%.10s:",
thread_id, _sched->name); thread_id, _thread->name);
} else { } else {
append_string(prefix, "%04" PRIxPTR ":0x%08" PRIxPTR ":", append_string(prefix, "%04" PRIxPTR ":0x%08" PRIxPTR ":",
thread_id, (uintptr_t) _sched); thread_id, (uintptr_t) _thread);
} }
if (task) { if (task) {
if (task->name) { if (task->name) {

View File

@@ -8,18 +8,18 @@ const uint32_t log_info = 2;
const uint32_t log_debug = 3; const uint32_t log_debug = 3;
#define LOG(task, field, ...) \ #define LOG(task, field, ...) \
DLOG_LVL(log_debug, task, task->sched, field, __VA_ARGS__) DLOG_LVL(log_debug, task, task->thread, field, __VA_ARGS__)
#define LOG_ERR(task, field, ...) \ #define LOG_ERR(task, field, ...) \
DLOG_LVL(log_err, task, task->sched, field, __VA_ARGS__) DLOG_LVL(log_err, task, task->thread, field, __VA_ARGS__)
#define DLOG(sched, field, ...) \ #define DLOG(thread, field, ...) \
DLOG_LVL(log_debug, NULL, sched, field, __VA_ARGS__) DLOG_LVL(log_debug, NULL, thread, field, __VA_ARGS__)
#define DLOG_ERR(sched, field, ...) \ #define DLOG_ERR(thread, field, ...) \
DLOG_LVL(log_err, NULL, sched, field, __VA_ARGS__) DLOG_LVL(log_err, NULL, thread, field, __VA_ARGS__)
#define LOGPTR(sched, msg, ptrval) \ #define LOGPTR(thread, msg, ptrval) \
DLOG_LVL(log_debug, NULL, sched, mem, "%s 0x%" PRIxPTR, msg, ptrval) DLOG_LVL(log_debug, NULL, thread, mem, "%s 0x%" PRIxPTR, msg, ptrval)
#define DLOG_LVL(lvl, task, sched, field, ...) \ #define DLOG_LVL(lvl, task, thread, field, ...) \
do { \ do { \
rust_scheduler* _d_ = sched; \ rust_task_thread* _d_ = thread; \
if (log_rt_##field >= lvl && _d_->log_lvl >= lvl) { \ if (log_rt_##field >= lvl && _d_->log_lvl >= lvl) { \
_d_->log(task, lvl, __VA_ARGS__); \ _d_->log(task, lvl, __VA_ARGS__); \
} \ } \
@@ -34,13 +34,13 @@ const uint32_t log_debug = 3;
} \ } \
} while (0) } while (0)
struct rust_scheduler; struct rust_task_thread;
struct rust_task; struct rust_task;
class rust_log { class rust_log {
public: public:
rust_log(rust_srv *srv, rust_scheduler *sched); rust_log(rust_srv *srv, rust_task_thread *thread);
virtual ~rust_log(); virtual ~rust_log();
void trace_ln(rust_task *task, uint32_t level, char *message); void trace_ln(rust_task *task, uint32_t level, char *message);
@@ -49,7 +49,7 @@ public:
private: private:
rust_srv *_srv; rust_srv *_srv;
rust_scheduler *_sched; rust_task_thread *_thread;
bool _use_labels; bool _use_labels;
void trace_ln(rust_task *task, char *message); void trace_ln(rust_task *task, char *message);
}; };

View File

@@ -21,7 +21,7 @@ rust_port::~rust_port() {
} }
void rust_port::detach() { void rust_port::detach() {
I(task->sched, !task->lock.lock_held_by_current_thread()); I(task->thread, !task->lock.lock_held_by_current_thread());
scoped_lock with(task->lock); scoped_lock with(task->lock);
{ {
task->release_port(id); task->release_port(id);
@@ -29,7 +29,7 @@ void rust_port::detach() {
} }
void rust_port::send(void *sptr) { void rust_port::send(void *sptr) {
I(task->sched, !lock.lock_held_by_current_thread()); I(task->thread, !lock.lock_held_by_current_thread());
scoped_lock with(lock); scoped_lock with(lock);
buffer.enqueue(sptr); buffer.enqueue(sptr);
@@ -46,7 +46,7 @@ void rust_port::send(void *sptr) {
} }
bool rust_port::receive(void *dptr) { bool rust_port::receive(void *dptr) {
I(task->sched, lock.lock_held_by_current_thread()); I(task->thread, lock.lock_held_by_current_thread());
if (buffer.is_empty() == false) { if (buffer.is_empty() == false) {
buffer.dequeue(dptr); buffer.dequeue(dptr);
LOG(task, comm, "<=== read data ==="); LOG(task, comm, "<=== read data ===");
@@ -56,7 +56,7 @@ bool rust_port::receive(void *dptr) {
} }
size_t rust_port::size() { size_t rust_port::size() {
I(task->sched, !lock.lock_held_by_current_thread()); I(task->thread, !lock.lock_held_by_current_thread());
scoped_lock with(lock); scoped_lock with(lock);
return buffer.size(); return buffer.size();
} }

View File

@@ -532,7 +532,7 @@ extern "C" void
shape_cmp_type(int8_t *result, const type_desc *tydesc, shape_cmp_type(int8_t *result, const type_desc *tydesc,
const type_desc **subtydescs, uint8_t *data_0, const type_desc **subtydescs, uint8_t *data_0,
uint8_t *data_1, uint8_t cmp_type) { uint8_t *data_1, uint8_t cmp_type) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
shape::arena arena; shape::arena arena;
// FIXME: This may well be broken when comparing two closures or objects // FIXME: This may well be broken when comparing two closures or objects
@@ -553,7 +553,7 @@ shape_cmp_type(int8_t *result, const type_desc *tydesc,
extern "C" rust_str * extern "C" rust_str *
shape_log_str(const type_desc *tydesc, uint8_t *data) { shape_log_str(const type_desc *tydesc, uint8_t *data) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
shape::arena arena; shape::arena arena;
shape::type_param *params = shape::type_param *params =
@@ -571,7 +571,7 @@ shape_log_str(const type_desc *tydesc, uint8_t *data) {
extern "C" void extern "C" void
shape_log_type(const type_desc *tydesc, uint8_t *data, uint32_t level) { shape_log_type(const type_desc *tydesc, uint8_t *data, uint32_t level) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
shape::arena arena; shape::arena arena;
shape::type_param *params = shape::type_param *params =
@@ -583,6 +583,6 @@ shape_log_type(const type_desc *tydesc, uint8_t *data, uint32_t level) {
log.walk(); log.walk();
task->sched->log(task, level, "%s", ss.str().c_str()); task->thread->log(task, level, "%s", ss.str().c_str());
} }

View File

@@ -67,7 +67,7 @@ const uint8_t stack_canary[] = {0xAB, 0xCD, 0xAB, 0xCD,
0xAB, 0xCD, 0xAB, 0xCD}; 0xAB, 0xCD, 0xAB, 0xCD};
static size_t static size_t
get_next_stk_size(rust_scheduler *sched, rust_task *task, get_next_stk_size(rust_task_thread *thread, rust_task *task,
size_t min, size_t current, size_t requested) { size_t min, size_t current, size_t requested) {
LOG(task, mem, "calculating new stack size for 0x%" PRIxPTR, task); LOG(task, mem, "calculating new stack size for 0x%" PRIxPTR, task);
LOG(task, mem, LOG(task, mem,
@@ -84,7 +84,7 @@ get_next_stk_size(rust_scheduler *sched, rust_task *task,
sz = std::max(sz, next); sz = std::max(sz, next);
LOG(task, mem, "next stack size: %" PRIdPTR, sz); LOG(task, mem, "next stack size: %" PRIdPTR, sz);
I(sched, requested <= sz); I(thread, requested <= sz);
return sz; return sz;
} }
@@ -132,13 +132,13 @@ user_stack_size(stk_seg *stk) {
static void static void
free_stk(rust_task *task, stk_seg *stk) { free_stk(rust_task *task, stk_seg *stk) {
LOGPTR(task->sched, "freeing stk segment", (uintptr_t)stk); LOGPTR(task->thread, "freeing stk segment", (uintptr_t)stk);
task->total_stack_sz -= user_stack_size(stk); task->total_stack_sz -= user_stack_size(stk);
task->free(stk); task->free(stk);
} }
static stk_seg* static stk_seg*
new_stk(rust_scheduler *sched, rust_task *task, size_t requested_sz) new_stk(rust_task_thread *thread, rust_task *task, size_t requested_sz)
{ {
LOG(task, mem, "creating new stack for task %" PRIxPTR, task); LOG(task, mem, "creating new stack for task %" PRIxPTR, task);
if (task->stk) { if (task->stk) {
@@ -146,7 +146,7 @@ new_stk(rust_scheduler *sched, rust_task *task, size_t requested_sz)
} }
// The minimum stack size, in bytes, of a Rust stack, excluding red zone // The minimum stack size, in bytes, of a Rust stack, excluding red zone
size_t min_sz = sched->min_stack_size; size_t min_sz = thread->min_stack_size;
// Try to reuse an existing stack segment // Try to reuse an existing stack segment
if (task->stk != NULL && task->stk->prev != NULL) { if (task->stk != NULL && task->stk->prev != NULL) {
@@ -154,7 +154,7 @@ new_stk(rust_scheduler *sched, rust_task *task, size_t requested_sz)
if (min_sz <= prev_sz && requested_sz <= prev_sz) { if (min_sz <= prev_sz && requested_sz <= prev_sz) {
LOG(task, mem, "reusing existing stack"); LOG(task, mem, "reusing existing stack");
task->stk = task->stk->prev; task->stk = task->stk->prev;
A(sched, task->stk->prev == NULL, "Bogus stack ptr"); A(thread, task->stk->prev == NULL, "Bogus stack ptr");
config_valgrind_stack(task->stk); config_valgrind_stack(task->stk);
return task->stk; return task->stk;
} else { } else {
@@ -170,23 +170,23 @@ new_stk(rust_scheduler *sched, rust_task *task, size_t requested_sz)
current_sz = user_stack_size(task->stk); current_sz = user_stack_size(task->stk);
} }
// The calculated size of the new stack, excluding red zone // The calculated size of the new stack, excluding red zone
size_t rust_stk_sz = get_next_stk_size(sched, task, min_sz, size_t rust_stk_sz = get_next_stk_size(thread, task, min_sz,
current_sz, requested_sz); current_sz, requested_sz);
if (task->total_stack_sz + rust_stk_sz > sched->env->max_stack_size) { if (task->total_stack_sz + rust_stk_sz > thread->env->max_stack_size) {
LOG_ERR(task, task, "task %" PRIxPTR " ran out of stack", task); LOG_ERR(task, task, "task %" PRIxPTR " ran out of stack", task);
task->fail(); task->fail();
} }
size_t sz = sizeof(stk_seg) + rust_stk_sz + RED_ZONE_SIZE; size_t sz = sizeof(stk_seg) + rust_stk_sz + RED_ZONE_SIZE;
stk_seg *stk = (stk_seg *)task->malloc(sz, "stack"); stk_seg *stk = (stk_seg *)task->malloc(sz, "stack");
LOGPTR(task->sched, "new stk", (uintptr_t)stk); LOGPTR(task->thread, "new stk", (uintptr_t)stk);
memset(stk, 0, sizeof(stk_seg)); memset(stk, 0, sizeof(stk_seg));
add_stack_canary(stk); add_stack_canary(stk);
stk->prev = NULL; stk->prev = NULL;
stk->next = task->stk; stk->next = task->stk;
stk->end = (uintptr_t) &stk->data[rust_stk_sz + RED_ZONE_SIZE]; stk->end = (uintptr_t) &stk->data[rust_stk_sz + RED_ZONE_SIZE];
LOGPTR(task->sched, "stk end", stk->end); LOGPTR(task->thread, "stk end", stk->end);
task->stk = stk; task->stk = stk;
config_valgrind_stack(task->stk); config_valgrind_stack(task->stk);
@@ -222,20 +222,20 @@ del_stk(rust_task *task, stk_seg *stk)
unconfig_valgrind_stack(stk); unconfig_valgrind_stack(stk);
if (delete_stack) { if (delete_stack) {
free_stk(task, stk); free_stk(task, stk);
A(task->sched, task->total_stack_sz == 0, "Stack size should be 0"); A(task->thread, task->total_stack_sz == 0, "Stack size should be 0");
} }
} }
// Tasks // Tasks
rust_task::rust_task(rust_scheduler *sched, rust_task_list *state, rust_task::rust_task(rust_task_thread *thread, rust_task_list *state,
rust_task *spawner, const char *name, rust_task *spawner, const char *name,
size_t init_stack_sz) : size_t init_stack_sz) :
ref_count(1), ref_count(1),
stk(NULL), stk(NULL),
runtime_sp(0), runtime_sp(0),
sched(sched), thread(thread),
cache(NULL), cache(NULL),
kernel(sched->kernel), kernel(thread->kernel),
name(name), name(name),
state(state), state(state),
cond(NULL), cond(NULL),
@@ -244,7 +244,7 @@ rust_task::rust_task(rust_scheduler *sched, rust_task_list *state,
list_index(-1), list_index(-1),
next_port_id(0), next_port_id(0),
rendezvous_ptr(0), rendezvous_ptr(0),
local_region(&sched->srv->local_region), local_region(&thread->srv->local_region),
boxed(&local_region), boxed(&local_region),
unwinding(false), unwinding(false),
killed(false), killed(false),
@@ -253,14 +253,14 @@ rust_task::rust_task(rust_scheduler *sched, rust_task_list *state,
cc_counter(0), cc_counter(0),
total_stack_sz(0) total_stack_sz(0)
{ {
LOGPTR(sched, "new task", (uintptr_t)this); LOGPTR(thread, "new task", (uintptr_t)this);
DLOG(sched, task, "sizeof(task) = %d (0x%x)", sizeof *this, sizeof *this); DLOG(thread, task, "sizeof(task) = %d (0x%x)", sizeof *this, sizeof *this);
assert((void*)this == (void*)&user); assert((void*)this == (void*)&user);
user.notify_enabled = 0; user.notify_enabled = 0;
stk = new_stk(sched, this, init_stack_sz); stk = new_stk(thread, this, init_stack_sz);
user.rust_sp = stk->end; user.rust_sp = stk->end;
if (supervisor) { if (supervisor) {
supervisor->ref(); supervisor->ref();
@@ -269,9 +269,9 @@ rust_task::rust_task(rust_scheduler *sched, rust_task_list *state,
rust_task::~rust_task() rust_task::~rust_task()
{ {
I(sched, !sched->lock.lock_held_by_current_thread()); I(thread, !thread->lock.lock_held_by_current_thread());
I(sched, port_table.is_empty()); I(thread, port_table.is_empty());
DLOG(sched, task, "~rust_task %s @0x%" PRIxPTR ", refcnt=%d", DLOG(thread, task, "~rust_task %s @0x%" PRIxPTR ", refcnt=%d",
name, (uintptr_t)this, ref_count); name, (uintptr_t)this, ref_count);
if (supervisor) { if (supervisor) {
@@ -282,7 +282,7 @@ rust_task::~rust_task()
/* FIXME: tighten this up, there are some more /* FIXME: tighten this up, there are some more
assertions that hold at task-lifecycle events. */ assertions that hold at task-lifecycle events. */
I(sched, ref_count == 0); // || I(thread, ref_count == 0); // ||
// (ref_count == 1 && this == sched->root_task)); // (ref_count == 1 && this == sched->root_task));
// Delete all the stacks. There may be more than one if the task failed // Delete all the stacks. There may be more than one if the task failed
@@ -325,7 +325,7 @@ cleanup_task(cleanup_args *args) {
#ifndef __WIN32__ #ifndef __WIN32__
task->conclude_failure(); task->conclude_failure();
#else #else
A(task->sched, false, "Shouldn't happen"); A(task->thread, false, "Shouldn't happen");
#endif #endif
} }
} }
@@ -342,7 +342,7 @@ void task_start_wrapper(spawn_args *a)
// must have void return type, we can safely pass 0. // must have void return type, we can safely pass 0.
a->f(0, a->envptr, a->argptr); a->f(0, a->envptr, a->argptr);
} catch (rust_task *ex) { } catch (rust_task *ex) {
A(task->sched, ex == task, A(task->thread, ex == task,
"Expected this task to be thrown for unwinding"); "Expected this task to be thrown for unwinding");
threw_exception = true; threw_exception = true;
} }
@@ -359,7 +359,7 @@ void task_start_wrapper(spawn_args *a)
// The cleanup work needs lots of stack // The cleanup work needs lots of stack
cleanup_args ca = {a, threw_exception}; cleanup_args ca = {a, threw_exception};
task->sched->c_context.call_shim_on_c_stack(&ca, (void*)cleanup_task); task->thread->c_context.call_shim_on_c_stack(&ca, (void*)cleanup_task);
task->ctx.next->swap(task->ctx); task->ctx.next->swap(task->ctx);
} }
@@ -373,7 +373,7 @@ rust_task::start(spawn_fn spawnee_fn,
" with env 0x%" PRIxPTR " and arg 0x%" PRIxPTR, " with env 0x%" PRIxPTR " and arg 0x%" PRIxPTR,
spawnee_fn, envptr, argptr); spawnee_fn, envptr, argptr);
I(sched, stk->data != NULL); I(thread, stk->data != NULL);
char *sp = (char *)user.rust_sp; char *sp = (char *)user.rust_sp;
@@ -393,7 +393,7 @@ rust_task::start(spawn_fn spawnee_fn,
void rust_task::start() void rust_task::start()
{ {
transition(&sched->newborn_tasks, &sched->running_tasks); transition(&thread->newborn_tasks, &thread->running_tasks);
} }
// Only run this on the rust stack // Only run this on the rust stack
@@ -440,7 +440,7 @@ bool rust_task_is_unwinding(rust_task *rt) {
void void
rust_task::fail() { rust_task::fail() {
// See note in ::kill() regarding who should call this. // See note in ::kill() regarding who should call this.
DLOG(sched, task, "task %s @0x%" PRIxPTR " failing", name, this); DLOG(thread, task, "task %s @0x%" PRIxPTR " failing", name, this);
backtrace(); backtrace();
unwinding = true; unwinding = true;
#ifndef __WIN32__ #ifndef __WIN32__
@@ -449,7 +449,7 @@ rust_task::fail() {
die(); die();
conclude_failure(); conclude_failure();
// FIXME: Need unwinding on windows. This will end up aborting // FIXME: Need unwinding on windows. This will end up aborting
sched->fail(); thread->fail();
#endif #endif
} }
@@ -461,7 +461,7 @@ rust_task::conclude_failure() {
void void
rust_task::fail_parent() { rust_task::fail_parent() {
if (supervisor) { if (supervisor) {
DLOG(sched, task, DLOG(thread, task,
"task %s @0x%" PRIxPTR "task %s @0x%" PRIxPTR
" propagating failure to supervisor %s @0x%" PRIxPTR, " propagating failure to supervisor %s @0x%" PRIxPTR,
name, this, supervisor->name, supervisor); name, this, supervisor->name, supervisor);
@@ -469,14 +469,14 @@ rust_task::fail_parent() {
} }
// FIXME: implement unwinding again. // FIXME: implement unwinding again.
if (NULL == supervisor && propagate_failure) if (NULL == supervisor && propagate_failure)
sched->fail(); thread->fail();
} }
void void
rust_task::unsupervise() rust_task::unsupervise()
{ {
if (supervisor) { if (supervisor) {
DLOG(sched, task, DLOG(thread, task,
"task %s @0x%" PRIxPTR "task %s @0x%" PRIxPTR
" disconnecting from supervisor %s @0x%" PRIxPTR, " disconnecting from supervisor %s @0x%" PRIxPTR,
name, this, supervisor->name, supervisor); name, this, supervisor->name, supervisor);
@@ -495,13 +495,13 @@ rust_task::get_frame_glue_fns(uintptr_t fp) {
bool bool
rust_task::running() rust_task::running()
{ {
return state == &sched->running_tasks; return state == &thread->running_tasks;
} }
bool bool
rust_task::blocked() rust_task::blocked()
{ {
return state == &sched->blocked_tasks; return state == &thread->blocked_tasks;
} }
bool bool
@@ -513,7 +513,7 @@ rust_task::blocked_on(rust_cond *on)
bool bool
rust_task::dead() rust_task::dead()
{ {
return state == &sched->dead_tasks; return state == &thread->dead_tasks;
} }
void * void *
@@ -537,55 +537,55 @@ rust_task::free(void *p)
void void
rust_task::transition(rust_task_list *src, rust_task_list *dst) { rust_task::transition(rust_task_list *src, rust_task_list *dst) {
bool unlock = false; bool unlock = false;
if(!sched->lock.lock_held_by_current_thread()) { if(!thread->lock.lock_held_by_current_thread()) {
unlock = true; unlock = true;
sched->lock.lock(); thread->lock.lock();
} }
DLOG(sched, task, DLOG(thread, task,
"task %s " PTR " state change '%s' -> '%s' while in '%s'", "task %s " PTR " state change '%s' -> '%s' while in '%s'",
name, (uintptr_t)this, src->name, dst->name, state->name); name, (uintptr_t)this, src->name, dst->name, state->name);
I(sched, state == src); I(thread, state == src);
src->remove(this); src->remove(this);
dst->append(this); dst->append(this);
state = dst; state = dst;
sched->lock.signal(); thread->lock.signal();
if(unlock) if(unlock)
sched->lock.unlock(); thread->lock.unlock();
} }
void void
rust_task::block(rust_cond *on, const char* name) { rust_task::block(rust_cond *on, const char* name) {
I(sched, !lock.lock_held_by_current_thread()); I(thread, !lock.lock_held_by_current_thread());
scoped_lock with(lock); scoped_lock with(lock);
LOG(this, task, "Blocking on 0x%" PRIxPTR ", cond: 0x%" PRIxPTR, LOG(this, task, "Blocking on 0x%" PRIxPTR ", cond: 0x%" PRIxPTR,
(uintptr_t) on, (uintptr_t) cond); (uintptr_t) on, (uintptr_t) cond);
A(sched, cond == NULL, "Cannot block an already blocked task."); A(thread, cond == NULL, "Cannot block an already blocked task.");
A(sched, on != NULL, "Cannot block on a NULL object."); A(thread, on != NULL, "Cannot block on a NULL object.");
transition(&sched->running_tasks, &sched->blocked_tasks); transition(&thread->running_tasks, &thread->blocked_tasks);
cond = on; cond = on;
cond_name = name; cond_name = name;
} }
void void
rust_task::wakeup(rust_cond *from) { rust_task::wakeup(rust_cond *from) {
I(sched, !lock.lock_held_by_current_thread()); I(thread, !lock.lock_held_by_current_thread());
scoped_lock with(lock); scoped_lock with(lock);
A(sched, cond != NULL, "Cannot wake up unblocked task."); A(thread, cond != NULL, "Cannot wake up unblocked task.");
LOG(this, task, "Blocked on 0x%" PRIxPTR " woken up on 0x%" PRIxPTR, LOG(this, task, "Blocked on 0x%" PRIxPTR " woken up on 0x%" PRIxPTR,
(uintptr_t) cond, (uintptr_t) from); (uintptr_t) cond, (uintptr_t) from);
A(sched, cond == from, "Cannot wake up blocked task on wrong condition."); A(thread, cond == from, "Cannot wake up blocked task on wrong condition.");
cond = NULL; cond = NULL;
cond_name = "none"; cond_name = "none";
transition(&sched->blocked_tasks, &sched->running_tasks); transition(&thread->blocked_tasks, &thread->running_tasks);
} }
void void
rust_task::die() { rust_task::die() {
I(sched, !lock.lock_held_by_current_thread()); I(thread, !lock.lock_held_by_current_thread());
scoped_lock with(lock); scoped_lock with(lock);
transition(&sched->running_tasks, &sched->dead_tasks); transition(&thread->running_tasks, &thread->dead_tasks);
} }
void void
@@ -601,8 +601,8 @@ rust_crate_cache *
rust_task::get_crate_cache() rust_task::get_crate_cache()
{ {
if (!cache) { if (!cache) {
DLOG(sched, task, "fetching cache for current crate"); DLOG(thread, task, "fetching cache for current crate");
cache = sched->get_cache(); cache = thread->get_cache();
} }
return cache; return cache;
} }
@@ -623,7 +623,7 @@ rust_task::calloc(size_t size, const char *tag) {
} }
rust_port_id rust_task::register_port(rust_port *port) { rust_port_id rust_task::register_port(rust_port *port) {
I(sched, !lock.lock_held_by_current_thread()); I(thread, !lock.lock_held_by_current_thread());
scoped_lock with(lock); scoped_lock with(lock);
rust_port_id id = next_port_id++; rust_port_id id = next_port_id++;
@@ -632,12 +632,12 @@ rust_port_id rust_task::register_port(rust_port *port) {
} }
void rust_task::release_port(rust_port_id id) { void rust_task::release_port(rust_port_id id) {
I(sched, lock.lock_held_by_current_thread()); I(thread, lock.lock_held_by_current_thread());
port_table.remove(id); port_table.remove(id);
} }
rust_port *rust_task::get_port_by_id(rust_port_id id) { rust_port *rust_task::get_port_by_id(rust_port_id id) {
I(sched, !lock.lock_held_by_current_thread()); I(thread, !lock.lock_held_by_current_thread());
scoped_lock with(lock); scoped_lock with(lock);
rust_port *port = NULL; rust_port *port = NULL;
port_table.get(id, &port); port_table.get(id, &port);
@@ -675,8 +675,8 @@ record_sp(void *limit);
void * void *
rust_task::new_stack(size_t stk_sz, void *args_addr, size_t args_sz) { rust_task::new_stack(size_t stk_sz, void *args_addr, size_t args_sz) {
stk_seg *stk_seg = new_stk(sched, this, stk_sz + args_sz); stk_seg *stk_seg = new_stk(thread, this, stk_sz + args_sz);
A(sched, stk_seg->end - (uintptr_t)stk_seg->data >= stk_sz + args_sz, A(thread, stk_seg->end - (uintptr_t)stk_seg->data >= stk_sz + args_sz,
"Did not receive enough stack"); "Did not receive enough stack");
uint8_t *new_sp = (uint8_t*)stk_seg->end; uint8_t *new_sp = (uint8_t*)stk_seg->end;
// Push the function arguments to the new stack // Push the function arguments to the new stack
@@ -700,7 +700,7 @@ rust_task::record_stack_limit() {
// subtracting the frame size. As a result we need our stack limit to // subtracting the frame size. As a result we need our stack limit to
// account for those 256 bytes. // account for those 256 bytes.
const unsigned LIMIT_OFFSET = 256; const unsigned LIMIT_OFFSET = 256;
A(sched, A(thread,
(uintptr_t)stk->end - RED_ZONE_SIZE (uintptr_t)stk->end - RED_ZONE_SIZE
- (uintptr_t)stk->data >= LIMIT_OFFSET, - (uintptr_t)stk->data >= LIMIT_OFFSET,
"Stack size must be greater than LIMIT_OFFSET"); "Stack size must be greater than LIMIT_OFFSET");
@@ -731,7 +731,7 @@ rust_task::reset_stack_limit() {
uintptr_t sp = get_sp(); uintptr_t sp = get_sp();
while (!sp_in_stk_seg(sp, stk)) { while (!sp_in_stk_seg(sp, stk)) {
del_stk(this, stk); del_stk(this, stk);
A(sched, stk != NULL, "Failed to find the current stack"); A(thread, stk != NULL, "Failed to find the current stack");
} }
record_stack_limit(); record_stack_limit();
} }

View File

@@ -76,7 +76,7 @@ rust_task : public kernel_owned<rust_task>, rust_cond
context ctx; context ctx;
stk_seg *stk; stk_seg *stk;
uintptr_t runtime_sp; // Runtime sp while task running. uintptr_t runtime_sp; // Runtime sp while task running.
rust_scheduler *sched; rust_task_thread *thread;
rust_crate_cache *cache; rust_crate_cache *cache;
// Fields known only to the runtime. // Fields known only to the runtime.
@@ -123,7 +123,7 @@ rust_task : public kernel_owned<rust_task>, rust_cond
size_t total_stack_sz; size_t total_stack_sz;
// Only a pointer to 'name' is kept, so it must live as long as this task. // Only a pointer to 'name' is kept, so it must live as long as this task.
rust_task(rust_scheduler *sched, rust_task(rust_task_thread *thread,
rust_task_list *state, rust_task_list *state,
rust_task *spawner, rust_task *spawner,
const char *name, const char *name,

View File

@@ -1,15 +1,15 @@
#include "rust_internal.h" #include "rust_internal.h"
rust_task_list::rust_task_list (rust_scheduler *sched, const char* name) : rust_task_list::rust_task_list (rust_task_thread *thread, const char* name) :
sched(sched), name(name) { thread(thread), name(name) {
} }
void void
rust_task_list::delete_all() { rust_task_list::delete_all() {
DLOG(sched, task, "deleting all %s tasks", name); DLOG(thread, task, "deleting all %s tasks", name);
while (is_empty() == false) { while (is_empty() == false) {
rust_task *task = pop_value(); rust_task *task = pop_value();
DLOG(sched, task, "deleting task " PTR, task); DLOG(thread, task, "deleting task " PTR, task);
delete task; delete task;
} }
} }

View File

@@ -8,9 +8,9 @@
class rust_task_list : public indexed_list<rust_task>, class rust_task_list : public indexed_list<rust_task>,
public kernel_owned<rust_task_list> { public kernel_owned<rust_task_list> {
public: public:
rust_scheduler *sched; rust_task_thread *thread;
const char* name; const char* name;
rust_task_list (rust_scheduler *sched, const char* name); rust_task_list (rust_task_thread *thread, const char* name);
void delete_all(); void delete_all();
}; };

View File

@@ -7,14 +7,14 @@
#include "globals.h" #include "globals.h"
#ifndef _WIN32 #ifndef _WIN32
pthread_key_t rust_scheduler::task_key; pthread_key_t rust_task_thread::task_key;
#else #else
DWORD rust_scheduler::task_key; DWORD rust_task_thread::task_key;
#endif #endif
bool rust_scheduler::tls_initialized = false; bool rust_task_thread::tls_initialized = false;
rust_scheduler::rust_scheduler(rust_kernel *kernel, rust_task_thread::rust_task_thread(rust_kernel *kernel,
rust_srv *srv, rust_srv *srv,
int id) : int id) :
ref_count(1), ref_count(1),
@@ -46,8 +46,8 @@ rust_scheduler::rust_scheduler(rust_kernel *kernel,
init_tls(); init_tls();
} }
rust_scheduler::~rust_scheduler() { rust_task_thread::~rust_task_thread() {
DLOG(this, dom, "~rust_scheduler %s @0x%" PRIxPTR, name, (uintptr_t)this); DLOG(this, dom, "~rust_task_thread %s @0x%" PRIxPTR, name, (uintptr_t)this);
newborn_tasks.delete_all(); newborn_tasks.delete_all();
running_tasks.delete_all(); running_tasks.delete_all();
@@ -59,7 +59,7 @@ rust_scheduler::~rust_scheduler() {
} }
void void
rust_scheduler::activate(rust_task *task) { rust_task_thread::activate(rust_task *task) {
task->ctx.next = &c_context; task->ctx.next = &c_context;
DLOG(this, task, "descheduling..."); DLOG(this, task, "descheduling...");
lock.unlock(); lock.unlock();
@@ -69,7 +69,7 @@ rust_scheduler::activate(rust_task *task) {
} }
void void
rust_scheduler::log(rust_task* task, uint32_t level, char const *fmt, ...) { rust_task_thread::log(rust_task* task, uint32_t level, char const *fmt, ...) {
char buf[BUF_BYTES]; char buf[BUF_BYTES];
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
@@ -79,14 +79,14 @@ rust_scheduler::log(rust_task* task, uint32_t level, char const *fmt, ...) {
} }
void void
rust_scheduler::fail() { rust_task_thread::fail() {
log(NULL, log_err, "domain %s @0x%" PRIxPTR " root task failed", log(NULL, log_err, "domain %s @0x%" PRIxPTR " root task failed",
name, this); name, this);
kernel->fail(); kernel->fail();
} }
void void
rust_scheduler::kill_all_tasks() { rust_task_thread::kill_all_tasks() {
I(this, !lock.lock_held_by_current_thread()); I(this, !lock.lock_held_by_current_thread());
scoped_lock with(lock); scoped_lock with(lock);
@@ -104,7 +104,7 @@ rust_scheduler::kill_all_tasks() {
} }
size_t size_t
rust_scheduler::number_of_live_tasks() { rust_task_thread::number_of_live_tasks() {
return running_tasks.length() + blocked_tasks.length(); return running_tasks.length() + blocked_tasks.length();
} }
@@ -112,7 +112,7 @@ rust_scheduler::number_of_live_tasks() {
* Delete any dead tasks. * Delete any dead tasks.
*/ */
void void
rust_scheduler::reap_dead_tasks() { rust_task_thread::reap_dead_tasks() {
I(this, lock.lock_held_by_current_thread()); I(this, lock.lock_held_by_current_thread());
if (dead_tasks.length() == 0) { if (dead_tasks.length() == 0) {
return; return;
@@ -157,7 +157,7 @@ rust_scheduler::reap_dead_tasks() {
* Returns NULL if no tasks can be scheduled. * Returns NULL if no tasks can be scheduled.
*/ */
rust_task * rust_task *
rust_scheduler::schedule_task() { rust_task_thread::schedule_task() {
I(this, this); I(this, this);
// FIXME: in the face of failing tasks, this is not always right. // FIXME: in the face of failing tasks, this is not always right.
// I(this, n_live_tasks() > 0); // I(this, n_live_tasks() > 0);
@@ -173,7 +173,7 @@ rust_scheduler::schedule_task() {
} }
void void
rust_scheduler::log_state() { rust_task_thread::log_state() {
if (log_rt_task < log_debug) return; if (log_rt_task < log_debug) return;
if (!running_tasks.is_empty()) { if (!running_tasks.is_empty()) {
@@ -211,7 +211,7 @@ rust_scheduler::log_state() {
* drop to zero. * drop to zero.
*/ */
void void
rust_scheduler::start_main_loop() { rust_task_thread::start_main_loop() {
lock.lock(); lock.lock();
DLOG(this, dom, "started domain loop %d", id); DLOG(this, dom, "started domain loop %d", id);
@@ -277,12 +277,12 @@ rust_scheduler::start_main_loop() {
} }
rust_crate_cache * rust_crate_cache *
rust_scheduler::get_cache() { rust_task_thread::get_cache() {
return &cache; return &cache;
} }
rust_task * rust_task *
rust_scheduler::create_task(rust_task *spawner, const char *name, rust_task_thread::create_task(rust_task *spawner, const char *name,
size_t init_stack_sz) { size_t init_stack_sz) {
rust_task *task = rust_task *task =
new (this->kernel, "rust_task") new (this->kernel, "rust_task")
@@ -300,27 +300,27 @@ rust_scheduler::create_task(rust_task *spawner, const char *name,
return task; return task;
} }
void rust_scheduler::run() { void rust_task_thread::run() {
this->start_main_loop(); this->start_main_loop();
} }
#ifndef _WIN32 #ifndef _WIN32
void void
rust_scheduler::init_tls() { rust_task_thread::init_tls() {
int result = pthread_key_create(&task_key, NULL); int result = pthread_key_create(&task_key, NULL);
assert(!result && "Couldn't create the TLS key!"); assert(!result && "Couldn't create the TLS key!");
tls_initialized = true; tls_initialized = true;
} }
void void
rust_scheduler::place_task_in_tls(rust_task *task) { rust_task_thread::place_task_in_tls(rust_task *task) {
int result = pthread_setspecific(task_key, task); int result = pthread_setspecific(task_key, task);
assert(!result && "Couldn't place the task in TLS!"); assert(!result && "Couldn't place the task in TLS!");
task->record_stack_limit(); task->record_stack_limit();
} }
rust_task * rust_task *
rust_scheduler::get_task() { rust_task_thread::get_task() {
if (!tls_initialized) if (!tls_initialized)
return NULL; return NULL;
rust_task *task = reinterpret_cast<rust_task *> rust_task *task = reinterpret_cast<rust_task *>
@@ -330,21 +330,21 @@ rust_scheduler::get_task() {
} }
#else #else
void void
rust_scheduler::init_tls() { rust_task_thread::init_tls() {
task_key = TlsAlloc(); task_key = TlsAlloc();
assert(task_key != TLS_OUT_OF_INDEXES && "Couldn't create the TLS key!"); assert(task_key != TLS_OUT_OF_INDEXES && "Couldn't create the TLS key!");
tls_initialized = true; tls_initialized = true;
} }
void void
rust_scheduler::place_task_in_tls(rust_task *task) { rust_task_thread::place_task_in_tls(rust_task *task) {
BOOL result = TlsSetValue(task_key, task); BOOL result = TlsSetValue(task_key, task);
assert(result && "Couldn't place the task in TLS!"); assert(result && "Couldn't place the task in TLS!");
task->record_stack_limit(); task->record_stack_limit();
} }
rust_task * rust_task *
rust_scheduler::get_task() { rust_task_thread::get_task() {
if (!tls_initialized) if (!tls_initialized)
return NULL; return NULL;
rust_task *task = reinterpret_cast<rust_task *>(TlsGetValue(task_key)); rust_task *task = reinterpret_cast<rust_task *>(TlsGetValue(task_key));
@@ -354,7 +354,7 @@ rust_scheduler::get_task() {
#endif #endif
void void
rust_scheduler::exit() { rust_task_thread::exit() {
A(this, !lock.lock_held_by_current_thread(), "Shouldn't have lock"); A(this, !lock.lock_held_by_current_thread(), "Shouldn't have lock");
scoped_lock with(lock); scoped_lock with(lock);
should_exit = true; should_exit = true;

View File

@@ -1,5 +1,5 @@
#ifndef RUST_SCHEDULER_H #ifndef RUST_TASK_THREAD_H
#define RUST_SCHEDULER_H #define RUST_TASK_THREAD_H
#include "context.h" #include "context.h"
@@ -9,7 +9,7 @@
#include <windows.h> #include <windows.h>
#endif #endif
struct rust_scheduler; struct rust_task_thread;
struct rust_hashable_dict { struct rust_hashable_dict {
UT_hash_handle hh; UT_hash_handle hh;
@@ -32,18 +32,18 @@ private:
public: public:
rust_scheduler *sched; rust_task_thread *thread;
size_t idx; size_t idx;
rust_crate_cache(rust_scheduler *sched); rust_crate_cache(rust_task_thread *thread);
~rust_crate_cache(); ~rust_crate_cache();
void flush(); void flush();
}; };
struct rust_scheduler : public kernel_owned<rust_scheduler>, struct rust_task_thread : public kernel_owned<rust_task_thread>,
rust_thread rust_thread
{ {
RUST_REFCOUNTED(rust_scheduler) RUST_REFCOUNTED(rust_task_thread)
// Fields known only by the runtime: // Fields known only by the runtime:
rust_log _log; rust_log _log;
@@ -92,8 +92,8 @@ struct rust_scheduler : public kernel_owned<rust_scheduler>,
// Only a pointer to 'name' is kept, so it must live as long as this // Only a pointer to 'name' is kept, so it must live as long as this
// domain. // domain.
rust_scheduler(rust_kernel *kernel, rust_srv *srv, int id); rust_task_thread(rust_kernel *kernel, rust_srv *srv, int id);
~rust_scheduler(); ~rust_task_thread();
void activate(rust_task *task); void activate(rust_task *task);
void log(rust_task *task, uint32_t level, char const *fmt, ...); void log(rust_task *task, uint32_t level, char const *fmt, ...);
rust_log & get_log(); rust_log & get_log();
@@ -132,7 +132,7 @@ struct rust_scheduler : public kernel_owned<rust_scheduler>,
}; };
inline rust_log & inline rust_log &
rust_scheduler::get_log() { rust_task_thread::get_log() {
return _log; return _log;
} }
@@ -147,4 +147,4 @@ rust_scheduler::get_log() {
// End: // End:
// //
#endif /* RUST_SCHEDULER_H */ #endif /* RUST_TASK_THREAD_H */

View File

@@ -8,7 +8,7 @@
#include "rust_cc.h" #include "rust_cc.h"
#include "rust_internal.h" #include "rust_internal.h"
#include "rust_scheduler.h" #include "rust_task_thread.h"
#include "rust_unwind.h" #include "rust_unwind.h"
#include "rust_upcall.h" #include "rust_upcall.h"
#include "rust_util.h" #include "rust_util.h"
@@ -46,9 +46,9 @@ static void check_stack_alignment() { }
inline void inline void
call_upcall_on_c_stack(void *args, void *fn_ptr) { call_upcall_on_c_stack(void *args, void *fn_ptr) {
check_stack_alignment(); check_stack_alignment();
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
rust_scheduler *sched = task->sched; rust_task_thread *thread = task->thread;
sched->c_context.call_shim_on_c_stack(args, fn_ptr); thread->c_context.call_shim_on_c_stack(args, fn_ptr);
} }
extern "C" void record_sp(void *limit); extern "C" void record_sp(void *limit);
@@ -62,21 +62,21 @@ extern "C" void record_sp(void *limit);
*/ */
extern "C" CDECL void extern "C" CDECL void
upcall_call_shim_on_c_stack(void *args, void *fn_ptr) { upcall_call_shim_on_c_stack(void *args, void *fn_ptr) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
// FIXME (1226) - The shim functions generated by rustc contain the // FIXME (1226) - The shim functions generated by rustc contain the
// morestack prologue, so we need to let them know they have enough // morestack prologue, so we need to let them know they have enough
// stack. // stack.
record_sp(0); record_sp(0);
rust_scheduler *sched = task->sched; rust_task_thread *thread = task->thread;
try { try {
sched->c_context.call_shim_on_c_stack(args, fn_ptr); thread->c_context.call_shim_on_c_stack(args, fn_ptr);
} catch (...) { } catch (...) {
A(sched, false, "Native code threw an exception"); A(thread, false, "Native code threw an exception");
} }
task = rust_scheduler::get_task(); task = rust_task_thread::get_task();
task->record_stack_limit(); task->record_stack_limit();
} }
@@ -90,7 +90,7 @@ struct s_fail_args {
extern "C" CDECL void extern "C" CDECL void
upcall_s_fail(s_fail_args *args) { upcall_s_fail(s_fail_args *args) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG_ERR(task, upcall, "upcall fail '%s', %s:%" PRIdPTR, LOG_ERR(task, upcall, "upcall fail '%s', %s:%" PRIdPTR,
args->expr, args->file, args->line); args->expr, args->file, args->line);
@@ -116,7 +116,7 @@ struct s_malloc_args {
extern "C" CDECL void extern "C" CDECL void
upcall_s_malloc(s_malloc_args *args) { upcall_s_malloc(s_malloc_args *args) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, mem, "upcall malloc(0x%" PRIxPTR ")", args->td); LOG(task, mem, "upcall malloc(0x%" PRIxPTR ")", args->td);
@@ -153,11 +153,11 @@ struct s_free_args {
extern "C" CDECL void extern "C" CDECL void
upcall_s_free(s_free_args *args) { upcall_s_free(s_free_args *args) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
rust_scheduler *sched = task->sched; rust_task_thread *thread = task->thread;
DLOG(sched, mem, DLOG(thread, mem,
"upcall free(0x%" PRIxPTR ", is_gc=%" PRIdPTR ")", "upcall free(0x%" PRIxPTR ", is_gc=%" PRIdPTR ")",
(uintptr_t)args->ptr); (uintptr_t)args->ptr);
@@ -200,7 +200,7 @@ struct s_shared_malloc_args {
extern "C" CDECL void extern "C" CDECL void
upcall_s_shared_malloc(s_shared_malloc_args *args) { upcall_s_shared_malloc(s_shared_malloc_args *args) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, mem, LOG(task, mem,
@@ -232,11 +232,11 @@ struct s_shared_free_args {
extern "C" CDECL void extern "C" CDECL void
upcall_s_shared_free(s_shared_free_args *args) { upcall_s_shared_free(s_shared_free_args *args) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
rust_scheduler *sched = task->sched; rust_task_thread *thread = task->thread;
DLOG(sched, mem, DLOG(thread, mem,
"upcall shared_free(0x%" PRIxPTR")", "upcall shared_free(0x%" PRIxPTR")",
(uintptr_t)args->ptr); (uintptr_t)args->ptr);
task->kernel->free(args->ptr); task->kernel->free(args->ptr);
@@ -262,7 +262,7 @@ struct s_create_shared_type_desc_args {
void upcall_s_create_shared_type_desc(s_create_shared_type_desc_args *args) void upcall_s_create_shared_type_desc(s_create_shared_type_desc_args *args)
{ {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
// Copy the main part of the type descriptor: // Copy the main part of the type descriptor:
@@ -301,7 +301,7 @@ upcall_create_shared_type_desc(type_desc *td) {
void upcall_s_free_shared_type_desc(type_desc *td) void upcall_s_free_shared_type_desc(type_desc *td)
{ // n.b.: invoked from rust_cc.cpp as well as generated code { // n.b.: invoked from rust_cc.cpp as well as generated code
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
if (td) { if (td) {
@@ -337,7 +337,7 @@ struct s_get_type_desc_args {
extern "C" CDECL void extern "C" CDECL void
upcall_s_get_type_desc(s_get_type_desc_args *args) { upcall_s_get_type_desc(s_get_type_desc_args *args) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
LOG(task, cache, "upcall get_type_desc with size=%" PRIdPTR LOG(task, cache, "upcall get_type_desc with size=%" PRIdPTR
@@ -375,7 +375,7 @@ struct s_intern_dict_args {
extern "C" CDECL void extern "C" CDECL void
upcall_s_intern_dict(s_intern_dict_args *args) { upcall_s_intern_dict(s_intern_dict_args *args) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
rust_crate_cache *cache = task->get_crate_cache(); rust_crate_cache *cache = task->get_crate_cache();
args->res = cache->get_dict(args->n_fields, args->dict); args->res = cache->get_dict(args->n_fields, args->dict);
@@ -397,7 +397,7 @@ struct s_vec_grow_args {
extern "C" CDECL void extern "C" CDECL void
upcall_s_vec_grow(s_vec_grow_args *args) { upcall_s_vec_grow(s_vec_grow_args *args) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
reserve_vec(task, args->vp, args->new_sz); reserve_vec(task, args->vp, args->new_sz);
(*args->vp)->fill = args->new_sz; (*args->vp)->fill = args->new_sz;
@@ -438,7 +438,7 @@ struct s_vec_push_args {
extern "C" CDECL void extern "C" CDECL void
upcall_s_vec_push(s_vec_push_args *args) { upcall_s_vec_push(s_vec_push_args *args) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
LOG_UPCALL_ENTRY(task); LOG_UPCALL_ENTRY(task);
size_t new_sz = (*args->vp)->fill + args->elt_ty->size; size_t new_sz = (*args->vp)->fill + args->elt_ty->size;
reserve_vec(task, args->vp, new_sz); reserve_vec(task, args->vp, new_sz);
@@ -456,7 +456,7 @@ upcall_vec_push(rust_vec** vp, type_desc* elt_ty, void* elt) {
upcall_s_vec_push(&args); upcall_s_vec_push(&args);
// Do the stack check to make sure this op, on the Rust stack, is behaving // Do the stack check to make sure this op, on the Rust stack, is behaving
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
task->check_stack_canary(); task->check_stack_canary();
} }
@@ -471,7 +471,7 @@ struct s_dynastack_mark_args {
extern "C" CDECL void extern "C" CDECL void
upcall_s_dynastack_mark(s_dynastack_mark_args *args) { upcall_s_dynastack_mark(s_dynastack_mark_args *args) {
args->retval = rust_scheduler::get_task()->dynastack.mark(); args->retval = rust_task_thread::get_task()->dynastack.mark();
} }
extern "C" CDECL void * extern "C" CDECL void *
@@ -496,7 +496,7 @@ extern "C" CDECL void
upcall_s_dynastack_alloc(s_dynastack_alloc_args *args) { upcall_s_dynastack_alloc(s_dynastack_alloc_args *args) {
size_t sz = args->sz; size_t sz = args->sz;
args->retval = sz ? args->retval = sz ?
rust_scheduler::get_task()->dynastack.alloc(sz, NULL) : NULL; rust_task_thread::get_task()->dynastack.alloc(sz, NULL) : NULL;
} }
extern "C" CDECL void * extern "C" CDECL void *
@@ -522,7 +522,7 @@ upcall_s_dynastack_alloc_2(s_dynastack_alloc_2_args *args) {
size_t sz = args->sz; size_t sz = args->sz;
type_desc *ty = args->ty; type_desc *ty = args->ty;
args->retval = sz ? args->retval = sz ?
rust_scheduler::get_task()->dynastack.alloc(sz, ty) : NULL; rust_task_thread::get_task()->dynastack.alloc(sz, ty) : NULL;
} }
extern "C" CDECL void * extern "C" CDECL void *
@@ -538,7 +538,7 @@ struct s_dynastack_free_args {
extern "C" CDECL void extern "C" CDECL void
upcall_s_dynastack_free(s_dynastack_free_args *args) { upcall_s_dynastack_free(s_dynastack_free_args *args) {
return rust_scheduler::get_task()->dynastack.free(args->ptr); return rust_task_thread::get_task()->dynastack.free(args->ptr);
} }
/** Frees space in the dynamic stack. */ /** Frees space in the dynamic stack. */
@@ -587,7 +587,7 @@ upcall_rust_personality(int version,
s_rust_personality_args args = {(_Unwind_Reason_Code)0, s_rust_personality_args args = {(_Unwind_Reason_Code)0,
version, actions, exception_class, version, actions, exception_class,
ue_header, context}; ue_header, context};
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
// The personality function is run on the stack of the // The personality function is run on the stack of the
// last function that threw or landed, which is going // last function that threw or landed, which is going
@@ -659,7 +659,7 @@ struct s_new_stack_args {
extern "C" CDECL void extern "C" CDECL void
upcall_s_new_stack(struct s_new_stack_args *args) { upcall_s_new_stack(struct s_new_stack_args *args) {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
args->result = task->new_stack(args->stk_sz, args->result = task->new_stack(args->stk_sz,
args->args_addr, args->args_addr,
args->args_sz); args->args_sz);
@@ -674,7 +674,7 @@ upcall_new_stack(size_t stk_sz, void *args_addr, size_t args_sz) {
extern "C" CDECL void extern "C" CDECL void
upcall_s_del_stack() { upcall_s_del_stack() {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
task->del_stack(); task->del_stack();
} }
@@ -689,7 +689,7 @@ upcall_del_stack() {
// needs to acquire the value of the stack pointer // needs to acquire the value of the stack pointer
extern "C" CDECL void extern "C" CDECL void
upcall_reset_stack_limit() { upcall_reset_stack_limit() {
rust_task *task = rust_scheduler::get_task(); rust_task *task = rust_task_thread::get_task();
task->reset_stack_limit(); task->reset_stack_limit();
} }

View File

@@ -13,24 +13,24 @@ ptr_vec<T>::ptr_vec(rust_task *task) :
fill(0), fill(0),
data(new (task, "ptr_vec<T>") T*[alloc]) data(new (task, "ptr_vec<T>") T*[alloc])
{ {
I(task->sched, data); I(task->thread, data);
DLOG(task->sched, mem, "new ptr_vec(data=0x%" PRIxPTR ") -> 0x%" PRIxPTR, DLOG(task->thread, mem, "new ptr_vec(data=0x%" PRIxPTR ") -> 0x%" PRIxPTR,
(uintptr_t)data, (uintptr_t)this); (uintptr_t)data, (uintptr_t)this);
} }
template <typename T> template <typename T>
ptr_vec<T>::~ptr_vec() ptr_vec<T>::~ptr_vec()
{ {
I(task->sched, data); I(task->thread, data);
DLOG(task->sched, mem, "~ptr_vec 0x%" PRIxPTR ", data=0x%" PRIxPTR, DLOG(task->thread, mem, "~ptr_vec 0x%" PRIxPTR ", data=0x%" PRIxPTR,
(uintptr_t)this, (uintptr_t)data); (uintptr_t)this, (uintptr_t)data);
I(task->sched, fill == 0); I(task->thread, fill == 0);
task->free(data); task->free(data);
} }
template <typename T> T *& template <typename T> T *&
ptr_vec<T>::operator[](size_t offset) { ptr_vec<T>::operator[](size_t offset) {
I(task->sched, data[offset]->idx == offset); I(task->thread, data[offset]->idx == offset);
return data[offset]; return data[offset];
} }
@@ -38,14 +38,14 @@ template <typename T>
void void
ptr_vec<T>::push(T *p) ptr_vec<T>::push(T *p)
{ {
I(task->sched, data); I(task->thread, data);
I(task->sched, fill <= alloc); I(task->thread, fill <= alloc);
if (fill == alloc) { if (fill == alloc) {
alloc *= 2; alloc *= 2;
data = (T **)task->realloc(data, alloc * sizeof(T*)); data = (T **)task->realloc(data, alloc * sizeof(T*));
I(task->sched, data); I(task->thread, data);
} }
I(task->sched, fill < alloc); I(task->thread, fill < alloc);
p->idx = fill; p->idx = fill;
data[fill++] = p; data[fill++] = p;
} }
@@ -68,13 +68,13 @@ template <typename T>
void void
ptr_vec<T>::trim(size_t sz) ptr_vec<T>::trim(size_t sz)
{ {
I(task->sched, data); I(task->thread, data);
if (sz <= (alloc / 4) && if (sz <= (alloc / 4) &&
(alloc / 2) >= INIT_SIZE) { (alloc / 2) >= INIT_SIZE) {
alloc /= 2; alloc /= 2;
I(task->sched, alloc >= fill); I(task->thread, alloc >= fill);
data = (T **)task->realloc(data, alloc * sizeof(T*)); data = (T **)task->realloc(data, alloc * sizeof(T*));
I(task->sched, data); I(task->thread, data);
} }
} }
@@ -83,9 +83,9 @@ void
ptr_vec<T>::swap_delete(T *item) ptr_vec<T>::swap_delete(T *item)
{ {
/* Swap the endpoint into i and decr fill. */ /* Swap the endpoint into i and decr fill. */
I(task->sched, data); I(task->thread, data);
I(task->sched, fill > 0); I(task->thread, fill > 0);
I(task->sched, item->idx < fill); I(task->thread, item->idx < fill);
fill--; fill--;
if (fill > 0) { if (fill > 0) {
T *subst = data[fill]; T *subst = data[fill];
@@ -124,13 +124,13 @@ align_to(T size, size_t alignment) {
// Initialization helper for ISAAC RNG // Initialization helper for ISAAC RNG
template <typename sched_or_kernel> template <typename thread_or_kernel>
static inline void static inline void
isaac_init(sched_or_kernel *sched, randctx *rctx) isaac_init(thread_or_kernel *thread, randctx *rctx)
{ {
memset(rctx, 0, sizeof(randctx)); memset(rctx, 0, sizeof(randctx));
char *rust_seed = sched->env->rust_seed; char *rust_seed = thread->env->rust_seed;
if (rust_seed != NULL) { if (rust_seed != NULL) {
ub4 seed = (ub4) atoi(rust_seed); ub4 seed = (ub4) atoi(rust_seed);
for (size_t i = 0; i < RANDSIZ; i ++) { for (size_t i = 0; i < RANDSIZ; i ++) {
@@ -140,24 +140,24 @@ isaac_init(sched_or_kernel *sched, randctx *rctx)
} else { } else {
#ifdef __WIN32__ #ifdef __WIN32__
HCRYPTPROV hProv; HCRYPTPROV hProv;
sched->win32_require thread->win32_require
(_T("CryptAcquireContext"), (_T("CryptAcquireContext"),
CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT|CRYPT_SILENT)); CRYPT_VERIFYCONTEXT|CRYPT_SILENT));
sched->win32_require thread->win32_require
(_T("CryptGenRandom"), (_T("CryptGenRandom"),
CryptGenRandom(hProv, sizeof(rctx->randrsl), CryptGenRandom(hProv, sizeof(rctx->randrsl),
(BYTE*)(&rctx->randrsl))); (BYTE*)(&rctx->randrsl)));
sched->win32_require thread->win32_require
(_T("CryptReleaseContext"), (_T("CryptReleaseContext"),
CryptReleaseContext(hProv, 0)); CryptReleaseContext(hProv, 0));
#else #else
int fd = open("/dev/urandom", O_RDONLY); int fd = open("/dev/urandom", O_RDONLY);
I(sched, fd > 0); I(thread, fd > 0);
I(sched, I(thread,
read(fd, (void*) &rctx->randrsl, sizeof(rctx->randrsl)) read(fd, (void*) &rctx->randrsl, sizeof(rctx->randrsl))
== sizeof(rctx->randrsl)); == sizeof(rctx->randrsl));
I(sched, close(fd) == 0); I(thread, close(fd) == 0);
#endif #endif
} }

View File

@@ -87,7 +87,7 @@ private:
public: public:
rust_uvtmp_thread() { rust_uvtmp_thread() {
task = rust_scheduler::get_task(); task = rust_task_thread::get_task();
stop_flag = false; stop_flag = false;
loop = uv_loop_new(); loop = uv_loop_new();
uv_idle_init(loop, &idle); uv_idle_init(loop, &idle);