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