2016-08-19 21:58:45 +08:00
|
|
|
// This file is part of libfringe, a low-level green threading library.
|
|
|
|
// Copyright (c) whitequark <whitequark@whitequark.org>
|
|
|
|
// See the LICENSE file included in this distribution.
|
|
|
|
|
2016-09-03 06:14:07 +08:00
|
|
|
/// SliceStack holds a non-guarded stack allocated elsewhere and provided as a mutable slice.
|
|
|
|
///
|
|
|
|
/// Any slice used in a SliceStack must adhere to the [Stack contract][contract].
|
|
|
|
/// [contract]: trait.Stack.html
|
2016-08-30 14:49:43 +08:00
|
|
|
#[derive(Debug)]
|
2016-08-19 21:58:45 +08:00
|
|
|
pub struct SliceStack<'a>(pub &'a mut [u8]);
|
|
|
|
|
|
|
|
impl<'a> ::stack::Stack for SliceStack<'a> {
|
|
|
|
#[inline(always)]
|
|
|
|
fn base(&self) -> *mut u8 {
|
|
|
|
// The slice cannot wrap around the address space, so the conversion from usize
|
|
|
|
// to isize will not wrap either.
|
|
|
|
let len: isize = self.0.len() as isize;
|
|
|
|
unsafe { self.limit().offset(len) }
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn limit(&self) -> *mut u8 {
|
|
|
|
self.0.as_ptr() as *mut u8
|
|
|
|
}
|
|
|
|
}
|