Skip to content

Commit 7a319f3

Browse files
committed
---
yaml --- r: 8177 b: refs/heads/snap-stage3 c: bfb8006 h: refs/heads/master i: 8175: 0928410 v: v3
1 parent e15e52f commit 7a319f3

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 8fe506bdca714fe2b8b005b1d190091d221c4044
4+
refs/heads/snap-stage3: bfb80064d2dd37bd1e7009d98aa585253f5a2812
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/src/rt/rust_task_thread.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ pthread_key_t rust_task_thread::task_key;
1313
DWORD rust_task_thread::task_key;
1414
#endif
1515

16+
const size_t C_STACK_SIZE = (1024*1024);
17+
1618
bool rust_task_thread::tls_initialized = false;
1719

1820
rust_task_thread::rust_task_thread(rust_scheduler *sched,
@@ -34,7 +36,8 @@ rust_task_thread::rust_task_thread(rust_scheduler *sched,
3436
id(id),
3537
min_stack_size(kernel->env->min_stack_size),
3638
env(kernel->env),
37-
should_exit(false)
39+
should_exit(false),
40+
cached_c_stack(NULL)
3841
{
3942
LOGPTR(this, "new dom", (uintptr_t)this);
4043
isaac_init(kernel, &rctx);
@@ -58,6 +61,10 @@ rust_task_thread::~rust_task_thread() {
5861
#ifndef __WIN32__
5962
pthread_attr_destroy(&attr);
6063
#endif
64+
65+
if (cached_c_stack) {
66+
destroy_stack(kernel, cached_c_stack);
67+
}
6168
}
6269

6370
void
@@ -367,6 +374,27 @@ rust_task_thread::exit() {
367374
lock.signal();
368375
}
369376

377+
stk_seg *
378+
rust_task_thread::borrow_c_stack() {
379+
380+
if (cached_c_stack) {
381+
stk_seg *your_stack = cached_c_stack;
382+
cached_c_stack = NULL;
383+
return your_stack;
384+
} else {
385+
return create_stack(kernel, C_STACK_SIZE);
386+
}
387+
}
388+
389+
void
390+
rust_task_thread::return_c_stack(stk_seg *stack) {
391+
if (cached_c_stack) {
392+
destroy_stack(kernel, stack);
393+
} else {
394+
cached_c_stack = stack;
395+
}
396+
}
397+
370398
//
371399
// Local Variables:
372400
// mode: C++

branches/snap-stage3/src/rt/rust_task_thread.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef RUST_TASK_THREAD_H
22
#define RUST_TASK_THREAD_H
33

4+
#include "rust_stack.h"
45
#include "context.h"
56

67
#ifndef _WIN32
@@ -91,6 +92,12 @@ struct rust_task_thread : public kernel_owned<rust_task_thread>,
9192

9293
bool should_exit;
9394

95+
private:
96+
97+
stk_seg *cached_c_stack;
98+
99+
public:
100+
94101
// Only a pointer to 'name' is kept, so it must live as long as this
95102
// domain.
96103
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>,
127134

128135
// Tells the scheduler to exit it's scheduling loop and thread
129136
void exit();
137+
138+
// Called by tasks when they need a stack on which to run C code
139+
stk_seg *borrow_c_stack();
140+
void return_c_stack(stk_seg *stack);
130141
};
131142

132143
inline rust_log &

0 commit comments

Comments
 (0)