diff --git a/benches/swap.rs b/benches/swap.rs index 6e7c832..1d113c4 100644 --- a/benches/swap.rs +++ b/benches/swap.rs @@ -3,14 +3,14 @@ #![feature(test)] extern crate test; extern crate lwkt; -use lwkt::{Context, StackSource}; +use lwkt::Context; static mut ctx_slot: *mut Context<'static, lwkt::os::Stack> = 0 as *mut Context<_>; #[bench] fn swap(b: &mut test::Bencher) { unsafe { - let stack = lwkt::os::StackSource.get_stack(4 << 20).unwrap(); + let stack = lwkt::os::Stack::new(4 << 20).unwrap(); let mut ctx = Context::new(stack, move || { let ctx_ptr = ctx_slot; diff --git a/examples/basic.rs b/examples/basic.rs index 791eafd..fabb7be 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -1,13 +1,13 @@ #![feature(thread_local)] extern crate lwkt; -use lwkt::{Context, StackSource}; +use lwkt::Context; #[thread_local] static mut ctx_slot: *mut Context<'static, lwkt::os::Stack> = 0 as *mut Context<_>; fn main() { unsafe { - let stack = lwkt::os::StackSource.get_stack(4 << 20).unwrap(); + let stack = lwkt::os::Stack::new(4 << 20).unwrap(); let mut ctx = Context::new(stack, move || { println!("it's alive!"); diff --git a/src/lib.rs b/src/lib.rs index 6a30d37..83fa1e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,7 @@ extern crate core; extern crate std; pub use context::Context; -pub use stack::{Stack, StackSource}; +pub use stack::Stack; #[cfg(not(test))] mod std { pub use core::*; } diff --git a/src/os/mod.rs b/src/os/mod.rs index fcf24f2..70e843f 100644 --- a/src/os/mod.rs +++ b/src/os/mod.rs @@ -11,12 +11,6 @@ use self::std::io::Error as IoError; use stack; mod sys; -#[derive(Copy, Clone)] -pub struct StackSource; - -unsafe impl Send for StackSource {} -unsafe impl Sync for StackSource {} - #[allow(raw_pointer_derive)] #[derive(Debug)] pub struct Stack { @@ -26,11 +20,8 @@ pub struct Stack { unsafe impl Send for Stack {} -impl stack::StackSource for StackSource { - type Output = Stack; - type Error = IoError; - - fn get_stack(&mut self, size: usize) -> Result { +impl Stack { + pub fn new(size: usize) -> Result { let page_size = sys::page_size(); // round the page size up, diff --git a/src/stack.rs b/src/stack.rs index 60b0c3b..a4d66a5 100644 --- a/src/stack.rs +++ b/src/stack.rs @@ -1,8 +1,6 @@ // Copyright (c) 2015, edef // See the LICENSE file included in this distribution. //! Traits for stacks. -use core::prelude::*; -use core::fmt::{Debug, Display}; /// A trait for objects that hold ownership of a stack. pub trait Stack { @@ -15,10 +13,3 @@ pub trait Stack { /// so this is the lowest address. fn limit(&self) -> *const u8; } - -/// A trait for objects that provide stacks of arbitrary size. -pub trait StackSource { - type Output: Stack; - type Error: Debug + Display = (); - fn get_stack(&mut self, size: usize) -> Result; -}