1 // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
13 use comm::{GenericChan, GenericPort};
32 Start a new thread outside of the current runtime context and wait
35 The executing thread has no access to a task pointer and will be using
38 pub fn run_in_bare_thread(f: ~fn()) {
40 use rt::thread::Thread;
42 let f_cell = Cell::new(f);
43 let (port, chan) = comm::stream();
44 // FIXME #4525: Unfortunate that this creates an extra scheduler but it's
45 // necessary since rust_raw_thread_join is blocking
46 do task::spawn_sched(task::SingleThreaded) {
47 Thread::start(f_cell.take()).join();
54 fn test_run_in_bare_thread() {
56 do run_in_bare_thread {
62 fn test_run_in_bare_thread_exchange() {
63 // Does the exchange heap work without the runtime?
65 do run_in_bare_thread {
71 /// Changes the current working directory to the specified
72 /// path while acquiring a global lock, then calls `action`.
73 /// If the change is successful, releases the lock and restores the
74 /// CWD to what it was before, returning true.
75 /// Returns false if the directory doesn't exist or if the directory change
76 /// is otherwise unsuccessful.
78 /// This is used by test cases to avoid cwd races.
82 /// This uses a pthread mutex so descheduling in the action callback
83 /// can lead to deadlock. Calling change_dir_locked recursively will
85 pub fn change_dir_locked(p: &Path, action: &fn()) -> bool {
86 #[fixed_stack_segment]; #[inline(never)];
90 use unstable::sync::atomically;
91 use unstable::finally::Finally;
94 // This is really sketchy. Using a pthread mutex so descheduling
95 // in the `action` callback can cause deadlock. Doing it in
96 // `task::atomically` to try to avoid that, but ... I don't know
98 return do atomically {
99 rust_take_change_dir_lock();
102 let old_dir = os::getcwd();
111 rust_drop_change_dir_lock();
117 fn rust_take_change_dir_lock();
118 fn rust_drop_change_dir_lock();