Skip to content

Commit b43107d

Browse files
committed
---
yaml --- r: 39799 b: refs/heads/incoming c: 1b1700f h: refs/heads/master i: 39797: 8691448 39795: 2c5cc63 39791: 52ef08f v: v3
1 parent ac59cbf commit b43107d

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 3d5418789064fdb463e872a4e651af1c628a3650
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278
9-
refs/heads/incoming: 4c441e95d69909265e69cffd3439f890914e02b3
9+
refs/heads/incoming: 1b1700f44b88225bc3557e1ca497644b9852e268
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libcore/private.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ extern mod rustrt {
3737
unsafe fn rust_destroy_little_lock(lock: rust_little_lock);
3838
unsafe fn rust_lock_little_lock(lock: rust_little_lock);
3939
unsafe fn rust_unlock_little_lock(lock: rust_little_lock);
40+
41+
unsafe fn rust_raw_thread_start(f: &fn()) -> *raw_thread;
42+
unsafe fn rust_raw_thread_join_delete(thread: *raw_thread);
4043
}
4144

4245
#[abi = "rust-intrinsic"]
@@ -46,6 +49,37 @@ extern mod rusti {
4649
fn atomic_xsub(dst: &mut int, src: int) -> int;
4750
}
4851

52+
#[allow(non_camel_case_types)] // runtime type
53+
type raw_thread = libc::c_void;
54+
55+
/**
56+
Start a new thread outside of the current runtime context and wait for it to terminate.
57+
58+
The executing thread has no access to a task pointer and will be using a normal large stack.
59+
*/
60+
pub unsafe fn run_in_bare_thread(f: ~fn()) {
61+
let (port, chan) = pipes::stream();
62+
// XXX Unfortunate that this creates an extra scheduler but it's necessary
63+
// since rust_raw_thread_join_delete is blocking
64+
do task::spawn_sched(task::SingleThreaded) unsafe {
65+
let closure: &fn() = || {
66+
f()
67+
};
68+
let thread = rustrt::rust_raw_thread_start(closure);
69+
rustrt::rust_raw_thread_join_delete(thread);
70+
chan.send(());
71+
}
72+
port.recv();
73+
}
74+
75+
#[test]
76+
fn test_run_in_bare_thread() unsafe {
77+
let i = 100;
78+
do run_in_bare_thread {
79+
assert i == 100;
80+
}
81+
}
82+
4983
#[allow(non_camel_case_types)] // runtime type
5084
type rust_port_id = uint;
5185

branches/incoming/src/rt/rust_builtin.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "rust_util.h"
1616
#include "rust_scheduler.h"
1717
#include "sync/timer.h"
18+
#include "sync/rust_thread.h"
1819
#include "rust_abi.h"
1920
#include "rust_port.h"
2021

@@ -972,6 +973,36 @@ rust_log_str(uint32_t level, const char *str, size_t size) {
972973
task->sched_loop->get_log().log(task, level, "%.*s", (int)size, str);
973974
}
974975

976+
extern "C" CDECL void record_sp_limit(void *limit);
977+
978+
class raw_thread: public rust_thread {
979+
public:
980+
fn_env_pair *fn;
981+
982+
raw_thread(fn_env_pair *fn) : fn(fn) { }
983+
984+
virtual void run() {
985+
record_sp_limit(0);
986+
fn->f(NULL, fn->env, NULL);
987+
}
988+
};
989+
990+
extern "C" raw_thread*
991+
rust_raw_thread_start(fn_env_pair *fn) {
992+
assert(fn);
993+
raw_thread *thread = new raw_thread(fn);
994+
thread->start();
995+
return thread;
996+
}
997+
998+
extern "C" void
999+
rust_raw_thread_join_delete(raw_thread *thread) {
1000+
assert(thread);
1001+
thread->join();
1002+
delete thread;
1003+
}
1004+
1005+
9751006
//
9761007
// Local Variables:
9771008
// mode: C++

branches/incoming/src/rt/rustrt.def.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,5 @@ linenoiseHistoryAdd
208208
linenoiseHistorySetMaxLen
209209
linenoiseHistorySave
210210
linenoiseHistoryLoad
211+
rust_raw_thread_start
212+
rust_raw_thread_join_delete

0 commit comments

Comments
 (0)