diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-02-04 23:42:27 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-02-08 15:33:40 -0800 |
| commit | c76b81cddf7cd7b4aaebbe64bbf8c6565e3ce682 (patch) | |
| tree | 1d2635bcf60d3b6ce6025079503ca463dbb18295 /src/rt | |
| parent | f39e64d56ab4929be5985d4a64020d2223706d96 (diff) | |
| download | rust-c76b81cddf7cd7b4aaebbe64bbf8c6565e3ce682.tar.gz rust-c76b81cddf7cd7b4aaebbe64bbf8c6565e3ce682.zip | |
rt: Delete schedulers immediately upon release
This will be needed once we support dynamically changing schedulers.
Diffstat (limited to 'src/rt')
| -rw-r--r-- | src/rt/rust_kernel.cpp | 5 | ||||
| -rw-r--r-- | src/rt/rust_kernel.h | 1 | ||||
| -rw-r--r-- | src/rt/rust_scheduler.cpp | 5 |
3 files changed, 6 insertions, 5 deletions
diff --git a/src/rt/rust_kernel.cpp b/src/rt/rust_kernel.cpp index 004e42a8138..8f41182d791 100644 --- a/src/rt/rust_kernel.cpp +++ b/src/rt/rust_kernel.cpp @@ -21,10 +21,6 @@ rust_kernel::rust_kernel(rust_srv *srv, size_t num_threads) : live_schedulers = 1; } -rust_kernel::~rust_kernel() { - delete sched; -} - void rust_kernel::log(uint32_t level, char const *fmt, ...) { char buf[BUF_BYTES]; @@ -83,6 +79,7 @@ void rust_kernel::release_scheduler() { I(this, !sched_lock.lock_held_by_current_thread()); scoped_lock with(sched_lock); + delete sched; --live_schedulers; if (live_schedulers == 0) { // We're all done. Tell the main thread to continue diff --git a/src/rt/rust_kernel.h b/src/rt/rust_kernel.h index 9a59a35e908..fdf9f5eb0f7 100644 --- a/src/rt/rust_kernel.h +++ b/src/rt/rust_kernel.h @@ -47,7 +47,6 @@ public: struct rust_env *env; rust_kernel(rust_srv *srv, size_t num_threads); - ~rust_kernel(); void log(uint32_t level, char const *fmt, ...); void fatal(char const *fmt, ...); diff --git a/src/rt/rust_scheduler.cpp b/src/rt/rust_scheduler.cpp index 904eb5cafcb..666733a4318 100644 --- a/src/rt/rust_scheduler.cpp +++ b/src/rt/rust_scheduler.cpp @@ -56,6 +56,11 @@ rust_scheduler::destroy_task_threads() { void rust_scheduler::start_task_threads() { + // Copy num_threads because it's possible for the last thread + // to terminate and have the kernel delete us before we + // hit the last check against num_threads, in which case + // we would be accessing invalid memory. + uintptr_t num_threads = this->num_threads; for(size_t i = 0; i < num_threads; ++i) { rust_task_thread *thread = threads[i]; thread->start(); |
