Skip to content

Commit 03dd9b8

Browse files
committed
Add test to ensure that atomic types are lock-free
1 parent 97216a6 commit 03dd9b8

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
-include ../tools.mk
2+
3+
# This tests ensure that atomic types are never lowered into runtime library calls that are not
4+
# guaranteed to be lock-free.
5+
6+
all:
7+
ifeq ($(UNAME),Linux)
8+
$(RUSTC) --target=i686-unknown-linux-gnu atomic_lock_free.rs
9+
nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add
10+
$(RUSTC) --target=x86_64-unknown-linux-gnu atomic_lock_free.rs
11+
nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add
12+
$(RUSTC) --target=arm-unknown-linux-gnueabi atomic_lock_free.rs
13+
nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add
14+
$(RUSTC) --target=arm-unknown-linux-gnueabihf atomic_lock_free.rs
15+
nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add
16+
$(RUSTC) --target=armv7-unknown-linux-gnueabihf atomic_lock_free.rs
17+
nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add
18+
$(RUSTC) --target=aarch64-unknown-linux-gnu atomic_lock_free.rs
19+
nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add
20+
$(RUSTC) --target=mips-unknown-linux-gnu atomic_lock_free.rs
21+
nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add
22+
$(RUSTC) --target=mipsel-unknown-linux-gnu atomic_lock_free.rs
23+
nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add
24+
$(RUSTC) --target=powerpc-unknown-linux-gnu atomic_lock_free.rs
25+
nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add
26+
$(RUSTC) --target=powerpc64-unknown-linux-gnu atomic_lock_free.rs
27+
nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add
28+
$(RUSTC) --target=powerpc64le-unknown-linux-gnu atomic_lock_free.rs
29+
nm "$(TMPDIR)/libatomic_lock_free.rlib" | grep -vq __atomic_fetch_add
30+
endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2016 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.
4+
//
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.
10+
11+
#![feature(cfg_target_has_atomic, no_core, intrinsics, lang_items)]
12+
#![crate_type="rlib"]
13+
#![no_core]
14+
15+
extern "rust-intrinsic" {
16+
fn atomic_xadd<T>(dst: *mut T, src: T) -> T;
17+
}
18+
19+
#[lang = "sized"]
20+
trait Sized {}
21+
22+
#[cfg(target_has_atomic = "8")]
23+
pub unsafe fn atomic_u8(x: *mut u8) {
24+
atomic_xadd(x, 1);
25+
atomic_xadd(x, 1);
26+
}
27+
#[cfg(target_has_atomic = "8")]
28+
pub unsafe fn atomic_i8(x: *mut i8) {
29+
atomic_xadd(x, 1);
30+
}
31+
#[cfg(target_has_atomic = "16")]
32+
pub unsafe fn atomic_u16(x: *mut u16) {
33+
atomic_xadd(x, 1);
34+
}
35+
#[cfg(target_has_atomic = "16")]
36+
pub unsafe fn atomic_i16(x: *mut i16) {
37+
atomic_xadd(x, 1);
38+
}
39+
#[cfg(target_has_atomic = "32")]
40+
pub unsafe fn atomic_u32(x: *mut u32) {
41+
atomic_xadd(x, 1);
42+
}
43+
#[cfg(target_has_atomic = "32")]
44+
pub unsafe fn atomic_i32(x: *mut i32) {
45+
atomic_xadd(x, 1);
46+
}
47+
#[cfg(target_has_atomic = "64")]
48+
pub unsafe fn atomic_u64(x: *mut u64) {
49+
atomic_xadd(x, 1);
50+
}
51+
#[cfg(target_has_atomic = "64")]
52+
pub unsafe fn atomic_i64(x: *mut i64) {
53+
atomic_xadd(x, 1);
54+
}
55+
#[cfg(target_has_atomic = "ptr")]
56+
pub unsafe fn atomic_usize(x: *mut usize) {
57+
atomic_xadd(x, 1);
58+
}
59+
#[cfg(target_has_atomic = "ptr")]
60+
pub unsafe fn atomic_isize(x: *mut isize) {
61+
atomic_xadd(x, 1);
62+
}

0 commit comments

Comments
 (0)