libfringe/src/context.rs

27 lines
514 B
Rust
Raw Normal View History

use core::prelude::*;
use platform::Stack;
2015-01-10 05:45:39 +08:00
use arch::{self, Registers};
use platform;
2014-12-24 13:12:39 +08:00
2014-12-23 11:24:40 +08:00
pub struct Context {
regs: Registers,
_stack: platform::Stack
2014-12-23 11:24:40 +08:00
}
impl Context {
#[inline]
pub unsafe fn new<F>(f: F) -> Context where F: FnOnce() + Send + 'static {
2014-12-24 13:12:39 +08:00
let mut stack = Stack::new(4 << 20);
let regs = arch::initialize_call_frame(&mut stack, f);
2014-12-23 11:24:40 +08:00
Context {
regs: regs,
_stack: stack
2014-12-23 11:24:40 +08:00
}
}
#[inline(always)]
pub unsafe fn swap(&mut self) {
arch::swap(&mut self.regs)
2014-12-23 11:24:40 +08:00
}
}