1
0
Fork 0

loosen the lifetime bounds on Context

fix #6
ref #3
This commit is contained in:
edef 2015-04-16 03:53:49 -04:00
parent 195350863a
commit 42db0ee5b1
4 changed files with 12 additions and 9 deletions

View File

@ -3,7 +3,7 @@ extern crate test;
extern crate lwkt;
use lwkt::{Context, Stack};
static mut ctx_slot: *mut Context<SliceStack<'static>> = 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]

View File

@ -3,7 +3,7 @@ extern crate test;
extern crate lwkt;
use lwkt::{Context, StackSource};
static mut ctx_slot: *mut Context<lwkt::os::Stack> = 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) {

View File

@ -3,7 +3,7 @@ extern crate lwkt;
use lwkt::{Context, StackSource};
#[thread_local]
static mut ctx_slot: *mut Context<lwkt::os::Stack> = 0 as *mut Context<_>;
static mut ctx_slot: *mut Context<'static, lwkt::os::Stack> = 0 as *mut Context<_>;
fn main() {
unsafe {

View File

@ -1,24 +1,27 @@
use core::prelude::*;
use core::marker::PhantomData;
use arch::Registers;
use stack;
use debug::StackId;
pub struct Context<Stack: stack::Stack> {
pub struct Context<'a, Stack: stack::Stack> {
regs: Registers,
_stack_id: StackId,
stack: Stack
stack: Stack,
_ref: PhantomData<&'a ()>
}
impl<Stack> Context<Stack> where Stack: stack::Stack {
impl<'a, Stack> Context<'a, Stack> where Stack: stack::Stack {
#[inline]
pub unsafe fn new<F>(mut stack: Stack, f: F) -> Context<Stack>
where F: FnOnce() + Send + 'static {
pub unsafe fn new<F>(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
}
}