diff options
Diffstat (limited to 'src/rt/rust_kernel.cpp')
| -rw-r--r-- | src/rt/rust_kernel.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/rt/rust_kernel.cpp b/src/rt/rust_kernel.cpp index f8e7e41971e..004e42a8138 100644 --- a/src/rt/rust_kernel.cpp +++ b/src/rt/rust_kernel.cpp @@ -18,6 +18,11 @@ rust_kernel::rust_kernel(rust_srv *srv, size_t num_threads) : { sched = new (this, "rust_scheduler") rust_scheduler(this, srv, num_threads); + live_schedulers = 1; +} + +rust_kernel::~rust_kernel() { + delete sched; } void @@ -41,10 +46,6 @@ rust_kernel::fatal(char const *fmt, ...) { va_end(args); } -rust_kernel::~rust_kernel() { - delete sched; -} - void * rust_kernel::malloc(size_t size, const char *tag) { return _region.malloc(size, tag); @@ -61,8 +62,16 @@ void rust_kernel::free(void *mem) { int rust_kernel::start_schedulers() { + I(this, !sched_lock.lock_held_by_current_thread()); sched->start_task_threads(); - return rval; + { + scoped_lock with(sched_lock); + // Schedulers could possibly have already exited + if (live_schedulers != 0) { + sched_lock.wait(); + } + return rval; + } } rust_scheduler * @@ -71,6 +80,17 @@ rust_kernel::get_default_scheduler() { } void +rust_kernel::release_scheduler() { + I(this, !sched_lock.lock_held_by_current_thread()); + scoped_lock with(sched_lock); + --live_schedulers; + if (live_schedulers == 0) { + // We're all done. Tell the main thread to continue + sched_lock.signal(); + } +} + +void rust_kernel::fail() { // FIXME: On windows we're getting "Application has requested the // Runtime to terminate it in an unusual way" when trying to shutdown |
