Skip to content

Commit bfd9aa9

Browse files
committed
core:rt: A few micro-opts
1 parent 6a6076a commit bfd9aa9

File tree

6 files changed

+21
-16
lines changed

6 files changed

+21
-16
lines changed

src/libcore/rt/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ pub impl Context {
8484
}
8585

8686
extern {
87+
#[rust_stack]
8788
fn swap_registers(out_regs: *mut Registers, in_regs: *Registers);
8889
}
8990

src/libcore/rt/global_heap.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use sys::{TypeDesc, size_of};
12-
use libc::{c_void, size_t};
12+
use libc::{c_void, size_t, uintptr_t};
1313
use c_malloc = libc::malloc;
1414
use c_free = libc::free;
1515
use managed::raw::{BoxHeaderRepr, BoxRepr};
@@ -34,7 +34,7 @@ pub unsafe fn malloc(td: *TypeDesc, size: uint) -> *c_void {
3434
box.header.prev = null();
3535
box.header.next = null();
3636

37-
let exchange_count = &mut *rust_get_exchange_count_ptr();
37+
let exchange_count = &mut *exchange_count_ptr();
3838
atomic_xadd(exchange_count, 1);
3939

4040
return transmute(box);
@@ -52,7 +52,7 @@ pub unsafe fn malloc_raw(size: uint) -> *c_void {
5252
}
5353

5454
pub unsafe fn free(ptr: *c_void) {
55-
let exchange_count = &mut *rust_get_exchange_count_ptr();
55+
let exchange_count = &mut *exchange_count_ptr();
5656
atomic_xsub(exchange_count, 1);
5757

5858
assert!(ptr.is_not_null());
@@ -77,7 +77,11 @@ fn align_to(size: uint, align: uint) -> uint {
7777
(size + align - 1) & !(align - 1)
7878
}
7979

80+
fn exchange_count_ptr() -> *mut int {
81+
// XXX: Need mutable globals
82+
unsafe { transmute(&rust_exchange_count) }
83+
}
84+
8085
extern {
81-
#[rust_stack]
82-
fn rust_get_exchange_count_ptr() -> *mut int;
86+
static rust_exchange_count: uintptr_t;
8387
}

src/libcore/rt/local_sched.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ fn maybe_tls_key() -> Option<tls::Key> {
126126
}
127127

128128
extern {
129+
#[fast_ffi]
129130
fn rust_get_sched_tls_key() -> *mut c_void;
130131
}
131132

src/libcore/rt/thread_local_storage.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ type pthread_key_t = ::libc::c_uint;
4646

4747
#[cfg(unix)]
4848
extern {
49+
#[fast_ffi]
4950
fn pthread_key_create(key: *mut pthread_key_t, dtor: *u8) -> c_int;
51+
#[fast_ffi]
5052
fn pthread_setspecific(key: pthread_key_t, value: *mut c_void) -> c_int;
53+
#[fast_ffi]
5154
fn pthread_getspecific(key: pthread_key_t) -> *mut c_void;
5255
}
5356

src/rt/rust_exchange_alloc.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
#include <string.h>
1616
#include <stdio.h>
1717

18-
uintptr_t exchange_count = 0;
18+
extern uintptr_t rust_exchange_count;
19+
uintptr_t rust_exchange_count = 0;
1920

2021
void *
2122
rust_exchange_alloc::malloc(size_t size) {
2223
void *value = ::malloc(size);
2324
assert(value);
2425

25-
sync::increment(exchange_count);
26+
sync::increment(rust_exchange_count);
2627

2728
return value;
2829
}
@@ -36,20 +37,15 @@ rust_exchange_alloc::realloc(void *ptr, size_t size) {
3637

3738
void
3839
rust_exchange_alloc::free(void *ptr) {
39-
sync::decrement(exchange_count);
40+
sync::decrement(rust_exchange_count);
4041
::free(ptr);
4142
}
4243

43-
extern "C" uintptr_t *
44-
rust_get_exchange_count_ptr() {
45-
return &exchange_count;
46-
}
47-
4844
void
4945
rust_check_exchange_count_on_exit() {
50-
if (exchange_count != 0) {
46+
if (rust_exchange_count != 0) {
5147
printf("exchange heap not empty on exit\n");
52-
printf("%d dangling allocations\n", (int)exchange_count);
48+
printf("%d dangling allocations\n", (int)rust_exchange_count);
5349
abort();
5450
}
5551
}

src/rt/rustrt.def.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ rust_register_exit_function
195195
rust_get_global_data_ptr
196196
rust_inc_kernel_live_count
197197
rust_dec_kernel_live_count
198-
rust_get_exchange_count_ptr
198+
rust_exchange_count
199199
rust_get_sched_tls_key
200200
swap_registers
201201
rust_readdir

0 commit comments

Comments
 (0)