2013-05-30 05:16:33 -05:00
|
|
|
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
2012-12-03 18:48:01 -06:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2012-04-04 23:17:50 -05:00
|
|
|
#[doc(hidden)];
|
|
|
|
|
2013-02-02 05:10:12 -06:00
|
|
|
use comm::{GenericChan, GenericPort};
|
2013-05-24 21:35:29 -05:00
|
|
|
use comm;
|
2013-01-08 21:37:25 -06:00
|
|
|
use prelude::*;
|
2012-12-23 16:41:37 -06:00
|
|
|
use task;
|
2013-08-09 18:30:44 -05:00
|
|
|
use libc::uintptr_t;
|
2012-04-06 19:03:00 -05:00
|
|
|
|
2013-06-09 01:29:32 -05:00
|
|
|
pub mod dynamic_lib;
|
|
|
|
|
2013-01-15 19:11:16 -06:00
|
|
|
pub mod finally;
|
2013-02-20 10:57:15 -06:00
|
|
|
pub mod intrinsics;
|
2013-05-08 00:37:18 -05:00
|
|
|
pub mod simd;
|
2013-02-20 14:08:25 -06:00
|
|
|
pub mod extfmt;
|
2013-05-08 06:11:23 -05:00
|
|
|
#[cfg(not(test))]
|
2013-03-01 19:27:14 -06:00
|
|
|
pub mod lang;
|
2013-05-09 19:36:45 -05:00
|
|
|
pub mod sync;
|
2013-05-25 00:51:26 -05:00
|
|
|
pub mod atomics;
|
2013-07-21 19:20:52 -05:00
|
|
|
pub mod raw;
|
2013-01-10 21:03:13 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
|
2013-01-11 19:59:35 -06:00
|
|
|
Start a new thread outside of the current runtime context and wait
|
|
|
|
for it to terminate.
|
|
|
|
|
|
|
|
The executing thread has no access to a task pointer and will be using
|
|
|
|
a normal large stack.
|
2013-01-10 21:03:13 -06:00
|
|
|
*/
|
2013-02-03 20:15:43 -06:00
|
|
|
pub fn run_in_bare_thread(f: ~fn()) {
|
2013-07-27 14:05:15 -05:00
|
|
|
use cell::Cell;
|
2013-10-05 16:44:37 -05:00
|
|
|
use rt::shouldnt_be_public::Thread;
|
2013-07-27 14:05:15 -05:00
|
|
|
|
|
|
|
let f_cell = Cell::new(f);
|
2013-02-02 05:10:12 -06:00
|
|
|
let (port, chan) = comm::stream();
|
2013-01-18 16:21:31 -06:00
|
|
|
// FIXME #4525: Unfortunate that this creates an extra scheduler but it's
|
2013-07-27 14:05:15 -05:00
|
|
|
// necessary since rust_raw_thread_join is blocking
|
2013-01-23 13:43:58 -06:00
|
|
|
do task::spawn_sched(task::SingleThreaded) {
|
2013-07-27 14:05:15 -05:00
|
|
|
Thread::start(f_cell.take()).join();
|
|
|
|
chan.send(());
|
2013-01-10 21:03:13 -06:00
|
|
|
}
|
|
|
|
port.recv();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2013-01-23 13:43:58 -06:00
|
|
|
fn test_run_in_bare_thread() {
|
2013-02-03 20:15:43 -06:00
|
|
|
let i = 100;
|
|
|
|
do run_in_bare_thread {
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(i, 100);
|
2013-01-10 21:03:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-13 18:53:13 -06:00
|
|
|
#[test]
|
|
|
|
fn test_run_in_bare_thread_exchange() {
|
2013-02-03 20:15:43 -06:00
|
|
|
// Does the exchange heap work without the runtime?
|
|
|
|
let i = ~100;
|
|
|
|
do run_in_bare_thread {
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(i == ~100);
|
2013-01-13 18:53:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-09 18:30:44 -05:00
|
|
|
/// Dynamically inquire about whether we're running under V.
|
|
|
|
/// You should usually not use this unless your test definitely
|
|
|
|
/// can't run correctly un-altered. Valgrind is there to help
|
|
|
|
/// you notice weirdness in normal, un-doctored code paths!
|
|
|
|
pub fn running_on_valgrind() -> bool {
|
|
|
|
#[fixed_stack_segment]; #[inline(never)];
|
|
|
|
unsafe { rust_running_on_valgrind() != 0 }
|
|
|
|
}
|
|
|
|
|
|
|
|
extern {
|
|
|
|
fn rust_running_on_valgrind() -> uintptr_t;
|
|
|
|
}
|