get rid of the old Context::swap
The two-parameter version is the only necessary API.
This commit is contained in:
parent
026f7b9925
commit
976b971436
|
@ -17,13 +17,13 @@ fn context_new(b: &mut test::Bencher) {
|
||||||
let mut ctx = Context::new(stack, move || {
|
let mut ctx = Context::new(stack, move || {
|
||||||
let ctx_ptr = ctx_slot;
|
let ctx_ptr = ctx_slot;
|
||||||
loop {
|
loop {
|
||||||
(*ctx_ptr).swap()
|
Context::swap(ctx_ptr, ctx_ptr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx_slot = &mut ctx;
|
ctx_slot = &mut ctx;
|
||||||
|
|
||||||
ctx.swap();
|
Context::swap(ctx_slot, ctx_slot);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,14 +17,15 @@ fn swap(b: &mut test::Bencher) {
|
||||||
let mut ctx = Context::new(stack, move || {
|
let mut ctx = Context::new(stack, move || {
|
||||||
let ctx_ptr = ctx_slot;
|
let ctx_ptr = ctx_slot;
|
||||||
loop {
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,12 +14,12 @@ fn main() {
|
||||||
|
|
||||||
let mut ctx = Context::new(stack, move || {
|
let mut ctx = Context::new(stack, move || {
|
||||||
println!("it's alive!");
|
println!("it's alive!");
|
||||||
(*ctx_slot).swap();
|
Context::swap(ctx_slot, ctx_slot);
|
||||||
panic!("Do not come back!")
|
panic!("Do not come back!")
|
||||||
});
|
});
|
||||||
|
|
||||||
ctx_slot = &mut ctx;
|
ctx_slot = &mut ctx;
|
||||||
|
|
||||||
(*ctx_slot).swap();
|
Context::swap(ctx_slot, ctx_slot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
/// Unwrap the context, returning the stack it contained.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn unwrap(self) -> Stack {
|
pub unsafe fn unwrap(self) -> Stack {
|
||||||
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue