From 54b34383e3d522c8a508d2f56b12176bd71099de Mon Sep 17 00:00:00 2001 From: edef Date: Wed, 15 Apr 2015 16:26:51 -0400 Subject: [PATCH] parametrise Context on Stack --- benches/context_new.rs | 2 +- benches/swap.rs | 2 +- examples/basic.rs | 2 +- src/context.rs | 11 ++++++----- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/benches/context_new.rs b/benches/context_new.rs index 4eec654..6ac9f51 100644 --- a/benches/context_new.rs +++ b/benches/context_new.rs @@ -3,7 +3,7 @@ extern crate test; extern crate lwkt; use lwkt::{Context, StackSource}; -static mut ctx_slot: *mut Context = 0 as *mut Context; +static mut ctx_slot: *mut Context = 0 as *mut Context<_>; #[bench] fn context_new(b: &mut test::Bencher) { diff --git a/benches/swap.rs b/benches/swap.rs index b6eb363..7d3c4ea 100644 --- a/benches/swap.rs +++ b/benches/swap.rs @@ -3,7 +3,7 @@ extern crate test; extern crate lwkt; use lwkt::{Context, StackSource}; -static mut ctx_slot: *mut Context = 0 as *mut Context; +static mut ctx_slot: *mut Context = 0 as *mut Context<_>; #[bench] fn swap(b: &mut test::Bencher) { diff --git a/examples/basic.rs b/examples/basic.rs index a421f13..435cbdd 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -3,7 +3,7 @@ extern crate lwkt; use lwkt::{Context, StackSource}; #[thread_local] -static mut ctx_slot: *mut Context = 0 as *mut Context; +static mut ctx_slot: *mut Context = 0 as *mut Context<_>; fn main() { unsafe { diff --git a/src/context.rs b/src/context.rs index 8ffcb30..d322ba8 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1,15 +1,16 @@ use core::prelude::*; use arch::Registers; -use os; +use stack; -pub struct Context { +pub struct Context { regs: Registers, - _stack: os::Stack + _stack: Stack } -impl Context { +impl Context where Stack: stack::Stack { #[inline] - pub unsafe fn new(mut stack: os::Stack, f: F) -> Context where F: FnOnce() + Send + 'static { + pub unsafe fn new(mut stack: Stack, f: F) -> Context + where F: FnOnce() + Send + 'static { let regs = Registers::new(&mut stack, f); Context { regs: regs,