about summary refs log tree commit diff
path: root/src/libstd/sys/windows
diff options
context:
space:
mode:
authorAaron Turon <aturon@mozilla.com>2014-12-14 00:05:32 -0800
committerAaron Turon <aturon@mozilla.com>2014-12-18 23:31:52 -0800
commita27fbac86849e07a0a6c746869d8f78319bd3a16 (patch)
treef17d75fcdd4d353f5ff919e491a5fc71252c0ef1 /src/libstd/sys/windows
parent13f302d0c5dd3a88426da53ba07cdbe16459635b (diff)
downloadrust-a27fbac86849e07a0a6c746869d8f78319bd3a16.tar.gz
rust-a27fbac86849e07a0a6c746869d8f78319bd3a16.zip
Revise std::thread API to join by default
This commit is part of a series that introduces a `std::thread` API to
replace `std::task`.

In the new API, `spawn` returns a `JoinGuard`, which by default will
join the spawned thread when dropped. It can also be used to join
explicitly at any time, returning the thread's result. Alternatively,
the spawned thread can be explicitly detached (so no join takes place).

As part of this change, Rust processes now terminate when the main
thread exits, even if other detached threads are still running, moving
Rust closer to standard threading models. This new behavior may break code
that was relying on the previously implicit join-all.

In addition to the above, the new thread API also offers some built-in
support for building blocking abstractions in user space; see the module
doc for details.

Closes #18000

[breaking-change]
Diffstat (limited to 'src/libstd/sys/windows')
-rw-r--r--src/libstd/sys/windows/backtrace.rs4
-rw-r--r--src/libstd/sys/windows/fs.rs2
-rw-r--r--src/libstd/sys/windows/os.rs5
-rw-r--r--src/libstd/sys/windows/stack_overflow.rs6
-rw-r--r--src/libstd/sys/windows/thread.rs7
-rw-r--r--src/libstd/sys/windows/thread_local.rs9
6 files changed, 17 insertions, 16 deletions
diff --git a/src/libstd/sys/windows/backtrace.rs b/src/libstd/sys/windows/backtrace.rs
index 9903d2f1ae2..b5961d783ff 100644
--- a/src/libstd/sys/windows/backtrace.rs
+++ b/src/libstd/sys/windows/backtrace.rs
@@ -27,9 +27,9 @@ use io::{IoResult, Writer};
 use libc;
 use mem;
 use ops::Drop;
-use option::{Some, None};
+use option::Option::{Some, None};
 use path::Path;
-use result::{Ok, Err};
+use result::Result::{Ok, Err};
 use sync::{StaticMutex, MUTEX_INIT};
 use slice::SliceExt;
 use str::StrPrelude;
diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs
index 05be8de0b56..0fb52c758d5 100644
--- a/src/libstd/sys/windows/fs.rs
+++ b/src/libstd/sys/windows/fs.rs
@@ -15,7 +15,7 @@ use libc::{mod, c_int};
 
 use c_str::CString;
 use mem;
-use os::windoze::fill_utf16_buf_and_decode;
+use sys::os::fill_utf16_buf_and_decode;
 use path;
 use ptr;
 use str;
diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs
index 5c690180c44..2fbb9494c71 100644
--- a/src/libstd/sys/windows/os.rs
+++ b/src/libstd/sys/windows/os.rs
@@ -24,6 +24,9 @@ use path::{Path, GenericPath, BytesContainer};
 use ptr::{mod, RawPtr};
 use sync::atomic::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
 use sys::fs::FileDesc;
+use option::Option;
+use option::Option::{Some, None};
+use slice;
 
 use os::TMPBUF_SZ;
 use libc::types::os::arch::extra::DWORD;
@@ -138,7 +141,7 @@ pub fn fill_utf16_buf_and_decode(f: |*mut u16, DWORD| -> DWORD) -> Option<String
                 // set `res` to None and continue.
                 let s = String::from_utf16(sub)
                     .expect("fill_utf16_buf_and_decode: closure created invalid UTF-16");
-                res = option::Some(s)
+                res = Some(s)
             }
         }
         return res;
