core:rt: A few micro-opts
This commit is contained in:
parent
6a6076ae81
commit
bfd9aa9755
@ -84,6 +84,7 @@ pub impl Context {
|
||||
}
|
||||
|
||||
extern {
|
||||
#[rust_stack]
|
||||
fn swap_registers(out_regs: *mut Registers, in_regs: *Registers);
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
use sys::{TypeDesc, size_of};
|
||||
use libc::{c_void, size_t};
|
||||
use libc::{c_void, size_t, uintptr_t};
|
||||
use c_malloc = libc::malloc;
|
||||
use c_free = libc::free;
|
||||
use managed::raw::{BoxHeaderRepr, BoxRepr};
|
||||
@ -34,7 +34,7 @@ pub unsafe fn malloc(td: *TypeDesc, size: uint) -> *c_void {
|
||||
box.header.prev = null();
|
||||
box.header.next = null();
|
||||
|
||||
let exchange_count = &mut *rust_get_exchange_count_ptr();
|
||||
let exchange_count = &mut *exchange_count_ptr();
|
||||
atomic_xadd(exchange_count, 1);
|
||||
|
||||
return transmute(box);
|
||||
@ -52,7 +52,7 @@ pub unsafe fn malloc_raw(size: uint) -> *c_void {
|
||||
}
|
||||
|
||||
pub unsafe fn free(ptr: *c_void) {
|
||||
let exchange_count = &mut *rust_get_exchange_count_ptr();
|
||||
let exchange_count = &mut *exchange_count_ptr();
|
||||
atomic_xsub(exchange_count, 1);
|
||||
|
||||
assert!(ptr.is_not_null());
|
||||
@ -77,7 +77,11 @@ fn align_to(size: uint, align: uint) -> uint {
|
||||
(size + align - 1) & !(align - 1)
|
||||
}
|
||||
|
||||
extern {
|
||||
#[rust_stack]
|
||||
fn rust_get_exchange_count_ptr() -> *mut int;
|
||||
fn exchange_count_ptr() -> *mut int {
|
||||
// XXX: Need mutable globals
|
||||
unsafe { transmute(&rust_exchange_count) }
|
||||
}
|
||||
|
||||
extern {
|
||||
static rust_exchange_count: uintptr_t;
|
||||
}
|
||||
|
@ -126,6 +126,7 @@ fn maybe_tls_key() -> Option<tls::Key> {
|
||||
}
|
||||
|
||||
extern {
|
||||
#[fast_ffi]
|
||||
fn rust_get_sched_tls_key() -> *mut c_void;
|
||||
}
|
||||
|
||||
|
@ -46,8 +46,11 @@ type pthread_key_t = ::libc::c_uint;
|
||||
|
||||
#[cfg(unix)]
|
||||
extern {
|
||||
#[fast_ffi]
|
||||
fn pthread_key_create(key: *mut pthread_key_t, dtor: *u8) -> c_int;
|
||||
#[fast_ffi]
|
||||
fn pthread_setspecific(key: pthread_key_t, value: *mut c_void) -> c_int;
|
||||
#[fast_ffi]
|
||||
fn pthread_getspecific(key: pthread_key_t) -> *mut c_void;
|
||||
}
|
||||
|
||||
|
@ -15,14 +15,15 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
uintptr_t exchange_count = 0;
|
||||
extern uintptr_t rust_exchange_count;
|
||||
uintptr_t rust_exchange_count = 0;
|
||||
|
||||
void *
|
||||
rust_exchange_alloc::malloc(size_t size) {
|
||||
void *value = ::malloc(size);
|
||||
assert(value);
|
||||
|
||||
sync::increment(exchange_count);
|
||||
sync::increment(rust_exchange_count);
|
||||
|
||||
return value;
|
||||
}
|
||||
@ -36,20 +37,15 @@ rust_exchange_alloc::realloc(void *ptr, size_t size) {
|
||||
|
||||
void
|
||||
rust_exchange_alloc::free(void *ptr) {
|
||||
sync::decrement(exchange_count);
|
||||
sync::decrement(rust_exchange_count);
|
||||
::free(ptr);
|
||||
}
|
||||
|
||||
extern "C" uintptr_t *
|
||||
rust_get_exchange_count_ptr() {
|
||||
return &exchange_count;
|
||||
}
|
||||
|
||||
void
|
||||
rust_check_exchange_count_on_exit() {
|
||||
if (exchange_count != 0) {
|
||||
if (rust_exchange_count != 0) {
|
||||
printf("exchange heap not empty on exit\n");
|
||||
printf("%d dangling allocations\n", (int)exchange_count);
|
||||
printf("%d dangling allocations\n", (int)rust_exchange_count);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ rust_register_exit_function
|
||||
rust_get_global_data_ptr
|
||||
rust_inc_kernel_live_count
|
||||
rust_dec_kernel_live_count
|
||||
rust_get_exchange_count_ptr
|
||||
rust_exchange_count
|
||||
rust_get_sched_tls_key
|
||||
swap_registers
|
||||
rust_readdir
|
||||
|
Loading…
Reference in New Issue
Block a user