rust/src/libcore/rt/thread.rs
Niko Matsakis efc7f82bc4 Revamp foreign code not to consider the Rust modes. This requires
adjusting a few foreign functions that were declared with by-ref
mode.  This also allows us to remove by-val mode in the near future.

With copy mode, though, we have to be careful because Rust will implicitly pass
somethings by pointer but this may not be the C ABI rules.  For example, rust
will pass a struct Foo as a Foo*.  So I added some code into the adapters to
fix this (though the C ABI rules may put the pointer back, oh well).

This patch also includes a lint mode for the use of by-ref mode
in foreign functions as the semantics of this have changed.
2013-03-13 16:59:37 -04:00

45 lines
1.2 KiB
Rust

// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// 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.
use libc;
use ops::Drop;
#[allow(non_camel_case_types)] // runtime type
type raw_thread = libc::c_void;
struct Thread {
main: ~fn(),
raw_thread: *raw_thread
}
impl Thread {
static fn start(main: ~fn()) -> Thread {
fn substart(main: &fn()) -> *raw_thread {
unsafe { rust_raw_thread_start(&main) }
}
let raw = substart(main);
Thread {
main: main,
raw_thread: raw
}
}
}
impl Drop for Thread {
fn finalize(&self) {
unsafe { rust_raw_thread_join_delete(self.raw_thread) }
}
}
extern {
pub unsafe fn rust_raw_thread_start(f: &(&fn())) -> *raw_thread;
pub unsafe fn rust_raw_thread_join_delete(thread: *raw_thread);
}