forked from M-Labs/libfringe
simplify Valgrind wrapper
This commit is contained in:
parent
5411f10460
commit
878a6fefc3
@ -1,27 +1,21 @@
|
||||
// This file is part of libfringe, a low-level green threading library.
|
||||
// Copyright (c) 2015, edef <edef@edef.eu>
|
||||
// See the LICENSE file included in this distribution.
|
||||
pub use self::imp::*;
|
||||
|
||||
#[cfg(feature = "valgrind")]
|
||||
#[path = "valgrind/mod.rs"]
|
||||
mod imp;
|
||||
|
||||
#[cfg(not(feature = "valgrind"))]
|
||||
mod imp {
|
||||
use stack;
|
||||
|
||||
mod valgrind;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct StackId(valgrind::stack_id_t);
|
||||
|
||||
pub struct StackId;
|
||||
/// No-op since no valgrind
|
||||
impl StackId {
|
||||
#[inline(always)]
|
||||
pub fn register<Stack: stack::Stack>(stack: &mut Stack) -> StackId {
|
||||
StackId(unsafe {
|
||||
valgrind::stack_register(stack.limit(), stack.top())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for StackId {
|
||||
#[inline(always)]
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
valgrind::stack_deregister(self.0)
|
||||
pub unsafe fn register<Stack: stack::Stack>(_stack: &mut Stack) -> StackId {
|
||||
StackId
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,44 @@
|
||||
// This file is part of libfringe, a low-level green threading library.
|
||||
// Copyright (c) 2015, edef <edef@edef.eu>
|
||||
// See the LICENSE file included in this distribution.
|
||||
pub use self::imp::*;
|
||||
|
||||
#[cfg(feature = "valgrind")]
|
||||
#[path = "native.rs"]
|
||||
mod imp;
|
||||
|
||||
#[cfg(not(feature = "valgrind"))]
|
||||
mod imp {
|
||||
//! Stub for the Valgrind functions
|
||||
#![allow(non_camel_case_types)]
|
||||
pub type stack_id_t = ();
|
||||
pub unsafe fn stack_register(_start: *const u8, _end: *const u8) -> stack_id_t {}
|
||||
pub unsafe fn stack_deregister(_id: stack_id_t) {}
|
||||
//! In order for Valgrind to keep track of stack overflows and such, it needs
|
||||
//! a little help. That help unfortunately comes in the form of a set of C
|
||||
//! macros. Calling out to un-inlineable C code for this is pointlessly slow,
|
||||
//! but that's the way it is for now.
|
||||
use stack;
|
||||
|
||||
pub type stack_id_t = u32;
|
||||
extern "C" {
|
||||
#[link_name = "valgrind_stack_register"]
|
||||
/// Register a stack with Valgrind. Returns an integer ID that can
|
||||
/// be used to deregister the stack when it's deallocated.
|
||||
/// `start < end`.
|
||||
pub fn stack_register(start: *const u8, end: *const u8) -> stack_id_t;
|
||||
|
||||
#[link_name = "valgrind_stack_deregister"]
|
||||
/// Deregister a stack from Valgrind. Takes the integer ID that was returned
|
||||
/// on registration.
|
||||
pub fn stack_deregister(id: stack_id_t);
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct StackId(stack_id_t);
|
||||
|
||||
impl StackId {
|
||||
#[inline(always)]
|
||||
pub fn register<Stack: stack::Stack>(stack: &mut Stack) -> StackId {
|
||||
StackId(unsafe {
|
||||
stack_register(stack.limit(), stack.top())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for StackId {
|
||||
#[inline(always)]
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
stack_deregister(self.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
// This file is part of libfringe, a low-level green threading library.
|
||||
// Copyright (c) 2015, edef <edef@edef.eu>
|
||||
// See the LICENSE file included in this distribution.
|
||||
#![allow(non_camel_case_types)]
|
||||
//! In order for Valgrind to keep track of stack overflows and such, it needs
|
||||
//! a little help. That help unfortunately comes in the form of a set of C
|
||||
//! macros. Calling out to un-inlineable C code for this is pointlessly slow,
|
||||
//! but that's the way it is for now.
|
||||
|
||||
pub type stack_id_t = u32;
|
||||
extern "C" {
|
||||
#[link_name = "valgrind_stack_register"]
|
||||
/// Register a stack with Valgrind. Returns an integer ID that can
|
||||
/// be used to deregister the stack when it's deallocated.
|
||||
/// `start < end`.
|
||||
pub fn stack_register(start: *const u8, end: *const u8) -> stack_id_t;
|
||||
|
||||
#[link_name = "valgrind_stack_deregister"]
|
||||
/// Deregister a stack from Valgrind. Takes the integer ID that was returned
|
||||
/// on registration.
|
||||
pub fn stack_deregister(id: stack_id_t);
|
||||
}
|
Loading…
Reference in New Issue
Block a user