From 42db0ee5b17fea7e7810695c3fb4bce181d31451 Mon Sep 17 00:00:00 2001 From: edef Date: Thu, 16 Apr 2015 03:53:49 -0400 Subject: [PATCH] loosen the lifetime bounds on Context fix #6 ref #3 --- benches/context_new.rs | 2 +- benches/swap.rs | 2 +- examples/basic.rs | 2 +- src/context.rs | 15 +++++++++------ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/benches/context_new.rs b/benches/context_new.rs index eb170b9..ec6c13e 100644 --- a/benches/context_new.rs +++ b/benches/context_new.rs @@ -3,7 +3,7 @@ extern crate test; extern crate lwkt; use lwkt::{Context, Stack}; -static mut ctx_slot: *mut Context> = 0 as *mut Context<_>; +static mut ctx_slot: *mut Context<'static, SliceStack<'static>> = 0 as *mut Context<_>; static mut stack_buf: [u8; 1024] = [0; 1024]; #[bench] diff --git a/benches/swap.rs b/benches/swap.rs index 7d3c4ea..257720e 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<'static, lwkt::os::Stack> = 0 as *mut Context<_>; #[bench] fn swap(b: &mut test::Bencher) { diff --git a/examples/basic.rs b/examples/basic.rs index 435cbdd..c116195 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<'static, lwkt::os::Stack> = 0 as *mut Context<_>; fn main() { unsafe { diff --git a/src/context.rs b/src/context.rs index ffb6dc5..f18be8f 100644 --- a/src/context.rs +++ b/src/context.rs @@ -1,24 +1,27 @@ use core::prelude::*; +use core::marker::PhantomData; use arch::Registers; use stack; use debug::StackId; -pub struct Context { +pub struct Context<'a, Stack: stack::Stack> { regs: Registers, _stack_id: StackId, - stack: Stack + stack: Stack, + _ref: PhantomData<&'a ()> } -impl Context where Stack: stack::Stack { +impl<'a, Stack> Context<'a, Stack> where Stack: stack::Stack { #[inline] - pub unsafe fn new(mut stack: Stack, f: F) -> Context - where F: FnOnce() + Send + 'static { + pub unsafe fn new(mut stack: Stack, f: F) -> Context<'a, Stack> + where F: FnOnce() + Send + 'a { let stack_id = StackId::register(&mut stack); let regs = Registers::new(&mut stack, f); Context { regs: regs, _stack_id: stack_id, - stack: stack + stack: stack, + _ref: PhantomData } }