From 090040bf4037a094e50b03d79e4baf5cd89c912b Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 5 May 2014 18:56:44 -0700 Subject: librustc: Remove `~EXPR`, `~TYPE`, and `~PAT` from the language, except for `~str`/`~[]`. Note that `~self` still remains, since I forgot to add support for `Box` before the snapshot. How to update your code: * Instead of `~EXPR`, you should write `box EXPR`. * Instead of `~TYPE`, you should write `Box`. * Instead of `~PATTERN`, you should write `box PATTERN`. [breaking-change] --- src/libstd/rt/thread.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/libstd/rt/thread.rs') diff --git a/src/libstd/rt/thread.rs b/src/libstd/rt/thread.rs index a836958279b..bc9a0b3460a 100644 --- a/src/libstd/rt/thread.rs +++ b/src/libstd/rt/thread.rs @@ -22,6 +22,7 @@ use kinds::Send; use libc; use ops::Drop; use option::{Option, Some, None}; +use owned::Box; use uint; type StartFn = extern "C" fn(*libc::c_void) -> imp::rust_thread_return; @@ -31,7 +32,7 @@ type StartFn = extern "C" fn(*libc::c_void) -> imp::rust_thread_return; pub struct Thread { native: imp::rust_thread, joined: bool, - packet: ~Option, + packet: Box>, } static DEFAULT_STACK_SIZE: uint = 1024 * 1024; @@ -45,7 +46,7 @@ extern fn thread_start(main: *libc::c_void) -> imp::rust_thread_return { use rt::stack; unsafe { stack::record_stack_bounds(0, uint::MAX); - let f: ~proc() = cast::transmute(main); + let f: Box = cast::transmute(main); (*f)(); cast::transmute(0 as imp::rust_thread_return) } @@ -78,11 +79,11 @@ impl Thread<()> { pub fn start_stack(stack: uint, main: proc():Send -> T) -> Thread { // We need the address of the packet to fill in to be stable so when - // `main` fills it in it's still valid, so allocate an extra ~ box to do + // `main` fills it in it's still valid, so allocate an extra box to do // so. let packet = box None; let packet2: *mut Option = unsafe { - *cast::transmute::<&~Option, **mut Option>(&packet) + *cast::transmute::<&Box>, **mut Option>(&packet) }; let main = proc() unsafe { *packet2 = Some(main()); }; let native = unsafe { imp::create(stack, box main) }; @@ -152,13 +153,14 @@ mod imp { use libc::types::os::arch::extra::{LPSECURITY_ATTRIBUTES, SIZE_T, BOOL, LPVOID, DWORD, LPDWORD, HANDLE}; use os; + use owned::Box; use ptr; use rt::stack::RED_ZONE; pub type rust_thread = HANDLE; pub type rust_thread_return = DWORD; - pub unsafe fn create(stack: uint, p: ~proc():Send) -> rust_thread { + pub unsafe fn create(stack: uint, p: Box) -> rust_thread { let arg: *mut libc::c_void = cast::transmute(p); // FIXME On UNIX, we guard against stack sizes that are too small but // that's because pthreads enforces that stacks are at least @@ -175,7 +177,7 @@ mod imp { if ret as uint == 0 { // be sure to not leak the closure - let _p: ~proc():Send = cast::transmute(arg); + let _p: Box = cast::transmute(arg); fail!("failed to spawn native thread: {}", os::last_os_error()); } return ret; @@ -218,13 +220,14 @@ mod imp { use libc; use mem; use os; + use owned::Box; use ptr; use rt::stack::RED_ZONE; pub type rust_thread = libc::pthread_t; pub type rust_thread_return = *u8; - pub unsafe fn create(stack: uint, p: ~proc():Send) -> rust_thread { + pub unsafe fn create(stack: uint, p: Box) -> rust_thread { let mut native: libc::pthread_t = mem::uninit(); let mut attr: libc::pthread_attr_t = mem::uninit(); assert_eq!(pthread_attr_init(&mut attr), 0); @@ -257,7 +260,7 @@ mod imp { if ret != 0 { // be sure to not leak the closure - let _p: ~proc():Send = cast::transmute(arg); + let _p: Box = cast::transmute(arg); fail!("failed to spawn native thread: {}", os::last_os_error()); } native -- cgit 1.4.1-3-g733a5