2010-06-23 23:03:09 -05:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
2011-09-27 19:14:18 -05:00
|
|
|
#include <cassert>
|
2011-11-14 15:52:35 -06:00
|
|
|
#include <pthread.h>
|
2010-06-23 23:03:09 -05:00
|
|
|
#include "rust_internal.h"
|
2012-01-06 14:06:35 -06:00
|
|
|
#include "rust_util.h"
|
2011-05-31 19:44:54 -05:00
|
|
|
#include "globals.h"
|
2012-02-03 17:12:18 -06:00
|
|
|
#include "rust_scheduler.h"
|
2010-06-23 23:03:09 -05:00
|
|
|
|
2011-09-27 19:14:18 -05:00
|
|
|
#ifndef _WIN32
|
2012-02-03 14:47:01 -06:00
|
|
|
pthread_key_t rust_task_thread::task_key;
|
2011-09-27 19:14:18 -05:00
|
|
|
#else
|
2012-02-03 14:47:01 -06:00
|
|
|
DWORD rust_task_thread::task_key;
|
2011-09-27 19:14:18 -05:00
|
|
|
#endif
|
|
|
|
|
2012-02-03 14:47:01 -06:00
|
|
|
bool rust_task_thread::tls_initialized = false;
|
2011-09-27 19:14:18 -05:00
|
|
|
|
2012-02-03 17:12:18 -06:00
|
|
|
rust_task_thread::rust_task_thread(rust_scheduler *sched,
|
|
|
|
rust_srv *srv,
|
|
|
|
int id) :
|
2011-08-18 17:49:58 -05:00
|
|
|
ref_count(1),
|
2010-06-23 23:03:09 -05:00
|
|
|
_log(srv, this),
|
2011-12-28 13:53:12 -06:00
|
|
|
log_lvl(log_debug),
|
2010-06-23 23:03:09 -05:00
|
|
|
srv(srv),
|
2011-07-23 21:03:02 -05:00
|
|
|
// TODO: calculate a per scheduler name.
|
|
|
|
name("main"),
|
2010-09-10 03:21:29 -05:00
|
|
|
newborn_tasks(this, "newborn"),
|
|
|
|
running_tasks(this, "running"),
|
|
|
|
blocked_tasks(this, "blocked"),
|
|
|
|
dead_tasks(this, "dead"),
|
2011-05-26 20:20:48 -05:00
|
|
|
cache(this),
|
2012-02-03 17:12:18 -06:00
|
|
|
kernel(sched->kernel),
|
|
|
|
sched(sched),
|
2011-07-27 16:34:39 -05:00
|
|
|
id(id),
|
|
|
|
min_stack_size(kernel->env->min_stack_size),
|
2012-02-02 19:02:50 -06:00
|
|
|
env(kernel->env),
|
|
|
|
should_exit(false)
|
2010-06-23 23:03:09 -05:00
|
|
|
{
|
2011-04-07 15:05:45 -05:00
|
|
|
LOGPTR(this, "new dom", (uintptr_t)this);
|
2012-02-03 20:42:12 -06:00
|
|
|
isaac_init(kernel, &rctx);
|
2010-07-25 23:45:09 -05:00
|
|
|
#ifndef __WIN32__
|
2010-06-23 23:03:09 -05:00
|
|
|
pthread_attr_init(&attr);
|
|
|
|
pthread_attr_setstacksize(&attr, 1024 * 1024);
|
|
|
|
pthread_attr_setdetachstate(&attr, true);
|
|
|
|
#endif
|
2011-09-27 19:14:18 -05:00
|
|
|
|
|
|
|
if (!tls_initialized)
|
|
|
|
init_tls();
|
2010-06-23 23:03:09 -05:00
|
|
|
}
|
|
|
|
|
2012-02-03 14:47:01 -06:00
|
|
|
rust_task_thread::~rust_task_thread() {
|
|
|
|
DLOG(this, dom, "~rust_task_thread %s @0x%" PRIxPTR, name, (uintptr_t)this);
|
2011-06-27 21:15:03 -05:00
|
|
|
|
2010-09-10 03:21:29 -05:00
|
|
|
newborn_tasks.delete_all();
|
|
|
|
running_tasks.delete_all();
|
|
|
|
blocked_tasks.delete_all();
|
|
|
|
dead_tasks.delete_all();
|
2010-06-23 23:03:09 -05:00
|
|
|
#ifndef __WIN32__
|
|
|
|
pthread_attr_destroy(&attr);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-03 14:47:01 -06:00
|
|
|
rust_task_thread::activate(rust_task *task) {
|
2011-09-27 21:19:19 -05:00
|
|
|
task->ctx.next = &c_context;
|
2011-05-31 19:44:54 -05:00
|
|
|
DLOG(this, task, "descheduling...");
|
2011-07-23 21:03:02 -05:00
|
|
|
lock.unlock();
|
2011-09-27 21:19:19 -05:00
|
|
|
task->ctx.swap(c_context);
|
2011-07-23 21:03:02 -05:00
|
|
|
lock.lock();
|
2011-05-31 19:44:54 -05:00
|
|
|
DLOG(this, task, "task has returned");
|
2010-06-23 23:03:09 -05:00
|
|
|
}
|
|
|
|
|
2010-07-19 16:05:18 -05:00
|
|
|
void
|
2012-02-03 14:47:01 -06:00
|
|
|
rust_task_thread::log(rust_task* task, uint32_t level, char const *fmt, ...) {
|
2011-01-14 15:41:39 -06:00
|
|
|
char buf[BUF_BYTES];
|
2011-04-19 05:21:57 -05:00
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
vsnprintf(buf, sizeof(buf), fmt, args);
|
|
|
|
_log.trace_ln(task, level, buf);
|
|
|
|
va_end(args);
|
2010-07-19 16:05:18 -05:00
|
|
|
}
|
|
|
|
|
2010-06-23 23:03:09 -05:00
|
|
|
void
|
2012-02-03 14:47:01 -06:00
|
|
|
rust_task_thread::fail() {
|
2011-04-19 05:21:57 -05:00
|
|
|
log(NULL, log_err, "domain %s @0x%" PRIxPTR " root task failed",
|
2010-08-08 21:24:35 -05:00
|
|
|
name, this);
|
2011-08-10 14:57:53 -05:00
|
|
|
kernel->fail();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-03 14:47:01 -06:00
|
|
|
rust_task_thread::kill_all_tasks() {
|
2011-08-10 14:57:53 -05:00
|
|
|
I(this, !lock.lock_held_by_current_thread());
|
|
|
|
scoped_lock with(lock);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < running_tasks.length(); i++) {
|
2011-09-14 19:05:35 -05:00
|
|
|
// We don't want the failure of these tasks to propagate back
|
|
|
|
// to the kernel again since we're already failing everything
|
|
|
|
running_tasks[i]->unsupervise();
|
2011-08-10 14:57:53 -05:00
|
|
|
running_tasks[i]->kill();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < blocked_tasks.length(); i++) {
|
2011-09-14 19:05:35 -05:00
|
|
|
blocked_tasks[i]->unsupervise();
|
2011-08-10 14:57:53 -05:00
|
|
|
blocked_tasks[i]->kill();
|
|
|
|
}
|
2010-06-23 23:03:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2012-02-03 14:47:01 -06:00
|
|
|
rust_task_thread::number_of_live_tasks() {
|
2010-06-23 23:03:09 -05:00
|
|
|
return running_tasks.length() + blocked_tasks.length();
|
|
|
|
}
|
|
|
|
|
2010-07-19 16:05:18 -05:00
|
|
|
/**
|
|
|
|
* Delete any dead tasks.
|
|
|
|
*/
|
2010-06-23 23:03:09 -05:00
|
|
|
void
|
2012-02-03 14:47:01 -06:00
|
|
|
rust_task_thread::reap_dead_tasks() {
|
2011-07-23 21:03:02 -05:00
|
|
|
I(this, lock.lock_held_by_current_thread());
|
2011-08-20 18:05:18 -05:00
|
|
|
if (dead_tasks.length() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-20 18:30:27 -05:00
|
|
|
// First make a copy of the dead_task list with the lock held
|
2011-08-20 18:05:18 -05:00
|
|
|
size_t dead_tasks_len = dead_tasks.length();
|
|
|
|
rust_task **dead_tasks_copy = (rust_task**)
|
|
|
|
srv->malloc(sizeof(rust_task*) * dead_tasks_len);
|
|
|
|
for (size_t i = 0; i < dead_tasks_len; ++i) {
|
2012-02-02 19:22:12 -06:00
|
|
|
dead_tasks_copy[i] = dead_tasks.pop_value();
|
2011-08-20 18:05:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now unlock again because we have to actually free the dead tasks,
|
2012-02-02 19:22:12 -06:00
|
|
|
// and that may end up wanting to lock the kernel lock. We have
|
|
|
|
// a kernel lock -> scheduler lock locking order that we need
|
|
|
|
// to maintain.
|
2011-08-20 18:05:18 -05:00
|
|
|
lock.unlock();
|
|
|
|
|
|
|
|
for (size_t i = 0; i < dead_tasks_len; ++i) {
|
|
|
|
rust_task *task = dead_tasks_copy[i];
|
2012-02-07 01:38:22 -06:00
|
|
|
// Release the task from the kernel so nobody else can get at it
|
|
|
|
kernel->release_task_id(task->user.id);
|
|
|
|
// Deref the task, which may cause it to request us to release it
|
|
|
|
task->deref();
|
2010-06-23 23:03:09 -05:00
|
|
|
}
|
2011-08-20 18:05:18 -05:00
|
|
|
srv->free(dead_tasks_copy);
|
|
|
|
|
|
|
|
lock.lock();
|
2010-06-23 23:03:09 -05:00
|
|
|
}
|
|
|
|
|
2012-02-07 01:38:22 -06:00
|
|
|
void
|
|
|
|
rust_task_thread::release_task(rust_task *task) {
|
|
|
|
// Nobody should have a ref to the task at this point
|
|
|
|
I(this, task->ref_count == 0);
|
|
|
|
// Kernel should not know about the task any more
|
|
|
|
I(this, kernel->get_task_by_id(task->user.id) == NULL);
|
|
|
|
// Now delete the task, which will require using this thread's
|
|
|
|
// memory region.
|
|
|
|
delete task;
|
|
|
|
// Now release the task from the scheduler, which may trigger this
|
|
|
|
// thread to exit
|
|
|
|
sched->release_task();
|
|
|
|
}
|
|
|
|
|
2010-07-19 16:05:18 -05:00
|
|
|
/**
|
|
|
|
* Schedules a running task for execution. Only running tasks can be
|
|
|
|
* activated. Blocked tasks have to be unblocked before they can be
|
|
|
|
* activated.
|
|
|
|
*
|
|
|
|
* Returns NULL if no tasks can be scheduled.
|
|
|
|
*/
|
2010-06-23 23:03:09 -05:00
|
|
|
rust_task *
|
2012-02-03 14:47:01 -06:00
|
|
|
rust_task_thread::schedule_task() {
|
2010-06-23 23:03:09 -05:00
|
|
|
I(this, this);
|
|
|
|
// FIXME: in the face of failing tasks, this is not always right.
|
|
|
|
// I(this, n_live_tasks() > 0);
|
|
|
|
if (running_tasks.length() > 0) {
|
2011-09-20 17:34:47 -05:00
|
|
|
size_t k = isaac_rand(&rctx);
|
2011-06-20 19:19:50 -05:00
|
|
|
// Look around for a runnable task, starting at k.
|
|
|
|
for(size_t j = 0; j < running_tasks.length(); ++j) {
|
|
|
|
size_t i = (j + k) % running_tasks.length();
|
2012-02-02 18:30:22 -06:00
|
|
|
return (rust_task *)running_tasks[i];
|
2010-08-11 23:23:34 -05:00
|
|
|
}
|
2010-06-23 23:03:09 -05:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-07-28 16:53:08 -05:00
|
|
|
void
|
2012-02-03 14:47:01 -06:00
|
|
|
rust_task_thread::log_state() {
|
2011-12-28 13:53:12 -06:00
|
|
|
if (log_rt_task < log_debug) return;
|
2011-04-19 05:21:57 -05:00
|
|
|
|
2010-07-28 16:53:08 -05:00
|
|
|
if (!running_tasks.is_empty()) {
|
2011-12-28 13:53:12 -06:00
|
|
|
log(NULL, log_debug, "running tasks:");
|
2010-07-28 16:53:08 -05:00
|
|
|
for (size_t i = 0; i < running_tasks.length(); i++) {
|
2012-02-02 18:24:32 -06:00
|
|
|
log(NULL, log_debug, "\t task: %s @0x%" PRIxPTR,
|
2010-08-11 23:23:34 -05:00
|
|
|
running_tasks[i]->name,
|
2012-02-02 18:24:32 -06:00
|
|
|
running_tasks[i]);
|
2010-07-28 16:53:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!blocked_tasks.is_empty()) {
|
2011-12-28 13:53:12 -06:00
|
|
|
log(NULL, log_debug, "blocked tasks:");
|
2010-07-28 16:53:08 -05:00
|
|
|
for (size_t i = 0; i < blocked_tasks.length(); i++) {
|
2011-12-28 13:53:12 -06:00
|
|
|
log(NULL, log_debug, "\t task: %s @0x%" PRIxPTR ", blocked on: 0x%"
|
2011-04-19 05:21:57 -05:00
|
|
|
PRIxPTR " '%s'",
|
2010-08-08 21:24:35 -05:00
|
|
|
blocked_tasks[i]->name, blocked_tasks[i],
|
2010-08-18 01:26:43 -05:00
|
|
|
blocked_tasks[i]->cond, blocked_tasks[i]->cond_name);
|
2010-07-28 16:53:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dead_tasks.is_empty()) {
|
2011-12-28 13:53:12 -06:00
|
|
|
log(NULL, log_debug, "dead tasks:");
|
2010-07-28 16:53:08 -05:00
|
|
|
for (size_t i = 0; i < dead_tasks.length(); i++) {
|
2011-12-28 13:53:12 -06:00
|
|
|
log(NULL, log_debug, "\t task: %s 0x%" PRIxPTR,
|
2011-07-27 16:51:25 -05:00
|
|
|
dead_tasks[i]->name, dead_tasks[i]);
|
2010-07-28 16:53:08 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-07-19 16:05:18 -05:00
|
|
|
/**
|
|
|
|
* Starts the main scheduler loop which performs task scheduling for this
|
|
|
|
* domain.
|
|
|
|
*
|
2010-07-28 18:49:16 -05:00
|
|
|
* Returns once no more tasks can be scheduled and all task ref_counts
|
|
|
|
* drop to zero.
|
2010-07-19 16:05:18 -05:00
|
|
|
*/
|
2011-07-23 21:03:02 -05:00
|
|
|
void
|
2012-02-03 14:47:01 -06:00
|
|
|
rust_task_thread::start_main_loop() {
|
2011-07-23 21:03:02 -05:00
|
|
|
lock.lock();
|
2011-06-20 19:19:50 -05:00
|
|
|
|
|
|
|
DLOG(this, dom, "started domain loop %d", id);
|
2010-07-19 16:05:18 -05:00
|
|
|
|
2012-02-02 19:02:50 -06:00
|
|
|
while (!should_exit) {
|
2012-02-03 19:26:54 -06:00
|
|
|
DLOG(this, dom, "worker %d, number_of_live_tasks = %d",
|
|
|
|
id, number_of_live_tasks());
|
2011-06-20 19:19:50 -05:00
|
|
|
|
2012-02-02 20:17:33 -06:00
|
|
|
rust_task *scheduled_task = schedule_task();
|
2010-07-19 16:05:18 -05:00
|
|
|
|
|
|
|
if (scheduled_task == NULL) {
|
2011-04-19 05:21:57 -05:00
|
|
|
log_state();
|
|
|
|
DLOG(this, task,
|
2011-06-20 19:19:50 -05:00
|
|
|
"all tasks are blocked, scheduler id %d yielding ...",
|
|
|
|
id);
|
2012-02-02 20:23:01 -06:00
|
|
|
lock.wait();
|
2012-02-02 20:17:33 -06:00
|
|
|
reap_dead_tasks();
|
2011-07-25 20:00:37 -05:00
|
|
|
DLOG(this, task,
|
|
|
|
"scheduler %d resuming ...", id);
|
2010-07-19 16:05:18 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
I(this, scheduled_task->running());
|
|
|
|
|
2011-04-19 05:21:57 -05:00
|
|
|
DLOG(this, task,
|
2011-07-27 16:51:25 -05:00
|
|
|
"activating task %s 0x%" PRIxPTR
|
|
|
|
", sp=0x%" PRIxPTR
|
|
|
|
", state: %s",
|
|
|
|
scheduled_task->name,
|
|
|
|
(uintptr_t)scheduled_task,
|
2011-08-17 16:42:28 -05:00
|
|
|
scheduled_task->user.rust_sp,
|
2011-07-27 16:51:25 -05:00
|
|
|
scheduled_task->state->name);
|
2010-07-19 16:05:18 -05:00
|
|
|
|
2011-09-27 19:14:18 -05:00
|
|
|
place_task_in_tls(scheduled_task);
|
|
|
|
|
2011-06-20 19:19:50 -05:00
|
|
|
DLOG(this, task,
|
|
|
|
"Running task %p on worker %d",
|
|
|
|
scheduled_task, id);
|
2010-07-19 16:05:18 -05:00
|
|
|
activate(scheduled_task);
|
|
|
|
|
2011-04-19 05:21:57 -05:00
|
|
|
DLOG(this, task,
|
2011-06-20 19:19:50 -05:00
|
|
|
"returned from task %s @0x%" PRIxPTR
|
2011-06-21 20:08:34 -05:00
|
|
|
" in state '%s', sp=0x%x, worker id=%d" PRIxPTR,
|
2011-06-20 19:19:50 -05:00
|
|
|
scheduled_task->name,
|
|
|
|
(uintptr_t)scheduled_task,
|
|
|
|
scheduled_task->state->name,
|
2011-08-17 16:42:28 -05:00
|
|
|
scheduled_task->user.rust_sp,
|
2011-06-20 19:19:50 -05:00
|
|
|
id);
|
2010-07-19 16:05:18 -05:00
|
|
|
|
2012-02-02 20:17:33 -06:00
|
|
|
reap_dead_tasks();
|
2010-07-19 16:05:18 -05:00
|
|
|
}
|
|
|
|
|
2012-02-02 18:34:34 -06:00
|
|
|
A(this, newborn_tasks.is_empty(), "Should have no newborn tasks");
|
|
|
|
A(this, running_tasks.is_empty(), "Should have no running tasks");
|
|
|
|
A(this, blocked_tasks.is_empty(), "Should have no blocked tasks");
|
|
|
|
A(this, dead_tasks.is_empty(), "Should have no dead tasks");
|
2010-07-19 16:05:18 -05:00
|
|
|
|
2011-07-23 21:03:02 -05:00
|
|
|
DLOG(this, dom, "finished main-loop %d", id);
|
2011-06-20 19:19:50 -05:00
|
|
|
|
2011-07-23 21:03:02 -05:00
|
|
|
lock.unlock();
|
2011-06-20 19:19:50 -05:00
|
|
|
}
|
2010-07-19 16:05:18 -05:00
|
|
|
|
2010-06-23 23:03:09 -05:00
|
|
|
rust_crate_cache *
|
2012-02-03 14:47:01 -06:00
|
|
|
rust_task_thread::get_cache() {
|
2011-05-26 20:20:48 -05:00
|
|
|
return &cache;
|
2010-06-23 23:03:09 -05:00
|
|
|
}
|
|
|
|
|
2012-02-03 19:26:54 -06:00
|
|
|
rust_task_id
|
2012-02-03 14:47:01 -06:00
|
|
|
rust_task_thread::create_task(rust_task *spawner, const char *name,
|
2012-01-29 23:20:36 -06:00
|
|
|
size_t init_stack_sz) {
|
2010-09-10 03:21:29 -05:00
|
|
|
rust_task *task =
|
2011-07-18 14:02:26 -05:00
|
|
|
new (this->kernel, "rust_task")
|
2012-01-29 23:20:36 -06:00
|
|
|
rust_task (this, &newborn_tasks, spawner, name, init_stack_sz);
|
2011-04-19 05:21:57 -05:00
|
|
|
DLOG(this, task, "created task: " PTR ", spawner: %s, name: %s",
|
2010-09-10 03:21:29 -05:00
|
|
|
task, spawner ? spawner->name : "null", name);
|
2011-08-01 13:01:59 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
scoped_lock with(lock);
|
|
|
|
newborn_tasks.append(task);
|
|
|
|
}
|
2011-07-23 21:03:02 -05:00
|
|
|
|
2012-02-03 19:26:54 -06:00
|
|
|
kernel->register_task(task);
|
|
|
|
return task->user.id;
|
2010-09-10 03:21:29 -05:00
|
|
|
}
|
2010-06-23 23:03:09 -05:00
|
|
|
|
2012-02-03 14:47:01 -06:00
|
|
|
void rust_task_thread::run() {
|
2011-07-23 21:03:02 -05:00
|
|
|
this->start_main_loop();
|
2012-02-04 16:54:10 -06:00
|
|
|
sched->release_task_thread();
|
2011-07-23 21:03:02 -05:00
|
|
|
}
|
|
|
|
|
2011-09-27 19:14:18 -05:00
|
|
|
#ifndef _WIN32
|
|
|
|
void
|
2012-02-03 14:47:01 -06:00
|
|
|
rust_task_thread::init_tls() {
|
2011-09-27 19:14:18 -05:00
|
|
|
int result = pthread_key_create(&task_key, NULL);
|
|
|
|
assert(!result && "Couldn't create the TLS key!");
|
|
|
|
tls_initialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-03 14:47:01 -06:00
|
|
|
rust_task_thread::place_task_in_tls(rust_task *task) {
|
2011-09-27 19:14:18 -05:00
|
|
|
int result = pthread_setspecific(task_key, task);
|
|
|
|
assert(!result && "Couldn't place the task in TLS!");
|
2011-12-01 17:26:42 -06:00
|
|
|
task->record_stack_limit();
|
2011-09-27 19:14:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
rust_task *
|
2012-02-03 14:47:01 -06:00
|
|
|
rust_task_thread::get_task() {
|
2011-11-14 15:52:35 -06:00
|
|
|
if (!tls_initialized)
|
|
|
|
return NULL;
|
2011-09-27 19:14:18 -05:00
|
|
|
rust_task *task = reinterpret_cast<rust_task *>
|
|
|
|
(pthread_getspecific(task_key));
|
|
|
|
assert(task && "Couldn't get the task from TLS!");
|
|
|
|
return task;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void
|
2012-02-03 14:47:01 -06:00
|
|
|
rust_task_thread::init_tls() {
|
2011-09-27 19:14:18 -05:00
|
|
|
task_key = TlsAlloc();
|
|
|
|
assert(task_key != TLS_OUT_OF_INDEXES && "Couldn't create the TLS key!");
|
|
|
|
tls_initialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-03 14:47:01 -06:00
|
|
|
rust_task_thread::place_task_in_tls(rust_task *task) {
|
2011-09-27 19:14:18 -05:00
|
|
|
BOOL result = TlsSetValue(task_key, task);
|
|
|
|
assert(result && "Couldn't place the task in TLS!");
|
2011-12-08 18:47:33 -06:00
|
|
|
task->record_stack_limit();
|
2011-09-27 19:14:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
rust_task *
|
2012-02-03 14:47:01 -06:00
|
|
|
rust_task_thread::get_task() {
|
2011-11-14 15:52:35 -06:00
|
|
|
if (!tls_initialized)
|
|
|
|
return NULL;
|
2011-09-27 19:14:18 -05:00
|
|
|
rust_task *task = reinterpret_cast<rust_task *>(TlsGetValue(task_key));
|
|
|
|
assert(task && "Couldn't get the task from TLS!");
|
|
|
|
return task;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-02-02 19:02:50 -06:00
|
|
|
void
|
2012-02-03 14:47:01 -06:00
|
|
|
rust_task_thread::exit() {
|
2012-02-02 19:02:50 -06:00
|
|
|
A(this, !lock.lock_held_by_current_thread(), "Shouldn't have lock");
|
|
|
|
scoped_lock with(lock);
|
|
|
|
should_exit = true;
|
2012-02-02 20:29:03 -06:00
|
|
|
lock.signal();
|
2012-02-02 19:02:50 -06:00
|
|
|
}
|
|
|
|
|
2010-06-23 23:03:09 -05:00
|
|
|
//
|
|
|
|
// Local Variables:
|
|
|
|
// mode: C++
|
|
|
|
// fill-column: 70;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|
|
|
|
//
|