about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-12-09 04:02:51 +0000
committerbors <bors@rust-lang.org>2016-12-09 04:02:51 +0000
commit6a495f71fffbc4b378c032295c0fc3ad20bc7e5e (patch)
treea5358a9a205b3eb26453670c001a232b812b595f /src/liballoc
parent97bfeadfd8eb4db591d9fb0fcfef7472d7480415 (diff)
parentabe6fc73e0d5d58d12b069a8b27514086ebbefa1 (diff)
downloadrust-6a495f71fffbc4b378c032295c0fc3ad20bc7e5e.tar.gz
rust-6a495f71fffbc4b378c032295c0fc3ad20bc7e5e.zip
Auto merge of #37492 - japaric:no-atomics-alloc, r=brson
make `alloc` and `collections` compilable for thumbv6m-none-eabi

by cfging away `alloc::Arc` and changing OOM to abort for this target

r? @alexcrichton
cc @thejpster
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/lib.rs2
-rw-r--r--src/liballoc/oom.rs49
2 files changed, 36 insertions, 15 deletions
diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs
index acce4ce0358..f9dfdc0e075 100644
--- a/src/liballoc/lib.rs
+++ b/src/liballoc/lib.rs
@@ -74,6 +74,7 @@
 
 #![feature(allocator)]
 #![feature(box_syntax)]
+#![feature(cfg_target_has_atomic)]
 #![feature(coerce_unsized)]
 #![feature(const_fn)]
 #![feature(core_intrinsics)]
@@ -122,6 +123,7 @@ mod boxed {
 }
 #[cfg(test)]
 mod boxed_test;
+#[cfg(target_has_atomic = "ptr")]
 pub mod arc;
 pub mod rc;
 pub mod raw_vec;
diff --git a/src/liballoc/oom.rs b/src/liballoc/oom.rs
index d355d59185e..3640156fec2 100644
--- a/src/liballoc/oom.rs
+++ b/src/liballoc/oom.rs
@@ -8,12 +8,10 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use core::sync::atomic::{AtomicPtr, Ordering};
-use core::mem;
+#[cfg(target_has_atomic = "ptr")]
+pub use self::imp::set_oom_handler;
 use core::intrinsics;
 
-static OOM_HANDLER: AtomicPtr<()> = AtomicPtr::new(default_oom_handler as *mut ());
-
 fn default_oom_handler() -> ! {
     // The default handler can't do much more since we can't assume the presence
     // of libc or any way of printing an error message.
@@ -26,17 +24,38 @@ fn default_oom_handler() -> ! {
 #[unstable(feature = "oom", reason = "not a scrutinized interface",
            issue = "27700")]
 pub fn oom() -> ! {
-    let value = OOM_HANDLER.load(Ordering::SeqCst);
-    let handler: fn() -> ! = unsafe { mem::transmute(value) };
-    handler();
+    self::imp::oom()
 }
 
-/// Set a custom handler for out-of-memory conditions
-///
-/// To avoid recursive OOM failures, it is critical that the OOM handler does
-/// not allocate any memory itself.
-#[unstable(feature = "oom", reason = "not a scrutinized interface",
-           issue = "27700")]
-pub fn set_oom_handler(handler: fn() -> !) {
-    OOM_HANDLER.store(handler as *mut (), Ordering::SeqCst);
+#[cfg(target_has_atomic = "ptr")]
+mod imp {
+    use core::mem;
+    use core::sync::atomic::{AtomicPtr, Ordering};
+
+    static OOM_HANDLER: AtomicPtr<()> = AtomicPtr::new(super::default_oom_handler as *mut ());
+
+    #[inline(always)]
+    pub fn oom() -> ! {
+        let value = OOM_HANDLER.load(Ordering::SeqCst);
+        let handler: fn() -> ! = unsafe { mem::transmute(value) };
+        handler();
+    }
+
+    /// Set a custom handler for out-of-memory conditions
+    ///
+    /// To avoid recursive OOM failures, it is critical that the OOM handler does
+    /// not allocate any memory itself.
+    #[unstable(feature = "oom", reason = "not a scrutinized interface",
+               issue = "27700")]
+    pub fn set_oom_handler(handler: fn() -> !) {
+        OOM_HANDLER.store(handler as *mut (), Ordering::SeqCst);
+    }
+}
+
+#[cfg(not(target_has_atomic = "ptr"))]
+mod imp {
+    #[inline(always)]
+    pub fn oom() -> ! {
+        super::default_oom_handler()
+    }
 }