Skip to content

Commit f794545

Browse files
author
Jethro Beekman
committed
Add "global" feature.
This feature gates GlobalDlmalloc and dependent functions. This creates a clean break between the pure Dlmalloc port and bindings to the Rust allocator system.
1 parent af4f85f commit f794545

File tree

6 files changed

+14
-0
lines changed

6 files changed

+14
-0
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,7 @@ rand = "0.3"
1717
debug-assertions = true
1818

1919
[features]
20+
default = ["global"]
21+
global = []
2022
debug = []
2123
allocator-api = []

src/dlmalloc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ pub struct Dlmalloc {
2626
release_checks: usize,
2727
}
2828

29+
unsafe impl Send for Dlmalloc {}
30+
2931
pub const DLMALLOC_INIT: Dlmalloc = Dlmalloc {
3032
smallmap: 0,
3133
treemap: 0,

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ use core::alloc::{Alloc, Layout, AllocErr};
88
use core::cmp;
99
use core::ptr;
1010

11+
#[cfg(feature = "global")]
1112
pub use self::global::GlobalDlmalloc;
1213

14+
#[cfg(feature = "global")]
1315
mod global;
1416
mod dlmalloc;
1517

src/linux.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,17 @@ pub fn can_release_part(_flags: u32) -> bool {
4444
true
4545
}
4646

47+
#[cfg(feature = "global")]
4748
static mut LOCK: libc::pthread_mutex_t = libc::PTHREAD_MUTEX_INITIALIZER;
4849

50+
#[cfg(feature = "global")]
4951
pub fn acquire_global_lock() {
5052
unsafe {
5153
assert_eq!(libc::pthread_mutex_lock(&mut LOCK), 0)
5254
}
5355
}
5456

57+
#[cfg(feature = "global")]
5558
pub fn release_global_lock() {
5659
unsafe {
5760
assert_eq!(libc::pthread_mutex_unlock(&mut LOCK), 0)

src/macos.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@ pub fn can_release_part(_flags: u32) -> bool {
3434
true
3535
}
3636

37+
#[cfg(feature = "global")]
3738
static mut LOCK: libc::pthread_mutex_t = libc::PTHREAD_MUTEX_INITIALIZER;
3839

40+
#[cfg(feature = "global")]
3941
pub fn acquire_global_lock() {
4042
unsafe {
4143
assert_eq!(libc::pthread_mutex_lock(&mut LOCK), 0)
4244
}
4345
}
4446

47+
#[cfg(feature = "global")]
4548
pub fn release_global_lock() {
4649
unsafe {
4750
assert_eq!(libc::pthread_mutex_unlock(&mut LOCK), 0)

src/wasm.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ pub fn can_release_part(_flags: u32) -> bool {
3434
false
3535
}
3636

37+
#[cfg(feature = "global")]
3738
pub fn acquire_global_lock() {
3839
// single threaded, no need!
3940
}
4041

42+
#[cfg(feature = "global")]
4143
pub fn release_global_lock() {
4244
// single threaded, no need!
4345
}

0 commit comments

Comments
 (0)