get rid of the old Context::swap

The two-parameter version is the only necessary API.
This commit is contained in:
edef 2016-04-03 19:54:40 +02:00
parent 026f7b9925
commit 976b971436
4 changed files with 17 additions and 20 deletions

View File

@ -17,13 +17,13 @@ fn context_new(b: &mut test::Bencher) {
let mut ctx = Context::new(stack, move || {
let ctx_ptr = ctx_slot;
loop {
(*ctx_ptr).swap()
Context::swap(ctx_ptr, ctx_ptr);
}
});
ctx_slot = &mut ctx;
ctx.swap();
Context::swap(ctx_slot, ctx_slot);
})
}

View File

@ -17,14 +17,15 @@ fn swap(b: &mut test::Bencher) {
let mut ctx = Context::new(stack, move || {
let ctx_ptr = ctx_slot;
loop {
(*ctx_ptr).swap()
Context::swap(ctx_ptr, ctx_ptr);
}
});
ctx_slot = &mut ctx;
let ctx_ptr = &mut ctx;
ctx_slot = ctx_ptr;
ctx.swap();
Context::swap(ctx_ptr, ctx_ptr);
b.iter(|| ctx.swap());
b.iter(|| Context::swap(ctx_ptr, ctx_ptr));
}
}

View File

@ -14,12 +14,12 @@ fn main() {
let mut ctx = Context::new(stack, move || {
println!("it's alive!");
(*ctx_slot).swap();
Context::swap(ctx_slot, ctx_slot);
panic!("Do not come back!")
});
ctx_slot = &mut ctx;
(*ctx_slot).swap();
Context::swap(ctx_slot, ctx_slot);
}
}

View File

@ -43,21 +43,17 @@ impl<'a, Stack> Context<'a, Stack> where Stack: stack::Stack {
}
}
/// Switch to the context, saving the current thread of execution there.
#[inline(always)]
pub unsafe fn swap(&mut self) {
Context::swap2(self, self)
}
/// Switch to in_ctx, saving the current thread of execution to out_ctx.
#[inline(always)]
pub unsafe fn swap2<'b>(out_ctx: *mut Context<'a, Stack>, in_ctx: *const Context<'b, Stack>) {
Registers::swap2(&mut (*out_ctx).regs, &(*in_ctx).regs)
}
/// Unwrap the context, returning the stack it contained.
#[inline]
pub unsafe fn unwrap(self) -> Stack {
self.stack
}
}
impl<'i, InStack> Context<'i, InStack> where InStack: stack::Stack {
/// Switch to in_ctx, saving the current thread of execution to out_ctx.
#[inline(always)]
pub unsafe fn swap<'o, OutStack: stack::Stack>(out_ctx: *mut Context<'o, OutStack>, in_ctx: *const Context<'i, InStack>) {
Registers::swap2(&mut (*out_ctx).regs, &(*in_ctx).regs)
}
}