Skip to content

Commit

Permalink
loosen the lifetime bounds on Context
Browse files Browse the repository at this point in the history
fix #6
ref #3
  • Loading branch information
edef1c committed Apr 16, 2015
1 parent 5bc9cc2 commit 866d590
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion benches/context_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion benches/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 9 additions & 6 deletions src/context.rs
Original file line number Diff line number Diff line change
@@ -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
}
}

Expand Down

0 comments on commit 866d590

Please sign in to comment.