make Context::new take a stack, instead of creating one
This commit is contained in:
parent
27318bc271
commit
8dc53c3125
|
@ -1,14 +1,16 @@
|
|||
#![feature(test)]
|
||||
extern crate test;
|
||||
extern crate lwkt;
|
||||
use lwkt::Context;
|
||||
use lwkt::{Context, StackSource};
|
||||
|
||||
static mut ctx_slot: *mut Context = 0 as *mut Context;
|
||||
|
||||
#[bench]
|
||||
fn context_new(b: &mut test::Bencher) {
|
||||
b.iter(|| unsafe {
|
||||
let mut ctx = Context::new(move || {
|
||||
let stack = lwkt::os::StackSource::get_stack(4 << 20);
|
||||
|
||||
let mut ctx = Context::new(stack, move || {
|
||||
let ctx_ptr = ctx_slot;
|
||||
loop {
|
||||
(*ctx_ptr).swap()
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
#![feature(test)]
|
||||
extern crate test;
|
||||
extern crate lwkt;
|
||||
use lwkt::Context;
|
||||
use lwkt::{Context, StackSource};
|
||||
|
||||
static mut ctx_slot: *mut Context = 0 as *mut Context;
|
||||
|
||||
#[bench]
|
||||
fn swap(b: &mut test::Bencher) {
|
||||
unsafe {
|
||||
let mut ctx = Context::new(move || {
|
||||
let stack = lwkt::os::StackSource::get_stack(4 << 20);
|
||||
|
||||
let mut ctx = Context::new(stack, move || {
|
||||
let ctx_ptr = ctx_slot;
|
||||
loop {
|
||||
(*ctx_ptr).swap()
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
#![feature(thread_local)]
|
||||
extern crate lwkt;
|
||||
use lwkt::Context;
|
||||
use lwkt::{Context, StackSource};
|
||||
|
||||
#[thread_local]
|
||||
static mut ctx_slot: *mut Context = 0 as *mut Context;
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
let mut ctx = Context::new(move || {
|
||||
let stack = lwkt::os::StackSource::get_stack(4 << 20);
|
||||
|
||||
let mut ctx = Context::new(stack, move || {
|
||||
println!("it's alive!");
|
||||
(*ctx_slot).swap();
|
||||
});
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
use core::prelude::*;
|
||||
use stack::StackSource;
|
||||
use arch::Registers;
|
||||
use stack::Stack;
|
||||
use os;
|
||||
|
||||
pub struct Context {
|
||||
|
@ -11,8 +9,7 @@ pub struct Context {
|
|||
|
||||
impl Context {
|
||||
#[inline]
|
||||
pub unsafe fn new<F>(f: F) -> Context where F: FnOnce() + Send + 'static {
|
||||
let mut stack = os::StackSource::get_stack(4 << 20);
|
||||
pub unsafe fn new<F>(mut stack: os::Stack, f: F) -> Context where F: FnOnce() + Send + 'static {
|
||||
let regs = Registers::new(&mut stack, f);
|
||||
Context {
|
||||
regs: regs,
|
||||
|
|
|
@ -20,4 +20,4 @@ pub mod context;
|
|||
pub mod stack;
|
||||
|
||||
mod arch;
|
||||
mod os;
|
||||
pub mod os;
|
||||
|
|
Loading…
Reference in New Issue