rt: Add methods to rust_task_thread for borrowing C stacks
This commit is contained in:
parent
8fe506bdca
commit
bfb80064d2
2 changed files with 40 additions and 1 deletions
|
@ -13,6 +13,8 @@ pthread_key_t rust_task_thread::task_key;
|
||||||
DWORD rust_task_thread::task_key;
|
DWORD rust_task_thread::task_key;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
const size_t C_STACK_SIZE = (1024*1024);
|
||||||
|
|
||||||
bool rust_task_thread::tls_initialized = false;
|
bool rust_task_thread::tls_initialized = false;
|
||||||
|
|
||||||
rust_task_thread::rust_task_thread(rust_scheduler *sched,
|
rust_task_thread::rust_task_thread(rust_scheduler *sched,
|
||||||
|
@ -34,7 +36,8 @@ rust_task_thread::rust_task_thread(rust_scheduler *sched,
|
||||||
id(id),
|
id(id),
|
||||||
min_stack_size(kernel->env->min_stack_size),
|
min_stack_size(kernel->env->min_stack_size),
|
||||||
env(kernel->env),
|
env(kernel->env),
|
||||||
should_exit(false)
|
should_exit(false),
|
||||||
|
cached_c_stack(NULL)
|
||||||
{
|
{
|
||||||
LOGPTR(this, "new dom", (uintptr_t)this);
|
LOGPTR(this, "new dom", (uintptr_t)this);
|
||||||
isaac_init(kernel, &rctx);
|
isaac_init(kernel, &rctx);
|
||||||
|
@ -58,6 +61,10 @@ rust_task_thread::~rust_task_thread() {
|
||||||
#ifndef __WIN32__
|
#ifndef __WIN32__
|
||||||
pthread_attr_destroy(&attr);
|
pthread_attr_destroy(&attr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (cached_c_stack) {
|
||||||
|
destroy_stack(kernel, cached_c_stack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -367,6 +374,27 @@ rust_task_thread::exit() {
|
||||||
lock.signal();
|
lock.signal();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stk_seg *
|
||||||
|
rust_task_thread::borrow_c_stack() {
|
||||||
|
|
||||||
|
if (cached_c_stack) {
|
||||||
|
stk_seg *your_stack = cached_c_stack;
|
||||||
|
cached_c_stack = NULL;
|
||||||
|
return your_stack;
|
||||||
|
} else {
|
||||||
|
return create_stack(kernel, C_STACK_SIZE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
rust_task_thread::return_c_stack(stk_seg *stack) {
|
||||||
|
if (cached_c_stack) {
|
||||||
|
destroy_stack(kernel, stack);
|
||||||
|
} else {
|
||||||
|
cached_c_stack = stack;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Local Variables:
|
// Local Variables:
|
||||||
// mode: C++
|
// mode: C++
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#ifndef RUST_TASK_THREAD_H
|
#ifndef RUST_TASK_THREAD_H
|
||||||
#define RUST_TASK_THREAD_H
|
#define RUST_TASK_THREAD_H
|
||||||
|
|
||||||
|
#include "rust_stack.h"
|
||||||
#include "context.h"
|
#include "context.h"
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
@ -91,6 +92,12 @@ struct rust_task_thread : public kernel_owned<rust_task_thread>,
|
||||||
|
|
||||||
bool should_exit;
|
bool should_exit;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
stk_seg *cached_c_stack;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
// 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_task_thread(rust_scheduler *sched, rust_srv *srv, int id);
|
rust_task_thread(rust_scheduler *sched, rust_srv *srv, int id);
|
||||||
|
@ -127,6 +134,10 @@ struct rust_task_thread : public kernel_owned<rust_task_thread>,
|
||||||
|
|
||||||
// Tells the scheduler to exit it's scheduling loop and thread
|
// Tells the scheduler to exit it's scheduling loop and thread
|
||||||
void exit();
|
void exit();
|
||||||
|
|
||||||
|
// Called by tasks when they need a stack on which to run C code
|
||||||
|
stk_seg *borrow_c_stack();
|
||||||
|
void return_c_stack(stk_seg *stack);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline rust_log &
|
inline rust_log &
|
||||||
|
|
Loading…
Reference in a new issue