diff --git a/src/libstd/sys/windows/stack_overflow.rs b/src/libstd/sys/windows/stack_overflow.rs
index 63b5b6f5863..bdf2e0bccb1 100644
--- a/src/libstd/sys/windows/stack_overflow.rs
+++ b/src/libstd/sys/windows/stack_overflow.rs
@@ -34,7 +34,7 @@ impl Drop for Handler {
 // It returns the guard page of the current task or 0 if that
 // guard page doesn't exist. None is returned if there's currently
 // no local task.
-unsafe fn get_task_guard_page() -> Option<uint> {
+unsafe fn get_task_guard_page() -> uint {
     thread_info::stack_guard()
 }
 
@@ -55,9 +55,7 @@ extern "system" fn vectored_handler(ExceptionInfo: *mut EXCEPTION_POINTERS) -> L
         // however stack checks by limit should be disabled on Windows
         stack::record_sp_limit(0);
 
-        if get_task_guard_page().is_some() {
-           report_overflow();
-        }
+        report_overflow();
 
         EXCEPTION_CONTINUE_SEARCH
     }
diff --git a/src/libstd/sys/windows/thread.rs b/src/libstd/sys/windows/thread.rs
index 00f1e9767f5..4498f56c00a 100644
--- a/src/libstd/sys/windows/thread.rs
+++ b/src/libstd/sys/windows/thread.rs
@@ -17,6 +17,7 @@ use ptr;
 use libc;
 use libc::types::os::arch::extra::{LPSECURITY_ATTRIBUTES, SIZE_T, BOOL,
                                    LPVOID, DWORD, LPDWORD, HANDLE};
+use thunk::Thunk;
 use sys_common::stack::RED_ZONE;
 use sys_common::thread::*;
 
@@ -43,8 +44,8 @@ pub mod guard {
     }
 }
 
-pub unsafe fn create(stack: uint, p: Box<proc():Send>) -> rust_thread {
-    let arg: *mut libc::c_void = mem::transmute(p);
+pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread {
+    let arg: *mut libc::c_void = mem::transmute(box p);
     // FIXME On UNIX, we guard against stack sizes that are too small but
     // that's because pthreads enforces that stacks are at least
     // PTHREAD_STACK_MIN bytes big.  Windows has no such lower limit, it's
@@ -60,7 +61,7 @@ pub unsafe fn create(stack: uint, p: Box<proc():Send>) -> rust_thread {
 
     if ret as uint == 0 {
         // be sure to not leak the closure
-        let _p: Box<proc():Send> = mem::transmute(arg);
+        let _p: Box<Thunk> = mem::transmute(arg);
         panic!("failed to spawn native thread: {}", ret);
     }
     return ret;
diff --git a/src/libstd/sys/windows/thread_local.rs b/src/libstd/sys/windows/thread_local.rs
index 6c8d9639d5c..0644519aabb 100644
--- a/src/libstd/sys/windows/thread_local.rs
+++ b/src/libstd/sys/windows/thread_local.rs
@@ -14,8 +14,7 @@ use libc::types::os::arch::extra::{DWORD, LPVOID, BOOL};
 
 use mem;
 use rt;
-use rt::exclusive::Exclusive;
-use sync::{ONCE_INIT, Once};
+use sync::{ONCE_INIT, Once, Mutex};
 
 pub type Key = DWORD;
 pub type Dtor = unsafe extern fn(*mut u8);
@@ -55,7 +54,7 @@ pub type Dtor = unsafe extern fn(*mut u8);
 //                        /threading/thread_local_storage_win.cc#L42
 
 static INIT_DTORS: Once = ONCE_INIT;
-static mut DTORS: *mut Exclusive<Vec<(Key, Dtor)>> = 0 as *mut _;
+static mut DTORS: *mut Mutex<Vec<(Key, Dtor)>> = 0 as *mut _;
 
 // -------------------------------------------------------------------------
 // Native bindings
@@ -126,13 +125,13 @@ extern "system" {
 // FIXME: This could probably be at least a little faster with a BTree.
 
 fn init_dtors() {
-    let dtors = box Exclusive::new(Vec::<(Key, Dtor)>::new());
+    let dtors = box Mutex::new(Vec::<(Key, Dtor)>::new());
     unsafe {
         DTORS = mem::transmute(dtors);
     }
 
     rt::at_exit(move|| unsafe {
-        mem::transmute::<_, Box<Exclusive<Vec<(Key, Dtor)>>>>(DTORS);
+        mem::transmute::<_, Box<Mutex<Vec<(Key, Dtor)>>>>(DTORS);
         DTORS = 0 as *mut _;
     });
 }