1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // aux-build:custom.rs
12 // aux-build:helper.rs
15 #![feature(global_allocator, heap_api, allocator_api)]
21 use std::heap::{Heap, Alloc, System, Layout};
22 use std::sync::atomic::{Ordering, ATOMIC_USIZE_INIT};
25 static GLOBAL: custom::A = custom::A(ATOMIC_USIZE_INIT);
29 let n = GLOBAL.0.load(Ordering::SeqCst);
30 let layout = Layout::from_size_align(4, 2).unwrap();
32 let ptr = Heap.alloc(layout.clone()).unwrap();
33 helper::work_with(&ptr);
34 assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 1);
35 Heap.dealloc(ptr, layout.clone());
36 assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2);
38 let ptr = System.alloc(layout.clone()).unwrap();
39 assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2);
40 helper::work_with(&ptr);
41 System.dealloc(ptr, layout);
42 assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2);