-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Performance pass for ralloc: global-local allocator model, TLS alloca…
…tor, and more - Ralloc now has a global-local allocator model where the local allocator requests memory from the global allocator. This allows for... - ...thread-local storage allocators. The local allocator stores the allocator in a TLS static, bypassing the mutex. - Changes to OOM handling: the OOM handleris no longer allocator-specific, but instead global - Thread-local OOMs - Tweak canonicalization. - Add UniCell primive, which allow for single-threaded mutexes - Tests and stuff.
- Loading branch information
Showing
16 changed files
with
755 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,83 @@ | ||
//! Symbols and externs that ralloc depends on. | ||
//! Symbols and externs that `ralloc` depends on. | ||
//! | ||
//! This crate provides implementation/import of these in Linux, BSD, and Mac OS. | ||
#![crate_name="ralloc_shim"] | ||
#![crate_type="lib"] | ||
#![feature(lang_items)] | ||
#![warn(missing_docs)] | ||
#![feature(lang_items, linkage)] | ||
#![no_std] | ||
#![warn(missing_docs)] | ||
|
||
extern crate libc; | ||
|
||
pub use libc::sched_yield; | ||
|
||
extern { | ||
/// Change the data segment. See `man sbrk`. | ||
pub fn sbrk(libc::intptr_t) -> *const libc::c_void; | ||
} | ||
|
||
/// Thread destructors for Linux. | ||
#[cfg(target_os = "linux")] | ||
pub mod thread_destructor { | ||
use libc; | ||
|
||
extern { | ||
#[linkage = "extern_weak"] | ||
static __dso_handle: *mut u8; | ||
#[linkage = "extern_weak"] | ||
static __cxa_thread_atexit_impl: *const libc::c_void; | ||
} | ||
|
||
/// Does this platform support thread destructors? | ||
/// | ||
/// This will return true, if and only if `__cxa_thread_atexit_impl` is non-null. | ||
#[inline] | ||
pub fn is_supported() -> bool { | ||
!__cxa_thread_atexit_impl.is_null() | ||
} | ||
|
||
extern "C" { | ||
/// Cooperatively gives up a timeslice to the OS scheduler. | ||
pub fn sched_yield() -> isize; | ||
/// Register a thread destructor. | ||
/// | ||
/// # Safety | ||
/// | ||
/// This is unsafe due to accepting (and dereferencing) raw pointers, as well as running an | ||
/// arbitrary unsafe function. | ||
/// | ||
/// On older system without the `__cxa_thread_atexit_impl` symbol, this is unsafe to call, and will | ||
/// likely segfault. | ||
// TODO: Due to rust-lang/rust#18804, make sure this is not generic! | ||
pub unsafe fn register(t: *mut u8, dtor: unsafe extern fn(*mut u8)) { | ||
use core::mem; | ||
|
||
/// A thread destructor. | ||
type Dtor = unsafe extern fn(dtor: unsafe extern fn(*mut u8), arg: *mut u8, dso_handle: *mut u8) -> libc::c_int; | ||
|
||
mem::transmute::<*const libc::c_void, Dtor>(__cxa_thread_atexit_impl)(dtor, t, &__dso_handle as *const _ as *mut _); | ||
} | ||
} | ||
|
||
/// Thread destructors for Mac OS. | ||
#[cfg(target_os = "macos")] | ||
pub mod thread_destructor { | ||
use libc; | ||
|
||
/// Increment data segment of this process by some, _n_, return a pointer to the new data segment | ||
/// start. | ||
/// Does this platform support thread destructors? | ||
/// | ||
/// This uses the system call BRK as backend. | ||
/// This will always return true. | ||
#[inline] | ||
pub fn is_supported() -> bool { true } | ||
|
||
/// Register a thread destructor. | ||
/// | ||
/// This is unsafe for multiple reasons. Most importantly, it can create an inconsistent state, | ||
/// because it is not atomic. Thus, it can be used to create Undefined Behavior. | ||
pub fn sbrk(n: isize) -> *mut u8; | ||
/// # Safety | ||
/// | ||
/// This is unsafe due to accepting (and dereferencing) raw pointers, as well as running an | ||
/// arbitrary unsafe function. | ||
#[cfg(target_os = "macos")] | ||
pub unsafe fn register(t: *mut u8, dtor: unsafe extern fn(*mut u8)) { | ||
extern { | ||
fn _tlv_atexit(dtor: unsafe extern fn(*mut u8), arg: *mut u8); | ||
} | ||
|
||
_tlv_atexit(dtor, t); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.